You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Note that RETURNING contains a reference to y.b,
which is not used anywhere in the SET clause.
When compiling UPDATE, we:
construct a "value input" relation, that provides the values for the SET clause,
compile insert x { a := ... }, using value relation for the inserted values,
resolve RETURNING in scope with a single rel var, which is the rel var of the
table we have just updated (x in this example), with all of its columns, as
they are after the update.
To support refs to arbitrary columns of y, we will have to:
export all columns in scope from the value relation,
when resolving RETURNING, join the updated relation with the value relation
so we can pull columns of y out of it.
Why do we need all columns of y, why not just the ones we need?
Because resolver does not "pull columns out of provided rel vars" as the edgeql
backend compiler does. Resolver needs a set of "tables in scope" where each of the
columns has a defined materialization. Most of the time, this is ColumnByName,
which means that you can materialize it into a single pgast.ColumnRef.
Other ways of materialization are even simpler (static or a provided expression).
what happens if there are multiple FROM clauses?
So that would be:
UPDATE x
SET a =y.aFROM (...) AS y, (...) AS z, (...) AS v
RETURNING y.b, z.c, v.d
We need to add all columns of all tables in scope (except the table we are updating).
The text was updated successfully, but these errors were encountered:
asyncdeftest_sql_dml_update_18(self):
# Test that RETURNING has FROM in scopeusers=awaitself.squery_values(
''' INSERT INTO "User" (id) VALUES (DEFAULT), (DEFAULT) RETURNING id '''
)
awaitself.squery_values(
''' WITH u(id) as (VALUES ($1), ($2)) INSERT INTO "Document" (title, owner_id) SELECT 'Report', u.id FROM u RETURNING title, owner_id ''',
str(users[0][0]),
str(users[1][0]),
)
res=awaitself.squery_values(
''' UPDATE "Document" SET owner_id = owner_id FROM "User" u WHERE "Document".owner_id = u.id RETURNING title, u.id ''',
)
self.assertEqual(
set(res),
set([
['Report (insert) (updated)', users[0][0]],
['Report (insert) (updated)', users[1][0]],
])
)
We want to also support such queries:
... because PostgreSQL supports it.
Note that
RETURNING
contains a reference toy.b
,which is not used anywhere in the
SET
clause.When compiling UPDATE, we:
insert x { a := ... }
, using value relation for the inserted values,RETURNING
in scope with a single rel var, which is the rel var of thetable we have just updated (
x
in this example), with all of its columns, asthey are after the update.
To support refs to arbitrary columns of
y
, we will have to:RETURNING
, join the updated relation with the value relationso we can pull columns of
y
out of it.Why do we need all columns of
y
, why not just the ones we need?Because resolver does not "pull columns out of provided rel vars" as the edgeql
backend compiler does. Resolver needs a set of "tables in scope" where each of the
columns has a defined materialization. Most of the time, this is
ColumnByName
,which means that you can materialize it into a single
pgast.ColumnRef
.Other ways of materialization are even simpler (static or a provided expression).
what happens if there are multiple FROM clauses?
So that would be:
We need to add all columns of all tables in scope (except the table we are updating).
The text was updated successfully, but these errors were encountered: