I am trying to obtain a value obtained from a SELECT
, and then INSERT
that value, together with other values, into another table:
WITH data AS (SELECT name FROM programmes WHERE id = $1)
INSERT INTO purchases (name, other_details, some_more_stuff)
VALUES (data.name, $2, $3) FROM data;
But PostgreSQL gives 42601 ERROR: syntax error at or near "FROM" LINE 1: ...(data.name, $2, $3) FROM data
.
INSERT
's documentation doesn't give any example of VALUES
and FROM
together in the same query. What is the correct syntax for this kind of query? Or is it not possible to phrase my query in this manner?