1

I am doing insert into one table record and generating UUID, how do I return this UUID to use in another part of my function?

function

do $$
begin 
 insert into table_1 values (uuid,,,,,,n);

-- need the result of this insert load into variable uuid_customer to reuse later

insert into tabel_2 (uuid,uuid_customer,,,,,,n );
end 

in MSSQL I can use output, but what about Postgres

INSERT INTO table (name) OUTPUT Inserted.ID VALUES('bob');

1 Answer 1

1

Try this :

WITH list AS
( insert into table_1 
  values (uuid,,,,,,n)
  returning uuid
)
SELECT uuid INTO uuid_customer ;
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.