Skip site navigation (1) Skip section navigation (2)

Checking empty array

From: Alexis Beuraud <alexis(at)siatel(dot)com>
To: "'pgsql-general(at)postgresql(dot)org'" <pgsql-general(at)postgresql(dot)org>
Subject: Checking empty array
Date: 2007-10-30 10:07:45
Message-ID: 20071030100749.71C879FB582@postgresql.org (view raw or flat)
Thread:
Lists: pgsql-general
Dear all,

What is the correct way to check whether an array is empty?
I have an array which I initialize with '{}' and then do som array_append
under some circonstances. I would like to know whether the array is empty at
the end of the function. I have not found the answer in the help page nor on
the web. I use the keyword isnull but that does not seem to work in all the
cases.
I would appreciate if someone could put this piece of information into the
Postgres documentation.

Here is what I do, in pseudo-code:

myarray varchar[];
myarray :=   '{}';

FOR ___ LOOP
 IF (___) THEN 
    myarray := array_append(myarray, somestuff);
 END IF;
END LOOP;

-- Is my array empty now?
IF (myarray isnull) THEN
__
END IF;

Regards,
Alexis Beuraud


Responses

pgsql-general by date

Next:From: Richard HuxtonDate: 2007-10-30 10:32:11
Subject: Re: Checking empty array
Previous:From: vincentDate: 2007-10-30 09:08:03
Subject: Re: Selecting K random rows - efficiently!

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group