Thread: Using PERFORM in plpgsql throws compile errors
Hi, I am trying to create a really simple pl/pgsql based function to simply return true or false depending on a query result ... As I do not need the query result row, I want to use PERFORM to dump the resulting data ... So, here's my attempt: CREATE OR REPLACE FUNCTION islicensed(int8, int8) RETURNS bool AS ' DECLARE pID ALIAS FOR $1; aID ALIAS FOR $2; BEGIN PERFORM SELECT * FROM transactions x INNER JOIN tx_items i ON(x.id = i.tx_id) where i.archive_id=aID and x.status=\'valid\' and x.person_id=pID; RETURN FOUND; END; ' LANGUAGE 'plpgsql'; However, even so the creation statement succeeds, any attempt to call this function throws a compilation error: ERROR: syntax error at or near "SELECT" at character 9 CONTEXT: PL/pgSQL function "islicensed" line 5 at perform Why this? As I understand the docs, this is how it should work!?! Any help is highly appreciated. Oh, PostgreSQL 7.4.1 running on RH Linux ES 3.0 (not from RH rpm, but compiled from sources) ... Thanks, Chris
Christian Armeanu wrote: > Hi, > > I am trying to create a really simple pl/pgsql based function to simply > return true or false depending on a query result ... > > As I do not need the query result row, I want to use PERFORM to dump the > resulting data ... So, here's my attempt: > > CREATE OR REPLACE FUNCTION islicensed(int8, int8) RETURNS bool AS ' > DECLARE > pID ALIAS FOR $1; > aID ALIAS FOR $2; > BEGIN > PERFORM SELECT * FROM transactions x INNER JOIN tx_items i ON(x.id = > i.tx_id) where i.archive_id=aID and x.status=\'valid\' and x.person_id=pID; > RETURN FOUND; > END; > ' LANGUAGE 'plpgsql'; > > > However, even so the creation statement succeeds, any attempt to call > this function throws a compilation error: > > ERROR: syntax error at or near "SELECT" at character 9 > CONTEXT: PL/pgSQL function "islicensed" line 5 at perform > > Why this? As I understand the docs, this is how it should work!?! > > Any help is highly appreciated. > > Oh, PostgreSQL 7.4.1 running on RH Linux ES 3.0 (not from RH rpm, but > compiled from sources) ... Remove the SELECT on the PERFORM statement: PERFORM * FROM .... Regards Gaetano Mendola