X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.2]) by svr1.postgresql.org (Postfix) with ESMTP id 67535D1E0CD for ; Thu, 15 Apr 2004 11:58:56 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (neptune.hub.org [200.46.204.2]) (amavisd-new, port 10024) with ESMTP id 73293-03 for ; Thu, 15 Apr 2004 11:58:58 -0300 (ADT) Received: from fzkmail2.fzk.de (fzkmail2.fzk.de [141.52.27.52]) by svr1.postgresql.org (Postfix) with SMTP id C2AFBD1DB99 for ; Thu, 15 Apr 2004 11:58:52 -0300 (ADT) Received: FROM resy5.fzk.de BY fzkmail2.fzk.de ; Thu Apr 15 16:58:51 2004 +0200 Received: œby rodos.fzk.de with ESMTP (8.8.6 (PHNE_17135)/8.7.1) id QAA20670; Thu, 15 Apr 2004 16:58:51 +0200 (METDST) From: Christoph Haller Message-Id: <200404151458.QAA03227@rodos> Subject: Re: Row count after SELECT INTO? To: fduch@antar.bryansk.ru (Alexander M. Pravking) Date: Thu, 15 Apr 2004 16:58:48 METDST Cc: pgsql-sql@postgresql.org In-Reply-To: <20040407190426.GI41029@dyatel.antar.bryansk.ru>; from "Alexander M. Pravking" at Apr 7, 104 10:17 pm X-Mailer: Elm [revision: 212.4] X-Virus-Scanned: by amavisd-new at postgresql.org X-Amavis-Alert: BAD HEADER Non-encoded 8-bit data (char 9C hex) in message header 'Received' Received: \234by rodos.fzk.de... ^ X-Archive-Number: 200404/140 X-Sequence-Number: 17515 > > 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