cockroach
cockroach copied to clipboard
sql: Support INSERT inside an INSERT
Support for something like the following would be nice
INSERT INTO orders VALUES (@OrderId, (INSERT INTO customers VALUES (@Id, @Name) RETURNING id))
cc: @dianasaur323 or @awoods187
@awoods187 would be the right person here
@JackHerring thanks for your request. We will be unable to address this request in the near time period, however, I've noted it for the long-term roadmap.
@JackHerring I believe this feature is supported already in CockroachDB 1.1 and 2.0.
Two syntaxes are possible:
- CockroachDB-specific:
insert into ab(a,b) values (1, (select * from [insert into a(a) values(2) returning a])); - Using standard SQL CTEs:
with v as (insert into a(a) values(2) returning a) insert into ab(a,b) values (1, (select * from v));
Let us know if you have any further question or comment.