As described in the PostgreSQL manual one can add multiple rows in a single INSERT statement:
INSERT INTO films (code, title, did, date_prod, kind) VALUES
('6717', 'Tampopo', 110, '1985-02-10', 'Comedy'),
('6120', 'The Dinner Game', 140, DEFAULT, 'Comedy');
Also a nested SELECT query like this works:
INSERT INTO films (code, title, did, date_prod, kind)
SELECT table.code, 'Tampopo', 110, '1985-02-10', 'Comedy'
FROM other_table AS table2;
However, I can't seem to figure out a way to do both at the same time:
INSERT INTO films (code, title, did, date_prod, kind)
SELECT
(table.code + 100, 'abc', NULL, t2.date_prod, t2.kind),
(table.code + 200, 'xyz', NULL, t2.date_prod, t2.kind)
FROM other_table AS t2;
If other_table contained only (61717 | 'Tampopo' | NULL | '1985-02-10' | 'Comedy'), the result table would look like this:
code | title | did | date_prod | kind
--------------------------------------------------
61817 | 'abc' | NULL | '1985-02-10' | 'Comedy'
61917 | 'xyz' | NULL | '1985-02-10' | 'Comedy'
This fiddle should explain it further...
Could you please point me to where I am going wrong. If possible, I would like to avoid multiple lookups in other_table AS t2 because it is a VIEW and it takes considerable time to construct.
table.code + 100is also not going to work.codeseems to be a character column, you can't use+with strings. Plus: what is the expected result of'HG120' + 100- that doesn't make sense.INT.