Testing for null value in arrays - Mailing list pgsql-general

From Michael Dunn
Subject Testing for null value in arrays
Date
Msg-id 3A526FAF.5090902@2cactus.com
Whole thread Raw
Responses Re: Testing for null value in arrays
List pgsql-general
I am new to the list and somewhat new to PostgreSQL... so, if my
question seems mundane or trivial I apologize. I have a plpgsql function
that performs multiple inserts and updates on a variety of tables.  In
one particular instance the function tests an array for null.  If the
array is not null the record is inserted.  I can get the array to test
true to null but it fails when reversed.

*** A sample and simple version of what I am trying to do ***

CREATE FUNCTION sb_event_insert (_TEXT)
RETURNS bool
AS 'DECLARE
    argv_vector    ALIAS FOR $1;
    evnt_seq    INTEGER;

     BEGIN
    IF argv_vector = \'{}\'
    THEN
        evnt_seq := nextval(\'event_sequence\');
        INSERT INTO argv VALUES (evnt_seq, argv_vector);
    END IF;
END;'
LANGUAGE 'plpgsql';


This evaluates successfully and without errors... but, obviously I am
testing for not null.  It seems inefficient to use an IF - THEN - ELSE
statement here.  So, by reversing the evaluation

    IF argv_vector != \'{}\'

the function when executed fails with the following error:

SELECT sb_event_insert ('{}');

ERROR: Unable to identify an operator '<>' for types '_text' and
'unknown'.  You will have to retype this query using an explicit cast.

Regards, Michael Dunn


pgsql-general by date:

Previous
From: Lincoln Yeoh
Date:
Subject: Re: Hierarchical queries in pgsql
Next
From: "SRINIVASARAGHAVAN,RAJESH (HP-Cupertino,ex1)"
Date:
Subject: programmatic interface into admin