Technical questionAccepted answer
Is there a way to create a CTE with values in postgres?
edog429
Jul 1
0 views1
I often just want to test out a function, or see what a variable might look like. This could be done by creating a temporary table, but I suspect that there is an easier way.
Basically,
WITH cte1 AS (
SELECT
VALUES(1,2,3) AS temp_var1
, VALUES(4,5,6) AS temp_var2
)
SELECT
temp_var1
, temp_var2
, (temp_var1 + temp_var2) AS temp_var3
FROM cte1
This would return
| temp_var1 | temp_var2 | temp_var3 |
|---|---|---|
| 1 | 4 | 5 |
| 2 | 5 | 7 |
| 3 | 6 | 9 |
Darn she's fine.
Note I'm using PostgreSQL 9.2.15.
1 answer
Accepted answer · original discussion
user330315
PermalinkJul 1
I think you are looking for
WITH cte1 (temp_var1, temp_var2) AS (
VALUES
(1,4),
(2,5),
(3,6)
)
SELECT
temp_var1
, temp_var2
, (temp_var1 + temp_var2) AS temp_var3
FROM cte1
3 question comments
Use comments to ask for clarification. Post a solution as an answer.
Laurenz AlbePermalink
Jul 1
8.2 didn't have CTEs. Also, I don't understand your question. Do you have a working query or not?
edog429Permalink
Jul 1
Forgive me, the documentation I was using was out of date. It is Postgres 9.2.24. I do not have a working query. That is the output I would like to generate using something similar to that query