I intend to write a INSERT INTO request in Postgresql based on several SELECT but didn't succeed. I have one table containing data I select (srctab), and another one where I insert data (dsttab). Here is what I run :
INSERT INTO dsttab (dstfld1, dstfld2) WITH
t1 AS (
SELECT srcfld1
FROM srctab
WHERE srcfld3 ='foo'
),
t2 AS (
SELECT srcfld5
FROM srctab
WHERE srcfld6 ='bar'
) select srcfld1, srcfld5 from srctab;
Could you please help to make this work ? Thank you !
insert
needs to go after thewith
- but the whole thing doesn't make sense. You are defining two CTEs but you never use them. What exactly are you trying to do?