Quantcast
Channel: dBforums – Everything on Databases, Design, Developers and Administrators
Viewing all articles
Browse latest Browse all 13329

Can't adapt pgplsql function for v8.1

$
0
0
Hello everyone :),

Some time ago with some suffering I made a pgplsql function for the v8.4 to reserve auto-generated ids before some massive but unfortunately "id fixed" transactions and it works just fine. Today I've tried to execute it in v8.1 and I get an error saying:
Quote:

ERROR: RETURN cannot have a parameter in function returning set; use RETURN NEXT in or close to «QUERY»
Just to clarify: yes, I'm actually trying to downgrade the compatibility to version 8.1 since using any more recent version is not an option in my case.

The function itself:
Code:

CREATE OR REPLACE FUNCTION schema1.reserve_medcomprado(in_regcount integer, in_tempname character varying)
  RETURNS SETOF integer AS
$BODY$
BEGIN
        SET SEARCH_PATH TO 'schema1';

        EXECUTE 'CREATE TABLE ' || QUOTE_IDENT(in_tempname) || ' (idmedcomprado integer NOT NULL) WITH (OIDS=FALSE)';

        FOR i IN 1..in_regcount LOOP
                EXECUTE 'INSERT INTO ' || QUOTE_IDENT(in_tempname) || $q$ VALUES(nextval('schema1.medcomprado_idmedcomprado_seq'))$q$;
        END LOOP;
       
        RETURN QUERY EXECUTE 'SELECT * FROM ' || QUOTE_IDENT(in_tempname);

        EXECUTE 'DROP TABLE IF EXISTS ' || QUOTE_IDENT(in_tempname);
END;
$BODY$
  LANGUAGE plpgsql VOLATILE
  COST 100
  ROWS 1000;

I'm pretty new to pgplsql so I've got no ideas how to correct the issue and make the function more "compatible".

Any ideas?

Viewing all articles
Browse latest Browse all 13329

Trending Articles