Say I have a table with the following columns:
a: integer
b: integer
c: integer
d: integer
code: text
(a, b) is a foreign key to another table 1
(c, d) is a foreign key to another table 2
Inserting is easy:
INSERT INTO table(a, b, c, d, code) VALUES(x1, y1, x2, y2, 'my code')
Now, I would like to insert while fetching the values of my composite foreign keys a,b and c,d in a subquery. Something like this:
INSERT INTO table(a, b, c, d, code) VALUES
((SELECT a, b FROM other-table-1 WHERE ...),
(SELECT c, d FROM other-table-2 WHERE ...), 'my code')
The query above doesn't work ofcourse, but it illustrates what I am trying to achieve.
Another try, but also not working (the sub-query has to return one column):
INSERT INTO table(a, b, code)
SELECT (SELECT a, b FROM other-table-1 WHERE ...),
(SELECT c, d FROM other-table-2 WHERE ...), 'my code')
Is this somehow possible?