From: Christoph Haller <ch@rodos.fzk.de>
To: fduch@antar.bryansk.ru
Cc: pgsql-sql@postgresql.org
Subject: Re: Row count after SELECT INTO?
Date: Thu, 15 Apr 2004 16:58:48 METDST
Message-ID: <200404151458.QAA03227@rodos> (raw)
In-Reply-To: <20040407190426.GI41029@dyatel.antar.bryansk.ru>
>
> Dear SQL and plPgSQL gurus, I seek for your wisdom.
>
> I have a variable assignment via SELECT INTO in my function, and I want
> to separate 3 cases:
> 1) no rows found;
> 2) one row found;
> 3) many rows found (ambiguous select).
>
> The first case is simple, I use FOUND variable for it.
> But how about the third? I tried to GET DIAGNOSTICS nrows = ROW_COUNT,
> bit it seems to get only value of 0 or 1. Is this how it supposed to be
> when SELECTing INTO a single variable?
>
> The only way I see now is a FOR ... IN SELECT loop, and I woner if
> there is a simpler solution. Could you please help me?
>
>
> --
> Fduch M. Pravking
>
I think ROW_COUNT values of 0/1 when SELECTing INTO a single variable are correct.
Because you cannot see more than one row anyway.
If you simply want to know about the number of result rows and don't care about
the data, you may change your SELECT ... into a SELECT COUNT(...
and separate your 3 cases from there.
Otherwise you'll have to go to a FOR ... IN SELECT loop.
Regards, Christoph
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: ch@rodos.fzk.de, fduch@antar.bryansk.ru
Subject: Re: Row count after SELECT INTO?
In-Reply-To: <200404151458.QAA03227@rodos>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox