Re: Oracle porting sample instr function

Lists: pgsql-hackers
From: Greg Smith <greg(at)2ndquadrant(dot)com>
To: pgsql-hackers(at)postgresql(dot)org
Subject: Oracle porting sample instr function
Date: 2012-07-03 00:51:14
Message-ID: 4FF24202.1000008@2ndquadrant.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

A web site doc comment from user skong today points out a small issue
around the sample INSTR function given in plpgsql-porting.html that I
can't confirm (none of those dirty Oracle instances here today), but it
sounds legit.

A look at Oracle's documentation on the INSTR function at
http://docs.oracle.com/cd/B28359_01/olap.111/b28126/dml_functions_1103.htm
says that the 3rd input, position to start searching, cannot be zero.
skong says that Oracle will just return a 0 if you give it that invalid
input.

The INSTR implementation in the docs will instead search backwards from
the end of the string if you tell it to start at 0, same as if you gave
it a negative input. I think it's therefore possible to get the plpgsql
version to return a value in cases Oracle would instead return 0. Seems
like a straightforward thing to confirm and change the sample to do
differently; just have to add an explicit test for a 0 value of beg_index.


From: "Albe Laurenz" <laurenz(dot)albe(at)wien(dot)gv(dot)at>
To: "Greg Smith *EXTERN*" <greg(at)2ndquadrant(dot)com>, <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Oracle porting sample instr function
Date: 2012-07-03 12:42:30
Message-ID: D960CB61B694CF459DCFB4B0128514C2081BE807@exadv11.host.magwien.gv.at
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Greg Smith wrote:
> A web site doc comment from user skong today points out a small issue
> around the sample INSTR function given in plpgsql-porting.html that I
> can't confirm (none of those dirty Oracle instances here today), but
it
> sounds legit.
>
> A look at Oracle's documentation on the INSTR function at
>
http://docs.oracle.com/cd/B28359_01/olap.111/b28126/dml_functions_1103.h
tm
> says that the 3rd input, position to start searching, cannot be zero.
> skong says that Oracle will just return a 0 if you give it that
invalid
> input.
>
> The INSTR implementation in the docs will instead search backwards
from
> the end of the string if you tell it to start at 0, same as if you
gave
> it a negative input. I think it's therefore possible to get the
plpgsql
> version to return a value in cases Oracle would instead return 0.
Seems
> like a straightforward thing to confirm and change the sample to do
> differently; just have to add an explicit test for a 0 value of
beg_index.

I can confirm that Oracle returns 0 if the third argument to
INSTR is 0.

Yours,
Laurenz Albe


From: Robert Haas <robertmhaas(at)gmail(dot)com>
To: Albe Laurenz <laurenz(dot)albe(at)wien(dot)gv(dot)at>
Cc: "Greg Smith *EXTERN*" <greg(at)2ndquadrant(dot)com>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: Oracle porting sample instr function
Date: 2012-07-03 12:47:33
Message-ID: CA+TgmoZJWFaPK4EsomzT8vuOaAoiBjEZFCaPOa9Ktu48pokqSA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Tue, Jul 3, 2012 at 8:42 AM, Albe Laurenz <laurenz(dot)albe(at)wien(dot)gv(dot)at> wrote:
> I can confirm that Oracle returns 0 if the third argument to
> INSTR is 0.

Can someone provide a suitable doc patch?

--
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company


From: "Albe Laurenz" <laurenz(dot)albe(at)wien(dot)gv(dot)at>
To: "Robert Haas *EXTERN*" <robertmhaas(at)gmail(dot)com>
Cc: "Greg Smith *EXTERN*" <greg(at)2ndquadrant(dot)com>, <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Oracle porting sample instr function
Date: 2012-07-04 07:50:29
Message-ID: D960CB61B694CF459DCFB4B0128514C2081BE962@exadv11.host.magwien.gv.at
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Robert Haas wrote:
>> I can confirm that Oracle returns 0 if the third argument to
>> INSTR is 0.

> Can someone provide a suitable doc patch?

Here you are.

Yours,
Laurenz Albe

Attachment Content-Type Size
instr-doc.patch application/octet-stream 1.6 KB

From: Robert Haas <robertmhaas(at)gmail(dot)com>
To: Albe Laurenz <laurenz(dot)albe(at)wien(dot)gv(dot)at>
Cc: "Greg Smith *EXTERN*" <greg(at)2ndquadrant(dot)com>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: Oracle porting sample instr function
Date: 2012-07-04 21:20:47
Message-ID: CA+Tgmob3BOz6kAMu3NSNOe2=4229iBh1XdBMgxE3QDEH9V326g@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Wed, Jul 4, 2012 at 3:50 AM, Albe Laurenz <laurenz(dot)albe(at)wien(dot)gv(dot)at> wrote:
> Robert Haas wrote:
>>> I can confirm that Oracle returns 0 if the third argument to
>>> INSTR is 0.
>
>> Can someone provide a suitable doc patch?

Thanks, committed.

--
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company


From: Roberto Mello <roberto(dot)mello(at)gmail(dot)com>
To: Greg Smith <greg(at)2ndquadrant(dot)com>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: Oracle porting sample instr function
Date: 2012-07-06 11:04:33
Message-ID: CAKz==bJ7oZi33-BJ548tuPTaYhrV+QpJtJQXEGTsHK48VkCtkg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Mon, Jul 2, 2012 at 8:51 PM, Greg Smith <greg(at)2ndquadrant(dot)com> wrote:
>

<snip>

> The INSTR implementation in the docs will instead search backwards from the
> end of the string if you tell it to start at 0, same as if you gave it a
> negative input. I think it's therefore possible to get the plpgsql version
> to return a value in cases Oracle would instead return 0. Seems like a
> straightforward thing to confirm and change the sample to do differently;
> just have to add an explicit test for a 0 value of beg_index.

I wrote that sample eons ago with the plpgsql-porting doc. I probably
overlooked the 0 behavior. Thanks for reporting Greg, and thanks Albe
for providing a patch.

Roberto