![]() | |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
Hi. You can use the following SQL to construct rows with column names on the fly, rather than from an existing table like sysibm.sysdummy1: SELECT * FROM TABLE ( VALUES (0, 1, 2), (3, 4, 5), (6, 7, 8) ) X(foo, bar, baz); or WITH X(foo, bar, baz) AS ( VALUES (0, 1, 2), (3, 4, 5), (6, 7, 8) ) SELECT * FROM X; As far as I tested, this construct is available on 7.2.8 and onwards. This is sometimes useful, for example in MERGE INTO statement, or when you don't want to create a table with a random name just to prepare a few rows like above. My question is, is this DB2-specific syntax, or is it(going to be) a part of the standard in the future? I tried on PostgreSQL, but it doesn't even accept the following SQL(to generate three columns without column names): VALUES (0, 1, 2); |
#3
| |||
| |||
|
|
I do not remember LATERAL as a keyword, but you can write: |
#4
| |||
| |||
|
|
According to the bedtime stories I heard ... |

#5
| |||
| |||
|
|
I am honestly lost on this one. I would expand and qualify that example like this: SELECT * FROM T WHERE EXISTS (SELECT * FROM T AS T1 CROSS JOIN (SELECT 1 FROM S WHERE S.PK = T1.PK) AS X(i) WHERE T1.C1 = X.i) ; This is, strictly speaking, illegal. The subquery cannot see T1.PK. |
|
I just follow the usual scoping rules to find the innermost copy of table T. if I want some strange realtionships, I cn qualify the copies of T SELECT * FROM T AS T0 WHERE EXISTS (SELECT * FROM T AS T1 CROSS JOIN (SELECT 1 FROM S WHERE S.PK = T0.PK) AS X(i) WHERE T1.C1 = X.i) ; What does LATERAL do that is different? According to the bedtime stories I heard ... The keyword COALESCE() instead of IBM's VALUE() is another story like that. Someone at the meeting had a pocket thesaurus and pulled that one out of list of things like "melt", "fuse", "meld", etc. It ws the least likely to be a column or table name, so we went with it ![]() I wonder whether there is a market for a story book on the SQL Standard, |
#6
| |||
| |||
|
|
The keyword COALESCE() instead of IBM's VALUE() is another story like that. Someone at the meeting had a pocket thesaurus and pulled that one out of list of things like "melt", "fuse", "meld", etc. It ws the least likely to be a column or table name, so we went with it ![]() I wonder whether there is a market for a story book on the SQL Standard, or standards in general... |
![]() |
| Thread Tools | |
| Display Modes | |
| |