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
It would be nice to be able to use CTEs with other main statements than just SELECT:
with my_cte as (select ... from ... where ...)
update this_table set ... where <condition involving my_cte>
with your_cte as (select ... from ... where ...),
his_cte as (select ... from ... where ...)
merge into that_table using your_cte
on <condition involving his_cte>
...
Etc.
Also, I would prefer the following syntax in PSQL:
with some_cte as (select ... from ... where ...)
for select ... from some_cte into ...
do
Although this involves just as much typing as the currently supported FOR WITH... SELECT syntax, it is much cleaner: first any CTEs are defined, then the loop is set up.
It also keeps FOR SELECT together. FOR WITH is just plain nonsense, English-wise. At least most of the time. For with any rule, there are exceptions.
The text was updated successfully, but these errors were encountered:
in my opinion "WITH" is where it should be.
Tested in the Firebird-2.5.6.27017 and FB3.0.32527.
Everything works. You can close CORE3169
MERGE
INTO d009 c
USING (
with xxx as (SELECT * FROM d009 WHERE d009_1 > '10')
select * from xxx) cd
ON (c.d009_1 = cd.d009_1)
WHEN MATCHED THEN UPDATE SET d009_1 = cd.d009_1
ok.
UPDATE d009 SET d009_1 = d009_1
where d009_1 in (
with xxx as (SELECT d009_1 FROM d009 WHERE d009_1 > '10')
select * from xxx)
ok.
delete from d009
where d009_1 in (
with xxx as (SELECT d009_1 FROM d009 WHERE d009_1 = 'x10')
select * from xxx)
ok.
No Boltik, you've got it the other way around.
Of course you can nest CTE's as tables within another statement, but I would like to be able to perform update, merge etc. operations within a CTE construct, i.e. with the CTE or CTE's neatly defined in the preamble and the operations following it. See my examples.
Defining CTE's in the preamble gives cleaner code. Nesting them parenthesized within another statement looks messy.
the first sample syntax is vital.
Update statements should support CTE, this simplify it a lot.
instead writing many "same" subqueries to put value for fields we then can use simple cte to do the same
e.g.
UPDATE TABLE1 T1
SET
T1.FIELD1=(SELECT http://T2.XXX FROM TABLE2 JOIN ... JOIN ... WHERE ...)
,T1.FIELD1=(SELECT http://T2.XXX FROM TABLE2 JOIN ... JOIN ... WHERE ...)
WHERE
....
we can write it simply as
WITH TX AS
(
SELECT http://T2.XXX, T3.YY FROM TABLE2 JOIN T3... JOIN ...
)
UPDATE TABLE1 T1
SET
T1.FIELD1=(SELECT http://TX.XXX FROM TX WHERE ...)
,T1.FIELD1=(SELECT TX.YYY FROM TX WHERE ...)
WHERE
....
IMO this ticket is about invalid things. Just use MERGE ... USING WITH. A CTE for UPDATE would be needed only if Firebird allowed to update the CTE (a simple map from a select), not for read data of a CTE.
Submitted by: @paulvink
Votes: 3
It would be nice to be able to use CTEs with other main statements than just SELECT:
with my_cte as (select ... from ... where ...)
update this_table set ... where <condition involving my_cte>
with your_cte as (select ... from ... where ...),
his_cte as (select ... from ... where ...)
merge into that_table using your_cte
on <condition involving his_cte>
...
Etc.
Also, I would prefer the following syntax in PSQL:
with some_cte as (select ... from ... where ...)
for select ... from some_cte into ...
do
Although this involves just as much typing as the currently supported FOR WITH... SELECT syntax, it is much cleaner: first any CTEs are defined, then the loop is set up.
It also keeps FOR SELECT together. FOR WITH is just plain nonsense, English-wise. At least most of the time. For with any rule, there are exceptions.
The text was updated successfully, but these errors were encountered: