kizunairo
kizunairo

Reputation: 41

Inserting Values into CTE

I'm trying to create a temp table in postgres using some values. Looking for help in creating the syntax.

Example data from csv

id sale
1 2321
2 143
3 1
4 233
5 123

I'm looking for if there is a way to import the csv into CTE or writing out all the data in syntax

Upvotes: 0

Views: 2598

Answers (1)

Thom Brown
Thom Brown

Reputation: 2029

You can either use file_fdw (https://www.postgresql.org/docs/12/file-fdw.html) to read the CSV file in as a table, or you can hardcode the values if you're only using a small set of data.

e.g.

WITH csvdata (id, sale) AS (
  VALUES (1, 2321),
    (2, 143),
    (3, 1),
    (4, 233)
)
SELECT *
FROM csvdata...

Upvotes: 4

Related Questions