Skip to content

"UPDATE ... FROM" does not work with CTE #267

@kevinburke1

Description

@kevinburke1

If I have

WITH x AS (
    SELECT * FROM table WHERE ...
)
UPDATE table
SET a = b 
FROM x

When I run it, I get:

relation "x" does not exist

This is valid per Postgres: https://www.postgresql.org/docs/11/sql-update.html

A list of table expressions, allowing columns from other tables to appear in the WHERE condition and the update expressions. This is similar to the list of tables that can be specified in the FROM Clause of a SELECT statement. Note that the target table must not appear in the from_list, unless you intend a self-join (in which case it must appear with an alias in the from_list).

I tried to debug further but didn't have any luck.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions