Skip to content

Postgres WITH/CTE with only a VALUES list - No query #993

@BenGatewood

Description

@BenGatewood

Motivation

Hey all - Opening this at Huli's request after a discussion on Discord:

It's not currently possible to construct SQL like the following where the CTE consists only of a VALUES list without a query:

WITH data (
    field1,
    field2,
    field3,
    field4,
    field5
    ) AS (
        VALUES (
                'a',
                123,
                'blah',
                333,
                1
               )
), ins1 AS (
    INSERT INTO tableA (col1, col2, col3) SELECT d.field1, d.field2, d.field3 FROM data d RETURNING id as tableA_id
) INSERT INTO tableB (table_a_id, colx, coly) SELECT ins1.tableA_id, d.field4, d.field5 FROM data d CROSS JOIN ins1;

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions