I would like to insert a blank record into a table and have its serial
primary key value update. I would then like to get the new value and insert it into a temporary table. This will take place within a function using language plpgsql
.
So far I have this:
CREATE TEMP TABLE _InsertedpostID ( -- to store inserted postid
postid int
);
INSERT INTO post
(
postid, --serial which needs to be held in the temp table above
title,
location
)
VALUES(NULL);
--- here I need to get the just inserted postid serial and put it into the _InsertedpostID table
The above does not insert anything (I grabbed the solution from a MySQL answer). It returns an error of:
[42601] ERROR: INSERT has more target columns than expressions
Removing the VALUES(NULL);
part does not work either like it does in SQL Server. How can I therefore insert a blank record with only the serial
updating?
Once a new record is generated with a new serial
number, how do I output that back into the temp table?