PL/pgSQL Function Help - Mailing list pgsql-general

From Niblett, David A
Subject PL/pgSQL Function Help
Date
Msg-id 94FE9AAAB50C92448DCF1A4B99816F660284A3@GRUCLXCHGPR01.gruadmin.gru.com
Whole thread Raw
Responses Re: PL/pgSQL Function Help
List pgsql-general
I've got an issue with a plpgsql function and I have not
been able to find any reference to this situation in searching.
I hope that someone can point me in the correct direction.

I'm running v8.0.3 and assuming a test set up of:
-----------------------------
CREATE TYPE myrec AS (
    id int
);

CREATE OR REPLACE FUNCTION test(x int) RETURNS myrec
    AS '
  DECLARE
    output RECORD;
  BEGIN
    IF x THEN
      RETURN NULL;
    END IF;

    SELECT INTO output 9999;
    RETURN output;
  END;
'
    LANGUAGE plpgsql;
-----------------------------

Testing the function yields:
-----------------------------
xxx=# select * from test(0);
  id
------
 9999
(1 row)

xxx=# select * from test(1);
 id
----

(1 row)
-----------------------------

My dilema is that the program I'm trying to write this
function for (not mine) expects that if (in this case) a
1 is sent, it should have zero rows returned (0 affected
rows).  It seems that any time I have a return type of
a record I'll get a nice NULL record, but it still counts
as something.

Is there no way in Postgres that I can simply not return
anything so I show zero rows?

Thanks.

--
David

pgsql-general by date:

Previous
From: "Qingqing Zhou"
Date:
Subject: Re: Migration tool from MS SQL server 7.0
Next
From: Madison Kelly
Date:
Subject: Re: Getting a DB password to work without editing pg_hba.conf,