Nested INSERT bug
See original GitHub issuedb> CREATE TYPE Foo {CREATE LINK bar -> Object};
CREATE
db> INSERT Foo {bar := (INSERT Foo)};
QueryError: invalid reference to default::Foo: self-referencing INSERTs are not allowed
Hint: Use DETACHED if you meant to refer to an uncorrelated default::Foo set
### INSERT Foo {bar := (INSERT Foo)};
###
This looks like a bug to me. I was under the impression that the thing right after INSERT
is supposed to be a type name, not an arbitrary expression, as such there cannot be a problem of self-reference. If memory serves me, we couldn’t actually guarantee that self-references in an INSERT
would work (say for use in a subquery selecting some link based on other yet-to-be-inserted data that appears syntactically in the INSERT
statement).
As far as I recall this is illegal:
INSERT Bar {
a := 'data',
b := .a
};
Am I misunderstanding INSERT
?
Just to clarify, the intent is to simple create 2 Foo
objects where one is linked to the other. This is not intended or expected to be some sort of self-link.
Issue Analytics
- State:
- Created 4 years ago
- Comments:12 (12 by maintainers)
Top Results From Across the Web
Errors: "INSERT EXEC statement cannot be nested." and ...
I tried to change the place of execute Sp2 and it display me another error: Cannot use the ROLLBACK statement within an INSERT-EXEC...
Read more >An INSERT EXEC statement cannot be nested after upgrade ...
I am receiving "An INSERT EXEC statement cannot be nested". ... there h*as never been issue with Insert Exec* nested error till now....
Read more >HOW TO - Resolve 'An INSERT EXEC statement cannot be ...
I get the error message. An INSERT EXEC statement cannot be nested. But the query DOES insert the records into my table. I...
Read more >INSERT EXEC statement cannot be nested
EXEC then if you try to call that stored procedure in the context of another INSERT...EXEC you will get the error you are...
Read more >Msg 8164 - An INSERT EXEC statement cannot be nested.
Server: Msg 8164, Level 16, State 1, Line 1 An INSERT EXEC statement cannot be nested. ... This error occurs when calling a...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
After some discussion and poking around the realization about nested
INSERT
is that it does, in fact, obey the general binding rules through itsUNLESS CONFLICT
clause, which would get very complicated and inconsistent in nested scenarios:Intuitively, the nested
ELSE Tree
should bind to the nearestINSERT
and not to the outerINSERT
, but this is inconsistent with the general binding rules of EdgeQL. Thus, I’m reaffirming our position thatINSERT
isn’t different from other statements in terms of the binding rules.A possible long-term solution to this problem would be type aliases as in #1578:
However, that hinges on a new syntax that isn’t yet implemented, so for now the official recommendation on how to handle simultaneous insertion into a recursive type is to move the nested
INSERT
statements into aWITH
block, as is the general recommendation where recursive types are concerned:I’m reopening this for reconsideration, since there is currently no clean way of
INSERT
-ing self-referencing objects. To improve the situation we have two options:Allow
INSERT Foo {bar := (INSERT Foo)};
without qualifiers, since, as @vpetrovykh rightly pointed out in the comment above, there is no ambiguity as to how to interpret the expression, it must always insert two distinct objects.Allow and require
INSERT DETACHED Foo
in the nestedINSERT
. The only benefit of this approach is visual consistency with other statements that already requireDETACHED
to refer toFoo
in the body of itsINSERT
, most importantly theUPDATE
statement.I now lean toward option 1), as it’s the least verbose option, and visual inconsistency with
UPDATE
can be explained in the error message and the documentation, whereas forcing theDISTINCT
noise word is a price you’ll need to pay every time.@1st1, thoughts?