I'm trying to return an ID from a function like this:
CREATE OR REPLACE FUNCTION fx (myTable text, myValue text) returns int
as $$
DECLARE
sqlQuery TEXT;
resultId INT;
BEGIN
sqlQuery :=
'INSERT INTO '
|| myTable || ' (id, some_column) values'
|| ' ('
|| 'nextval(' || quote_literal('seq_' || myTable) || ')'
|| ',' || myValue
|| ') RETURNING id INTO ' || resultId;
EXECUTE sqlQuery;
RETURN resultId;
END;
$$
LANGUAGE plpgsql;
select fx('some_table', 'some_value');
But is not working.
How can I get this ID from sql query string executed?
But is not working.Seriously: please provide proper information with your questions. Always include your version of Postgres and always the verbatim error message if applicable.