Re: PL/pgSQL: #option select_into_1_row (was SELECT INTO

Lists: pgsql-hackerspgsql-patches
From: Matt Miller <mattm(at)epx(dot)com>
To: pgsql-patches <pgsql-patches(at)postgresql(dot)org>
Subject: PL/pgSQL: SELECT INTO EXACT
Date: 2005-07-29 20:18:14
Message-ID: 1122668294.3600.29.camel@dbamm01-linux
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

This patch implements an optional EXACT keyword after the INTO keyword
of the PL/pgSQL SELECT INTO command. The motivation is to come closer
to Oracle's SELECT INTO behavior: when SELECTing INTO scalar targets,
raise an exception and leave the targets untouched if the query does not
return exactly one row. This patch does not go so far as to raise an
exception, but it can simplify porting efforts from PL/SQL. I also feel
that this EXACT behavior is overall a bit cleaner than the current
PL/pgSQL behavior. Maybe I've just been brainwashed by years of
Oracle'ing.

Here are three excerpts from the patched PL/pgSQL documentation:

"If the EXACT option is specified, then target will not be set unless
the query returns exactly one row"

"You can check the special FOUND variable after a SELECT INTO to
determine whether the statement was successful. ... an EXACT query is
successful only if exactly 1 row is returned."

"...GET DIAGNOSTICS (see Section 35.6.6) to retrieve ROW_COUNT. After a
SELECT INTO EXACT statement ROW_COUNT ... will be equal to 0, 1, or 2,
indicating no matching rows, exactly one matching row, or greater than
one matching row, respectively."

Attachment Content-Type Size
select_into_exact.patch text/x-patch 11.4 KB

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Matt Miller <mattm(at)epx(dot)com>
Cc: pgsql-patches <pgsql-patches(at)postgresql(dot)org>
Subject: Re: PL/pgSQL: SELECT INTO EXACT
Date: 2005-07-29 21:52:55
Message-ID: 21957.1122673975@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

Matt Miller <mattm(at)epx(dot)com> writes:
> This patch implements an optional EXACT keyword after the INTO keyword
> of the PL/pgSQL SELECT INTO command. The motivation is to come closer
> to Oracle's SELECT INTO behavior: when SELECTing INTO scalar targets,
> raise an exception and leave the targets untouched if the query does not
> return exactly one row. This patch does not go so far as to raise an
> exception, but it can simplify porting efforts from PL/SQL.

Uh, what's the point of being only sort-of compatible? Why not throw
the exception?

I dislike the choice of "EXACT", too, as it (a) adds a new reserved word
and (b) doesn't seem to convey quite what is happening anyway. Not sure
about a better word though ... anyone?

regards, tom lane


From: Jaime Casanova <systemguards(at)gmail(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Matt Miller <mattm(at)epx(dot)com>, pgsql-patches <pgsql-patches(at)postgresql(dot)org>
Subject: Re: PL/pgSQL: SELECT INTO EXACT
Date: 2005-07-29 22:04:52
Message-ID: c2d9e70e05072915047223be0b@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

On 7/29/05, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
> Matt Miller <mattm(at)epx(dot)com> writes:
> > This patch implements an optional EXACT keyword after the INTO keyword
> > of the PL/pgSQL SELECT INTO command. The motivation is to come closer
> > to Oracle's SELECT INTO behavior: when SELECTing INTO scalar targets,
> > raise an exception and leave the targets untouched if the query does not
> > return exactly one row. This patch does not go so far as to raise an
> > exception, but it can simplify porting efforts from PL/SQL.
>
> Uh, what's the point of being only sort-of compatible? Why not throw
> the exception?
>
> I dislike the choice of "EXACT", too, as it (a) adds a new reserved word
> and (b) doesn't seem to convey quite what is happening anyway. Not sure
> about a better word though ... anyone?
>
> regards, tom lane
>

just wonder, why that is not the default behavior of the SELECT INTO?
at least, the first time i think the function was right until i found
that the first row of a set of rows was assigned...

i mean, when you do that code you are expecting just one row from your
query, doesn't you?

--
Atentamente,
Jaime Casanova
(DBA: DataBase Aniquilator ;)


From: Matt Miller <mattm(at)epx(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: pgsql-patches <pgsql-patches(at)postgresql(dot)org>
Subject: Re: PL/pgSQL: SELECT INTO EXACT
Date: 2005-07-29 22:43:13
Message-ID: 1122676993.7396.32.camel@dbamm01-linux
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

On Fri, 2005-07-29 at 17:52 -0400, Tom Lane wrote:
> Matt Miller <mattm(at)epx(dot)com> writes:
> > The motivation is to come closer to Oracle's SELECT INTO
> > behavior: when SELECTing INTO scalar targets,
> > raise an exception and leave the targets untouched if the query does
> > not return exactly one row. This patch does not go so far as
> > to raise an exception

> Uh, what's the point of being only sort-of compatible? Why not throw
> the exception?

I guess my hesitation is that the PL/SQL notion of the exception as a
program flow control technique is a bit at odds with the PL/pgSQL notion
of the exception as a transaction control mechanism. Maybe these
notions could be reconciled by a new NOSAVE option to the EXCEPTION
block definition, to suppress the savepoint and the exception-induced
rollback for that BEGIN ... END block. Then an automatically-thrown
exception would not be so expensive.

> I dislike the choice of "EXACT", too, as it (a) adds a new
> reserved word and (b) doesn't seem to convey quite what is
> happening anyway

The motivation is that EXACTly one row must be returned.

Maybe UNIQUE instead of EXACT?


From: Matt Miller <mattm(at)epx(dot)com>
To: Jaime Casanova <systemguards(at)gmail(dot)com>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, pgsql-patches <pgsql-patches(at)postgresql(dot)org>
Subject: Re: PL/pgSQL: SELECT INTO EXACT
Date: 2005-07-29 22:47:18
Message-ID: 1122677238.7396.35.camel@dbamm01-linux
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

> > The motivation is to come closer
> > to Oracle's SELECT INTO behavior: when SELECTing INTO scalar targets,
> > raise an exception and leave the targets untouched if the query does not
> > return exactly one row.

> why that is not the default behavior of the SELECT INTO?
> ...
> i mean, when you do that code you are expecting just one row from your
> query

I agree. I suppose I was fearful of breaking existing stuff, so I added
a new keyword.


From: Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us>
To: Matt Miller <mattm(at)epx(dot)com>
Cc: pgsql-patches <pgsql-patches(at)postgresql(dot)org>
Subject: Re: PL/pgSQL: SELECT INTO EXACT
Date: 2005-07-30 04:23:57
Message-ID: 200507300423.j6U4NvI22516@candle.pha.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches


This has been saved for the 8.2 release:

http://momjian.postgresql.org/cgi-bin/pgpatches_hold

---------------------------------------------------------------------------

Matt Miller wrote:
> This patch implements an optional EXACT keyword after the INTO keyword
> of the PL/pgSQL SELECT INTO command. The motivation is to come closer
> to Oracle's SELECT INTO behavior: when SELECTing INTO scalar targets,
> raise an exception and leave the targets untouched if the query does not
> return exactly one row. This patch does not go so far as to raise an
> exception, but it can simplify porting efforts from PL/SQL. I also feel
> that this EXACT behavior is overall a bit cleaner than the current
> PL/pgSQL behavior. Maybe I've just been brainwashed by years of
> Oracle'ing.
>
> Here are three excerpts from the patched PL/pgSQL documentation:
>
> "If the EXACT option is specified, then target will not be set unless
> the query returns exactly one row"
>
> "You can check the special FOUND variable after a SELECT INTO to
> determine whether the statement was successful. ... an EXACT query is
> successful only if exactly 1 row is returned."
>
> "...GET DIAGNOSTICS (see Section 35.6.6) to retrieve ROW_COUNT. After a
> SELECT INTO EXACT statement ROW_COUNT ... will be equal to 0, 1, or 2,
> indicating no matching rows, exactly one matching row, or greater than
> one matching row, respectively."

[ Attachment, skipping... ]

>
> ---------------------------(end of broadcast)---------------------------
> TIP 3: Have you checked our extensive FAQ?
>
> http://www.postgresql.org/docs/faq

--
Bruce Momjian | http://candle.pha.pa.us
pgman(at)candle(dot)pha(dot)pa(dot)us | (610) 359-1001
+ If your life is a hard drive, | 13 Roberts Road
+ Christ can be your backup. | Newtown Square, Pennsylvania 19073


From: Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us>
To: Matt Miller <mattm(at)epx(dot)com>
Cc: pgsql-patches <pgsql-patches(at)postgresql(dot)org>
Subject: Re: PL/pgSQL: SELECT INTO EXACT
Date: 2005-07-30 04:24:25
Message-ID: 200507300424.j6U4OPW22653@candle.pha.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches


Sorry, patch removed from the queue. I now see the later discussion.

---------------------------------------------------------------------------

Matt Miller wrote:
> This patch implements an optional EXACT keyword after the INTO keyword
> of the PL/pgSQL SELECT INTO command. The motivation is to come closer
> to Oracle's SELECT INTO behavior: when SELECTing INTO scalar targets,
> raise an exception and leave the targets untouched if the query does not
> return exactly one row. This patch does not go so far as to raise an
> exception, but it can simplify porting efforts from PL/SQL. I also feel
> that this EXACT behavior is overall a bit cleaner than the current
> PL/pgSQL behavior. Maybe I've just been brainwashed by years of
> Oracle'ing.
>
> Here are three excerpts from the patched PL/pgSQL documentation:
>
> "If the EXACT option is specified, then target will not be set unless
> the query returns exactly one row"
>
> "You can check the special FOUND variable after a SELECT INTO to
> determine whether the statement was successful. ... an EXACT query is
> successful only if exactly 1 row is returned."
>
> "...GET DIAGNOSTICS (see Section 35.6.6) to retrieve ROW_COUNT. After a
> SELECT INTO EXACT statement ROW_COUNT ... will be equal to 0, 1, or 2,
> indicating no matching rows, exactly one matching row, or greater than
> one matching row, respectively."

[ Attachment, skipping... ]

>
> ---------------------------(end of broadcast)---------------------------
> TIP 3: Have you checked our extensive FAQ?
>
> http://www.postgresql.org/docs/faq

--
Bruce Momjian | http://candle.pha.pa.us
pgman(at)candle(dot)pha(dot)pa(dot)us | (610) 359-1001
+ If your life is a hard drive, | 13 Roberts Road
+ Christ can be your backup. | Newtown Square, Pennsylvania 19073


From: Matt Miller <mattm(at)epx(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: pgsql-patches <pgsql-patches(at)postgresql(dot)org>
Subject: Re: PL/pgSQL: SELECT INTO EXACT
Date: 2005-08-08 21:01:09
Message-ID: 1123534870.3062.56.camel@dbamm01-linux
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

On Fri, 2005-07-29 at 17:52 -0400, Tom Lane wrote:
> Matt Miller <mattm(at)epx(dot)com> writes:
> > This patch implements an optional EXACT keyword after the INTO keyword
> > of the PL/pgSQL SELECT INTO command. ... when SELECTing INTO ...
> > leave the targets untouched if the query does not
> > return exactly one row.
>
> I dislike the choice of "EXACT", too, as it (a) adds a new reserved word
> and (b) doesn't seem to convey quite what is happening anyway. Not sure
> about a better word though ... anyone?

I don't know how to avoid adding a keyword, unless the proposed EXACT
behavior just replaces the current behavior, potentially breaking
existing code. Is there a precedent for language-specific GUC vars?

I think the EXACT behavior is more reasonable overall, and maybe a
stepped approach can replace the current behavior with the EXACT flavor.
To that end the option could support either EXACT or NOEXACT, with
NOEXACT initially being the default. Eventually EXACT could become the
default, and finally the NOEXACT option could be dropped altogether. At
that point the EXACT keyword would be dropped as well.

I can attach a patch that supports [EXACT | NOEXACT].


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Matt Miller <mattm(at)epx(dot)com>
Cc: pgsql-patches <pgsql-patches(at)postgresql(dot)org>
Subject: Re: PL/pgSQL: SELECT INTO EXACT
Date: 2005-08-08 21:18:53
Message-ID: 9332.1123535933@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

Matt Miller <mattm(at)epx(dot)com> writes:
> On Fri, 2005-07-29 at 17:52 -0400, Tom Lane wrote:
>> I dislike the choice of "EXACT", too, as it (a) adds a new reserved word
>> and (b) doesn't seem to convey quite what is happening anyway. Not sure
>> about a better word though ... anyone?

> I can attach a patch that supports [EXACT | NOEXACT].

Somehow, proposing two new reserved words instead of one doesn't seem
very responsive to my gripe :-(.

If you think that this should be a global option instead of a
per-statement one, something like the (undocumented) #option hack might
be a good way to specify it; that would give it per-function scope,
which seems reasonable.

create function myfn(...) returns ... as $$
#option select_into_1_row
declare ...
$$ language plpgsql;

regards, tom lane


From: Matt Miller <mattm(at)epx(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: pgsql-patches <pgsql-patches(at)postgresql(dot)org>
Subject: Re: PL/pgSQL: SELECT INTO EXACT
Date: 2005-08-08 21:45:54
Message-ID: 1123537554.3062.69.camel@dbamm01-linux
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

On Mon, 2005-08-08 at 17:18 -0400, Tom Lane wrote:
> Matt Miller <mattm(at)epx(dot)com> writes:
> > On Fri, 2005-07-29 at 17:52 -0400, Tom Lane wrote:
> >> I dislike the choice of "EXACT", too, as it (a) adds a new reserved word
> >> and (b) doesn't seem to convey quite what is happening anyway. Not sure
> >> about a better word though ... anyone?
>
> > I can attach a patch that supports [EXACT | NOEXACT].
>
> Somehow, proposing two new reserved words instead of one doesn't seem
> very responsive to my gripe :-(.

My intention was to introduce the idea that the current behavior should
be changed, and to then suggest a path that eventually eliminates all
the new reserved words.

> If you think that this should be a global option instead of a
> per-statement one, something like the (undocumented) #option hack might
> be a good way to specify it; that would give it per-function scope,
> which seems reasonable.
>
> create function myfn(...) returns ... as $$
> #option select_into_1_row
> declare ...
> $$ language plpgsql;
>

Thanks, I'll take a look at this.


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Matt Miller <mattm(at)epx(dot)com>
Cc: pgsql-patches <pgsql-patches(at)postgresql(dot)org>
Subject: Re: PL/pgSQL: SELECT INTO EXACT
Date: 2005-08-09 00:06:13
Message-ID: 10611.1123545973@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

Matt Miller <mattm(at)epx(dot)com> writes:
>>> I can attach a patch that supports [EXACT | NOEXACT].
>>
>> Somehow, proposing two new reserved words instead of one doesn't seem
>> very responsive to my gripe :-(.

> My intention was to introduce the idea that the current behavior should
> be changed, and to then suggest a path that eventually eliminates all
> the new reserved words.

Once you put 'em in, you can't ever really get rid of 'em :-( ... so I'd
prefer to investigate a path that doesn't use that syntax in the first
place.

regards, tom lane


From: Matt Miller <mattm(at)epx(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: pgsql-patches <pgsql-patches(at)postgresql(dot)org>
Subject: Re: PL/pgSQL: #option select_into_1_row (was SELECT INTO
Date: 2005-08-09 15:01:29
Message-ID: 1123599690.3231.4.camel@dbamm01-linux
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

On Mon, 2005-08-08 at 17:18 -0400, Tom Lane wrote:
> If you think that this should be a global option instead of a
> per-statement one, something like the (undocumented) #option hack might
> be a good way to specify it; that would give it per-function scope,
> which seems reasonable.
>
> create function myfn(...) returns ... as $$
> #option select_into_1_row
> declare ...
> $$ language plpgsql;

Attached is a patch that implements the "#option select_into_1_row"
directive as suggested.

Is it time to document this directive?

Attachment Content-Type Size
select_into_1_row.patch text/x-patch 4.3 KB

From: Matt Miller <mattm(at)epx(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: pgsql-patches <pgsql-patches(at)postgresql(dot)org>
Subject: Re: PL/pgSQL: #option select_into_1_row (was SELECT INTO
Date: 2005-08-11 15:04:36
Message-ID: 1123772676.3638.24.camel@dbamm01-linux
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

On Tue, 2005-08-09 at 15:01 +0000, Matt Miller wrote:
> Attached is a patch that implements the "#option select_into_1_row"
> directive as suggested.

Is this patch good-to-go? Can it be queued?


From: Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us>
To: Matt Miller <mattm(at)epx(dot)com>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, pgsql-patches <pgsql-patches(at)postgresql(dot)org>
Subject: Re: PL/pgSQL: #option select_into_1_row (was SELECT INTO
Date: 2005-08-11 15:24:45
Message-ID: 200508111524.j7BFOjA07786@candle.pha.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

Matt Miller wrote:
> On Tue, 2005-08-09 at 15:01 +0000, Matt Miller wrote:
> > Attached is a patch that implements the "#option select_into_1_row"
> > directive as suggested.
>
> Is this patch good-to-go? Can it be queued?

We are in feature freeze, so unless there is overwhelming community
support, it will be held for 8.2.

--
Bruce Momjian | http://candle.pha.pa.us
pgman(at)candle(dot)pha(dot)pa(dot)us | (610) 359-1001
+ If your life is a hard drive, | 13 Roberts Road
+ Christ can be your backup. | Newtown Square, Pennsylvania 19073


From: Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Matt Miller <mattm(at)epx(dot)com>, pgsql-patches <pgsql-patches(at)postgresql(dot)org>
Subject: Re: PL/pgSQL: SELECT INTO EXACT
Date: 2005-08-13 01:53:25
Message-ID: 200508130153.j7D1rPL20132@candle.pha.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches


This has been saved for the 8.2 release:

http://momjian.postgresql.org/cgi-bin/pgpatches_hold

---------------------------------------------------------------------------

Tom Lane wrote:
> Matt Miller <mattm(at)epx(dot)com> writes:
> >>> I can attach a patch that supports [EXACT | NOEXACT].
> >>
> >> Somehow, proposing two new reserved words instead of one doesn't seem
> >> very responsive to my gripe :-(.
>
> > My intention was to introduce the idea that the current behavior should
> > be changed, and to then suggest a path that eventually eliminates all
> > the new reserved words.
>
> Once you put 'em in, you can't ever really get rid of 'em :-( ... so I'd
> prefer to investigate a path that doesn't use that syntax in the first
> place.
>
> regards, tom lane
>
> ---------------------------(end of broadcast)---------------------------
> TIP 9: In versions below 8.0, the planner will ignore your desire to
> choose an index scan if your joining column's datatypes do not
> match
>

--
Bruce Momjian | http://candle.pha.pa.us
pgman(at)candle(dot)pha(dot)pa(dot)us | (610) 359-1001
+ If your life is a hard drive, | 13 Roberts Road
+ Christ can be your backup. | Newtown Square, Pennsylvania 19073


From: Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us>
To: Matt Miller <mattm(at)epx(dot)com>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, pgsql-patches <pgsql-patches(at)postgresql(dot)org>
Subject: Re: PL/pgSQL: #option select_into_1_row (was SELECT INTO
Date: 2005-08-13 02:42:36
Message-ID: 200508130242.j7D2ga702991@candle.pha.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches


This has been saved for the 8.2 release:

http://momjian.postgresql.org/cgi-bin/pgpatches_hold

---------------------------------------------------------------------------

Matt Miller wrote:
> On Mon, 2005-08-08 at 17:18 -0400, Tom Lane wrote:
> > If you think that this should be a global option instead of a
> > per-statement one, something like the (undocumented) #option hack might
> > be a good way to specify it; that would give it per-function scope,
> > which seems reasonable.
> >
> > create function myfn(...) returns ... as $$
> > #option select_into_1_row
> > declare ...
> > $$ language plpgsql;
>
> Attached is a patch that implements the "#option select_into_1_row"
> directive as suggested.
>
> Is it time to document this directive?

[ Attachment, skipping... ]

>
> ---------------------------(end of broadcast)---------------------------
> TIP 6: explain analyze is your friend

--
Bruce Momjian | http://candle.pha.pa.us
pgman(at)candle(dot)pha(dot)pa(dot)us | (610) 359-1001
+ If your life is a hard drive, | 13 Roberts Road
+ Christ can be your backup. | Newtown Square, Pennsylvania 19073


From: Matt Miller <mattm(at)epx(dot)com>
To: Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, pgsql-patches <pgsql-patches(at)postgresql(dot)org>
Subject: Re: PL/pgSQL: SELECT INTO EXACT
Date: 2005-08-15 14:03:38
Message-ID: 1124114618.3361.7.camel@dbamm01-linux
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

On Fri, 2005-08-12 at 21:53 -0400, Bruce Momjian wrote:
> This has been saved for the 8.2 release:

Just to clarify: the "SELECT INTO EXACT" patch was abandoned in favor of
the "#option select_into_1_row" patch. I submitted both patches as part
of the same -patches thread, but the latter solution, the "#option
select_into_1_row" patch, superseded the "SELECT INTO EXACT" idea.

The correct patch is at
http://archives.postgresql.org/pgsql-patches/2005-08/msg00070.php This
should be the only patch that gets applied.


From: Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us>
To: Matt Miller <mattm(at)epx(dot)com>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, PostgreSQL-development <pgsql-hackers(at)postgreSQL(dot)org>
Subject: Re: [PATCHES] PL/pgSQL: #option select_into_1_row (was SELECT INTO
Date: 2006-03-21 03:23:36
Message-ID: 200603210323.k2L3NaA14699@candle.pha.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

Matt Miller wrote:
> On Mon, 2005-08-08 at 17:18 -0400, Tom Lane wrote:
> > If you think that this should be a global option instead of a
> > per-statement one, something like the (undocumented) #option hack might
> > be a good way to specify it; that would give it per-function scope,
> > which seems reasonable.
> >
> > create function myfn(...) returns ... as $$
> > #option select_into_1_row
> > declare ...
> > $$ language plpgsql;
>
> Attached is a patch that implements the "#option select_into_1_row"
> directive as suggested.

Are we agreed this is the way we want to control this?

--
Bruce Momjian http://candle.pha.pa.us
SRA OSS, Inc. http://www.sraoss.com

+ If your life is a hard drive, Christ can be your backup. +


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us>
Cc: Matt Miller <mattm(at)epx(dot)com>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: [PATCHES] PL/pgSQL: #option select_into_1_row (was SELECT INTO
Date: 2006-03-21 03:30:39
Message-ID: 10581.1142911839@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us> writes:
> Are we agreed this is the way we want to control this?

AFAICT, no one except Matt wants this feature at all, so I'd much prefer
to drop the whole idea. I think it's a insufficiently justified kluge.

regards, tom lane


From: Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Matt Miller <mattm(at)epx(dot)com>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: [PATCHES] PL/pgSQL: #option select_into_1_row (was SELECT
Date: 2006-03-21 03:32:12
Message-ID: 200603210332.k2L3WCU16255@candle.pha.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

Tom Lane wrote:
> Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us> writes:
> > Are we agreed this is the way we want to control this?
>
> AFAICT, no one except Matt wants this feature at all, so I'd much prefer
> to drop the whole idea. I think it's a insufficiently justified kluge.

Fine. Unless I hear from the non-kludge croud, it is dropped. ;-)

--
Bruce Momjian http://candle.pha.pa.us
SRA OSS, Inc. http://www.sraoss.com

+ If your life is a hard drive, Christ can be your backup. +


From: Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us>
To: Matt Miller <mattm(at)epx(dot)com>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, PostgreSQL-development <pgsql-hackers(at)postgreSQL(dot)org>
Subject: Re: [PATCHES] PL/pgSQL: SELECT INTO EXACT
Date: 2006-06-14 13:18:31
Message-ID: 200606141318.k5EDIVh08130@candle.pha.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches


I did some work on your patch:

ftp://candle.pha.pa.us/pub/postgresql/mypatches/first

I switched the name of the option flag to FIRST (already a reserved
word), making the default behavior PL/SQL-compatible. I also added the
proper execptions to match PL/SQL. My Oracle 9 PL/SQL manual has for
SELECT INTO:

When you use a SELECT INTO statement without the BULK COLLECT clause, it
should return only one row. If it returns more than one row, PL/SQL
raises the predefined exception TOO_MANY_ROWS.

However, if no rows are returned, PL/SQL raises NO_DATA_FOUND unless the
SELECT statement called a SQL aggregate function such as AVG or SUM.
(SQL aggregate functions always return a value or a null. So, a SELECT
INTO statement that calls an aggregate function never raises
NO_DATA_FOUND.)

The big problem is that a lot of applications use the SELECT INTO ... IF
NOT FOUND test, and I don't see any good way to keep those applications
working without being modified.

The #option keyword seems as bad as just giving up on being PL/SQL
compatibile and using the keyword STRICT (already a reserved word) when
you want PL/SQL functionality.

I don't think a GUC is going to work because it will affect all
functions stored in the database, and their might be functions expecting
different behaviors. Setting the GUC in the function that needs it also
will not work because it will spill into functions called by that
function.

I think we set up SELECT INTO this way originally because we didn't have
execeptions, but now that we have them, I don't see a clean way to move
to the PL/SQL behavior. Perhaps STRICT is the best option.

Comments?

---------------------------------------------------------------------------

Matt Miller wrote:
> On Mon, 2005-08-08 at 17:18 -0400, Tom Lane wrote:
> > Matt Miller <mattm(at)epx(dot)com> writes:
> > > On Fri, 2005-07-29 at 17:52 -0400, Tom Lane wrote:
> > >> I dislike the choice of "EXACT", too, as it (a) adds a new reserved word
> > >> and (b) doesn't seem to convey quite what is happening anyway. Not sure
> > >> about a better word though ... anyone?
> >
> > > I can attach a patch that supports [EXACT | NOEXACT].
> >
> > Somehow, proposing two new reserved words instead of one doesn't seem
> > very responsive to my gripe :-(.
>
> My intention was to introduce the idea that the current behavior should
> be changed, and to then suggest a path that eventually eliminates all
> the new reserved words.
>
> > If you think that this should be a global option instead of a
> > per-statement one, something like the (undocumented) #option hack might
> > be a good way to specify it; that would give it per-function scope,
> > which seems reasonable.
> >
> > create function myfn(...) returns ... as $$
> > #option select_into_1_row
> > declare ...
> > $$ language plpgsql;
> >
>
> Thanks, I'll take a look at this.
>
> ---------------------------(end of broadcast)---------------------------
> TIP 2: Don't 'kill -9' the postmaster
>

--
Bruce Momjian http://candle.pha.pa.us
EnterpriseDB http://www.enterprisedb.com

+ If your life is a hard drive, Christ can be your backup. +


From: Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us>
To: Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us>
Cc: Matt Miller <mattm(at)epx(dot)com>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: [PATCHES] PL/pgSQL: SELECT INTO EXACT
Date: 2006-06-14 21:23:11
Message-ID: 200606142123.k5ELNBp24205@candle.pha.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches


I have update the patch at:

ftp://candle.pha.pa.us/pub/postgresql/mypatches/strict

I re-did it to use STRICT for Oracle PL/SQL syntax. I don't think we
are going to be able to do any better than that, even in future
versions. I added documentation that should help too.

---------------------------------------------------------------------------

Bruce Momjian wrote:
>
> I did some work on your patch:
>
> ftp://candle.pha.pa.us/pub/postgresql/mypatches/first
>
> I switched the name of the option flag to FIRST (already a reserved
> word), making the default behavior PL/SQL-compatible. I also added the
> proper execptions to match PL/SQL. My Oracle 9 PL/SQL manual has for
> SELECT INTO:
>
> When you use a SELECT INTO statement without the BULK COLLECT clause, it
> should return only one row. If it returns more than one row, PL/SQL
> raises the predefined exception TOO_MANY_ROWS.
>
> However, if no rows are returned, PL/SQL raises NO_DATA_FOUND unless the
> SELECT statement called a SQL aggregate function such as AVG or SUM.
> (SQL aggregate functions always return a value or a null. So, a SELECT
> INTO statement that calls an aggregate function never raises
> NO_DATA_FOUND.)
>
> The big problem is that a lot of applications use the SELECT INTO ... IF
> NOT FOUND test, and I don't see any good way to keep those applications
> working without being modified.
>
> The #option keyword seems as bad as just giving up on being PL/SQL
> compatibile and using the keyword STRICT (already a reserved word) when
> you want PL/SQL functionality.
>
> I don't think a GUC is going to work because it will affect all
> functions stored in the database, and their might be functions expecting
> different behaviors. Setting the GUC in the function that needs it also
> will not work because it will spill into functions called by that
> function.
>
> I think we set up SELECT INTO this way originally because we didn't have
> execeptions, but now that we have them, I don't see a clean way to move
> to the PL/SQL behavior. Perhaps STRICT is the best option.
>
> Comments?
>
> ---------------------------------------------------------------------------
>
> Matt Miller wrote:
> > On Mon, 2005-08-08 at 17:18 -0400, Tom Lane wrote:
> > > Matt Miller <mattm(at)epx(dot)com> writes:
> > > > On Fri, 2005-07-29 at 17:52 -0400, Tom Lane wrote:
> > > >> I dislike the choice of "EXACT", too, as it (a) adds a new reserved word
> > > >> and (b) doesn't seem to convey quite what is happening anyway. Not sure
> > > >> about a better word though ... anyone?
> > >
> > > > I can attach a patch that supports [EXACT | NOEXACT].
> > >
> > > Somehow, proposing two new reserved words instead of one doesn't seem
> > > very responsive to my gripe :-(.
> >
> > My intention was to introduce the idea that the current behavior should
> > be changed, and to then suggest a path that eventually eliminates all
> > the new reserved words.
> >
> > > If you think that this should be a global option instead of a
> > > per-statement one, something like the (undocumented) #option hack might
> > > be a good way to specify it; that would give it per-function scope,
> > > which seems reasonable.
> > >
> > > create function myfn(...) returns ... as $$
> > > #option select_into_1_row
> > > declare ...
> > > $$ language plpgsql;
> > >
> >
> > Thanks, I'll take a look at this.
> >
> > ---------------------------(end of broadcast)---------------------------
> > TIP 2: Don't 'kill -9' the postmaster
> >
>
> --
> Bruce Momjian http://candle.pha.pa.us
> EnterpriseDB http://www.enterprisedb.com
>
> + If your life is a hard drive, Christ can be your backup. +
>
> ---------------------------(end of broadcast)---------------------------
> TIP 1: if posting/reading through Usenet, please send an appropriate
> subscribe-nomail command to majordomo(at)postgresql(dot)org so that your
> message can get through to the mailing list cleanly
>

--
Bruce Momjian http://candle.pha.pa.us
EnterpriseDB http://www.enterprisedb.com

+ If your life is a hard drive, Christ can be your backup. +


From: Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us>
To: Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us>
Cc: Matt Miller <mattm(at)epx(dot)com>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: [PATCHES] PL/pgSQL: SELECT INTO EXACT
Date: 2006-06-15 18:02:12
Message-ID: 200606151802.k5FI2CA22922@candle.pha.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches


Patch applied. Thanks.

---------------------------------------------------------------------------

Bruce Momjian wrote:
>
> I have update the patch at:
>
> ftp://candle.pha.pa.us/pub/postgresql/mypatches/strict
>
> I re-did it to use STRICT for Oracle PL/SQL syntax. I don't think we
> are going to be able to do any better than that, even in future
> versions. I added documentation that should help too.
>
> ---------------------------------------------------------------------------
>
> Bruce Momjian wrote:
> >
> > I did some work on your patch:
> >
> > ftp://candle.pha.pa.us/pub/postgresql/mypatches/first
> >
> > I switched the name of the option flag to FIRST (already a reserved
> > word), making the default behavior PL/SQL-compatible. I also added the
> > proper execptions to match PL/SQL. My Oracle 9 PL/SQL manual has for
> > SELECT INTO:
> >
> > When you use a SELECT INTO statement without the BULK COLLECT clause, it
> > should return only one row. If it returns more than one row, PL/SQL
> > raises the predefined exception TOO_MANY_ROWS.
> >
> > However, if no rows are returned, PL/SQL raises NO_DATA_FOUND unless the
> > SELECT statement called a SQL aggregate function such as AVG or SUM.
> > (SQL aggregate functions always return a value or a null. So, a SELECT
> > INTO statement that calls an aggregate function never raises
> > NO_DATA_FOUND.)
> >
> > The big problem is that a lot of applications use the SELECT INTO ... IF
> > NOT FOUND test, and I don't see any good way to keep those applications
> > working without being modified.
> >
> > The #option keyword seems as bad as just giving up on being PL/SQL
> > compatibile and using the keyword STRICT (already a reserved word) when
> > you want PL/SQL functionality.
> >
> > I don't think a GUC is going to work because it will affect all
> > functions stored in the database, and their might be functions expecting
> > different behaviors. Setting the GUC in the function that needs it also
> > will not work because it will spill into functions called by that
> > function.
> >
> > I think we set up SELECT INTO this way originally because we didn't have
> > execeptions, but now that we have them, I don't see a clean way to move
> > to the PL/SQL behavior. Perhaps STRICT is the best option.
> >
> > Comments?
> >
> > ---------------------------------------------------------------------------
> >
> > Matt Miller wrote:
> > > On Mon, 2005-08-08 at 17:18 -0400, Tom Lane wrote:
> > > > Matt Miller <mattm(at)epx(dot)com> writes:
> > > > > On Fri, 2005-07-29 at 17:52 -0400, Tom Lane wrote:
> > > > >> I dislike the choice of "EXACT", too, as it (a) adds a new reserved word
> > > > >> and (b) doesn't seem to convey quite what is happening anyway. Not sure
> > > > >> about a better word though ... anyone?
> > > >
> > > > > I can attach a patch that supports [EXACT | NOEXACT].
> > > >
> > > > Somehow, proposing two new reserved words instead of one doesn't seem
> > > > very responsive to my gripe :-(.
> > >
> > > My intention was to introduce the idea that the current behavior should
> > > be changed, and to then suggest a path that eventually eliminates all
> > > the new reserved words.
> > >
> > > > If you think that this should be a global option instead of a
> > > > per-statement one, something like the (undocumented) #option hack might
> > > > be a good way to specify it; that would give it per-function scope,
> > > > which seems reasonable.
> > > >
> > > > create function myfn(...) returns ... as $$
> > > > #option select_into_1_row
> > > > declare ...
> > > > $$ language plpgsql;
> > > >
> > >
> > > Thanks, I'll take a look at this.
> > >
> > > ---------------------------(end of broadcast)---------------------------
> > > TIP 2: Don't 'kill -9' the postmaster
> > >
> >
> > --
> > Bruce Momjian http://candle.pha.pa.us
> > EnterpriseDB http://www.enterprisedb.com
> >
> > + If your life is a hard drive, Christ can be your backup. +
> >
> > ---------------------------(end of broadcast)---------------------------
> > TIP 1: if posting/reading through Usenet, please send an appropriate
> > subscribe-nomail command to majordomo(at)postgresql(dot)org so that your
> > message can get through to the mailing list cleanly
> >
>
> --
> Bruce Momjian http://candle.pha.pa.us
> EnterpriseDB http://www.enterprisedb.com
>
> + If your life is a hard drive, Christ can be your backup. +
>
> ---------------------------(end of broadcast)---------------------------
> TIP 2: Don't 'kill -9' the postmaster
>

--
Bruce Momjian http://candle.pha.pa.us
EnterpriseDB http://www.enterprisedb.com

+ If your life is a hard drive, Christ can be your backup. +