2

for example,

select 1,2,3 ;

will return 3 columns with 1 row i.e [1,2,3]
, So how to get 3 coulmns with 3 rows with the same content ?

2
  • 1
    SELECT id FROM generate_series(1,3) id; Commented Oct 13, 2014 at 7:21
  • @vyegorov this will only returns only one column Commented Oct 13, 2014 at 7:24

2 Answers 2

1

Well, CROSS JOIN is a good fit here:

SELECT rownum, cols.*
  FROM (SELECT 1,2,3) cols
 CROSS JOIN generate_series(1,10) id(rownum);

You use SELECT cols.* if you need just values without row numbers.

Sign up to request clarification or add additional context in comments.

Comments

0

Try UNION, I think you need something like this

select 1 c1,2 c2,3 c3
     union  all
select 1 ,2 ,3 
     union  all
select 1 ,2 ,3 

1 Comment

Alternatively use the values clause: select * from ( values (1,2,3), (1,2,3), (1,2,3)) as t (c1, c2, c3). Btw: you only need to specify column names in the first statement of a union.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.