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

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: PL/pgSQL: SELECT INTO only if result count = 1
Дата
Msg-id 15694.1314484574@sss.pgh.pa.us
обсуждение исходный текст
Ответ на Re: PL/pgSQL: SELECT INTO only if result count = 1  (Tarlika Elisabeth Schmitz <postgresql6@numerixtechnology.de>)
Ответы Re: PL/pgSQL: SELECT INTO only if result count = 1
Список pgsql-general
Tarlika Elisabeth Schmitz <postgresql6@numerixtechnology.de> 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

В списке pgsql-general по дате отправления:

Предыдущее
От: Darren Duncan
Дата:
Сообщение: Re: Still no way to install PostGres on os x Lion?
Следующее
От: shuaixf
Дата:
Сообщение: Whether the function exists a in pgsql table or not?