I have following two tables:-
postgres=# select * from district;
id | name
----+-----------
1 | Ahmedabad
2 | Barmer
(2 rows)
postgres=# select * from wa
Vao Tsun has the correct answer for using insert . . . select
(and duly upvoted).
However, you are trying to use a subquery in values()
. That is allowed, but a subquery needs its own parentheses. So your version would work as:
insert into warehouse (name, district_id)
values ( 'Ghodasar-WH', (select id from district where name = 'Ahmedabad') );