Search Postgresql Archives

Re: PL/pgSQL: SELECT INTO only if result count = 1

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Tarlika Elisabeth Schmitz <postgresql6@xxxxxxxxxxxxxxxxxxxx> writes:
> SELECT INTO
> country_id, region_id, town_id
> country_fk, region_fk, id
> FROM town
> WHERE ...; 

> GET DIAGNOSTICS cnt = ROW_COUNT; 
> RAISE DEBUG 'COUNT %', cnt;
 
> always returns 1

Yeah.  By default, SELECT INTO just fetches one row and stops;
it doesn't look to see if there are more.

You could possibly use SELECT INTO STRICT and catch the error if
there's more than one row.  I suspect though that it'd be more efficient
to use a FOR loop and just note for yourself how many rows you get.

			regards, tom lane

-- 
Sent via pgsql-general mailing list (pgsql-general@xxxxxxxxxxxxxx)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux