I am writing a unit test for my PostgreSQL functionality. This starts with inserting data in the database and then calling a certain function. However, because I use auto-incrementing IDs, I cannot know what parameter to put in my function call.
I want to be able to do something like this:
INSERT INTO myTable ...;
SELECT id FROM myTable INTO l_id;
SELECT my_function(l_id);
Updates
- I am using an SQL script, not PL/pgSQL
- In MySQL I can do this:
SELECT @id:=itemid FROM myTable;
, then later on, I can use@id
anywhere I like.