pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Zac <zaccheob@inwind.it>
To: pgsql-sql@postgresql.org
Subject: SELECT INTO returning more than one row
Date: Tue, 21 Jun 2005 11:54:41 +0200
Message-ID: <d98o6p$i1p$1@news.hub.org> (raw)

Hi.

I have this problem in a plpgsql function:

SELECT INTO myvar col FROM table WHERE ...;

IF <query returns more than one row> THEN
	do something
ELSE IF <query returns no rows> THEN
	do something else
ELSE
	do other things

If <query returns no rows> I know that myvar IS NULL OR GET DIAGNOSTICS 
ROW_COUNT is zero.

Is there a way to know if the query returned more than one row?
In Oracle PL/SQL I can catch the TOO_MANY_ROWS exception but in Postgres 
I found no way for doing it:

- myvar is correctly valued with the first occurrence of the result
- FOUND is TRUE
- GET DIAGNOSTICS ROW_COUNT is 1 (it counts only fetched rows)

I tried to use a cursor but the only way to know how many rows it 
returned is to fetch them all. (And I don't like this solution)

Thanks in advance.



Message-ID: <d98o6p$i1p$1@news.hub.org>
Permalink:  ../d98o6p$i1p$1@news.hub.org/
Also on:    postgresql.org/message-id/d98o6p$i1p$1@news.hub.org

 · 

reply

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: zaccheob@inwind.it
  Subject: Re: SELECT INTO returning more than one row
  In-Reply-To: <d98o6p$i1p$1@news.hub.org>

* 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