To do this between databases you must use the foreign data wrapper postgres_fdw
or use dblink
. See the documentation. PostgreSQL doesn't support cross-database SELECT
.
Often, if you find yourself wanting to do this, you should be using separate schemas in a single database instead.
BTW, it's generally:
INSERT INTO ... SELECT ...
i.e. there's no subquery, no parentheses. That's because the VALUES
clause is actually a standalone statement too:
INSERT INTO ... VALUES ...
observe:
regress=> VALUES (1,2), (2,3);
column1 | column2
---------+---------
1 | 2
2 | 3
(2 rows)