| From: | Tarlika Elisabeth Schmitz <postgresql6(at)numerixtechnology(dot)de> |
|---|---|
| To: | pgsql-general <pgsql-general(at)postgresql(dot)org> |
| Subject: | Re: PL/pgSQL: SELECT INTO only if result count = 1 |
| Date: | 2011-08-27 23:20:28 |
| Message-ID: | 20110828002028.2f040e14@dick.coachhouse |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-general |
On Sat, 27 Aug 2011 18:36:14 -0400
Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
>Tarlika Elisabeth Schmitz <postgresql6(at)numerixtechnology(dot)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.
What a life saver late on a Saturday night! That does the trick.
--
Best Regards,
Tarlika Elisabeth Schmitz
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Andrej | 2011-08-28 04:43:22 | Re: Using Postgresql as application server |
| Previous Message | Tom Lane | 2011-08-27 22:36:14 | Re: PL/pgSQL: SELECT INTO only if result count = 1 |