Search Postgresql Archives

PL/pgSQL Function Help

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux