Pgsql. Returning field as insert result in function Pgsql. Returning field as insert result in function postgresql postgresql

Pgsql. Returning field as insert result in function


Try this:

INSERT INTO table(id,field)VALUES($id,$value)RETURNING id into var;


You could also use:

var := (INSERT INTO table(id,field) VALUES($id,$value) RETURNING id);

Readability is of course a personal preference, but I like this syntax because it shows an obvious assignment.