Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris

Re: Returning multiple rows from pgplsql to DBI

by erix (Parson)
on May 30, 2018 at 13:28 UTC ( #1215456=note: print w/replies, xml ) Need Help??

in reply to Returning multiple rows from pgplsql to DBI

I discovered a postgres bug in rowtype

If you can explain what the bug is I'll have it fixed. (Please mention what platform and software versions are used)

  • Comment on Re: Returning multiple rows from pgplsql to DBI

Replies are listed 'Best First'.
Re^2: Returning multiple rows from pgplsql to DBI
by (anonymized user) (Curate) on May 30, 2018 at 13:52 UTC
    In the below code, the FOR doc IN SELECT ... loop was returning a NULL in doc_typeid - impossible because it has a foreign key constraint on it. By luck I found that modifying it to FOR doc in SELECT doc_id, doc_typeid magically forced the correct value into doc_typeid (luck because I didn't need to select doc_id). When I changed the declaration of doc to record instead of a rowtype and removed the kludgey doc_id from the SELECT, it also worked correctly. These different tests led me to conclude that something other than the list of selected columns in the SELECT was determining the result set - perhaps the columns as ordered in the doc table at the last creation or alter table event are driving the population of the rowtype variable instead. So perhaps because record does not depend on any tables, my workaround to replace the rowtype declaration with record worked first time.
    CREATE OR REPLACE FUNCTION public."doct_GetActMask"( parm_holid bigint, parm_holtype character varying) RETURNS integer AS $BODY$DECLARE doc document%ROWTYPE;; actmask integer := 0; doctpid integer := NULL; approved integer := NULL; verified integer := NULL; logok integer := NULL; BEGIN SELECT docs_id FROM public."DocumentStatus" WHERE docs_shortname = 'Approved' INTO approved; SELECT docs_id FROM public."DocumentStatus" WHERE docs_shortname = 'Verified' INTO verified; FOR doc IN SELECT doc_type_id FROM document WHERE doc_hol_id = parm_holid AND (doc_docsid = approved OR doc_docsid = verified) LOOP SELECT public."doct_GetRoot"(doc.doc_type_id) INTO doctpid; IF doctpid < 0 THEN RETURN doctpid; END IF; actmask := actmask | (1<<(doctpid-1)); END LOOP; RETURN actmask; END$BODY$ LANGUAGE plpgsql VOLATILE COST 100; ALTER FUNCTION public."doct_GetActMask"(bigint, character varying) OWNER TO mydbo;

    One world, one people

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1215456]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (4)
As of 2020-10-28 11:26 GMT
Find Nodes?
    Voting Booth?
    My favourite web site is:

    Results (260 votes). Check out past polls.