Skip to content

ExecuteUpdate with cross apply produces invalid SQL #28823

@roji

Description

@roji

On PG, test Update_with_cross_apply_set_constant produces the following SQL:

UPDATE "Customers" AS c
SET "ContactName" = 'Updated'
FROM (
    SELECT o."OrderID", o."CustomerID", o."EmployeeID", o."OrderDate"
    FROM "Orders" AS o
    WHERE o."OrderID" < 10300 AND date_part('year', o."OrderDate")::int < length(c."ContactName")::int
) AS t
WHERE c."CustomerID" LIKE 'F%'

This fails with the following, since c.ContactName references an outer column:

ERROR:  invalid reference to FROM-clause entry for table "c" at character 240
HINT:  There is an entry for table "c", but it cannot be referenced from this part of the query.

Originally discussed in npgsql/efcore.pg#2475 (comment)

Metadata

Metadata

Assignees

Type

No fields configured for Bug.

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions