Search code examples
sqlcommon-table-expressiongreenplum

CTE/with clause in PSQL


I get ERROR:

syntax error at or near "INSERT"* on executing the following:

WITH
    sq as (select * from input_client)
INSERT INTO cleaned
select *
  from weekly
    cross join sq;

Refer(red) the manual for syntax: https://www.postgresql.org/docs/9.1/static/queries-with.html


Solution

  • INSERT INTO cleaned
    select w.*
    from weekly w, input_client;
    

    If you just want a cartesian product of input_client and weekly, just write it that way.