on 2021 Oct 15 9:56 AM
Combining query blocks with UNION, INTERSECT or EXCEPT is rather common.
How can you put these combined results into a table?
It seems that both SELECT..INTO and INSERT..SELECT and do work with UNIONs and the like:
drop table if exists LT_TestResult; select 1 as ID, 'Query block 1' as Description into local temporary table LT_TestResult from dummy union all select 2, 'Query block 2' from dummy union all select 3, 'Query block 3' from dummy order by 1; select * from LT_TestResult order by 1;
This returns 3 rows, i.e. the SELECT...INTO has apparently used the combined result set although the INTO clause is just specfied for the first query block (and is not allowed for the further query blocks).
The same does work with INSERT SELECT:
truncate table LT_TestResult; insert into LT_TestResult select 1 as ID, 'Query block 1' as Description from dummy union all select 2, 'Query block 2' from dummy union all select 3, 'Query block 3' from dummy order by 1; select * from LT_TestResult order by 1;
This also returns 3 rows although according to the docs INSERT expects a (single) SELECT statement and not a combined query.
So, in a nutshell, this works as desired as of V17.0.10.6315 but I think it is not really documented that way.
If this is expected behaviour, I'd suggest to add this to the docs.
Request clarification before answering.
User | Count |
---|---|
74 | |
30 | |
9 | |
7 | |
7 | |
6 | |
6 | |
5 | |
5 | |
5 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.