cancel
Showing results for 
Search instead for 
Did you mean: 

SELECT over a DML statement; limitations or a bug?

Chris26
Explorer
480

Take this example

create table Test1 (colA integer);
create table Test2 (colB integer);

insert into Test2 (colB)
select new1.colA
  from (insert into Test1 (colA) values (1)) referencing (final as new1)

After this tables Test1 and Test2 both contain 1 record, which is what I expected. Now try this:

create table Test3 (colA integer);
create table Test4 (colB integer);
create table Test5 (colC integer);

insert into Test5 (colC)
select new4.colB
  from (insert into Test4 (colB)
        select new3.colA
          from (insert into Test3 (colA) values (2)
               ) referencing (final as new3)
       ) referencing (final as new4)

You don't get any errors, but the result is not what I expected. Only in table Test3 a record is inserted. Tables Test4 and Test5 remain empty.

From the help: "The dml-derived-table statement can only reference one updatable table; updates over multiple tables return an error. Also, selecting from dml-statement is not allowed if the DML statement appears inside a correlated subquery or common table expression because the semantics of these constructs can be unclear."

I'm not quite sure if this last part in the help is trying to explain that what I'm trying to do here doesn't work.
So basically my question is: is this a known limitation or a bug?
And if it's a known limitation: an exception would be appreciated in such a situation so it's clear immediately that this is not supported.

Accepted Solutions (0)

Answers (0)