Home > other >  PostgreSQL: Create/Select a fake/dummy column
PostgreSQL: Create/Select a fake/dummy column

Time:10-06

How would i write a query so that i can generate myself a column with some specific numbers? I would prefer not to be forced to create a table and import from excel, nor insert values (as i have many numbers to put into that column, and i'll have to put lots of parantheses around those values) See picture for reference. Now imagine i have 1000 numbers. I would like to have some query where i could just copy-paste over those numbers. I tried:

  • select (231,356,...) as companyid ... obviously this did not provide the desired result.
  • i succeded with a temp table and insert into .. but i had to go like VALUES(231),(356),... ... which is nasty

enter image description here

CodePudding user response:

For a list of numbers, from some other source, you can use UNNEST():

SELECT  UNNEST('{1,2,4,6,54,3,900}'::int[]) AS id;

Just replace "1,2,4,6,54,3,900" with your input, and use the comma to separate the values.

  • Related