Testing for null value in arrays

Поиск
Список
Период
Сортировка
От Michael Dunn
Тема Testing for null value in arrays
Дата
Msg-id 3A526FAF.5090902@2cactus.com
обсуждение исходный текст
Ответы Re: Testing for null value in arrays
Список 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 по дате отправления:

Предыдущее
От: Lincoln Yeoh
Дата:
Сообщение: Re: Hierarchical queries in pgsql
Следующее
От: "SRINIVASARAGHAVAN,RAJESH (HP-Cupertino,ex1)"
Дата:
Сообщение: programmatic interface into admin