Re: BUG #2917: spi_prepare doesn't accept typename aliases

Lists: pgsql-hackers
From: Andrew Dunstan <andrew(at)dunslane(dot)net>
To: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: BUG #2917: spi_prepare doesn't accept typename aliases such as 'integer'
Date: 2007-01-25 19:23:36
Message-ID: 45B903B8.5090300@dunslane.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers


The author of this bug was good enough to send me a copy, since I don't
normally read the -bugs list. It can now be found at
http://archives.postgresql.org/pgsql-bugs/2007-01/msg00111.php .

I dug into it a bit and found that pltcl and plpython appear to use
almost identical code, but only pltcl has this limitation documented.
I'm inclined to say we should document this for plperl and plpython for
stable releases and remove the limitation for all three for 8.3. I see
that SQL level prepare calls regprocin() to resolve type names, so maybe
we should that for the PLs when calling SPI_prepare as well.
Alternatively, should we adjust things lower down (e.g. in
typenameType() or LookupTypeName() ) ?

Comments?

cheers

andrew


From: Andrew Dunstan <andrew(at)dunslane(dot)net>
To: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: BUG #2917: spi_prepare doesn't accept typename aliases
Date: 2007-01-25 20:36:49
Message-ID: 45B914E1.2050704@dunslane.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

I wrote:
>
> I see that SQL level prepare calls regprocin() to resolve type names,
> so maybe we should that for the PLs when calling SPI_prepare as well.

Of course, that should be regtypein()

cheers

andrew


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Andrew Dunstan <andrew(at)dunslane(dot)net>
Cc: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: BUG #2917: spi_prepare doesn't accept typename aliases
Date: 2007-01-25 21:14:19
Message-ID: 5723.1169759659@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Andrew Dunstan <andrew(at)dunslane(dot)net> writes:
>> I see that SQL level prepare calls regprocin() to resolve type names,
>> so maybe we should that for the PLs when calling SPI_prepare as well.
> Of course, that should be regtypein()

[ squint... ] build_regtype_array seems a rather stupid bit of code.
How many hundreds of cycles is it expending to convert an OID to an OID?

regards, tom lane


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Andrew Dunstan <andrew(at)dunslane(dot)net>
Cc: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: BUG #2917: spi_prepare doesn't accept typename aliases such as 'integer'
Date: 2007-01-25 21:24:54
Message-ID: 6536.1169760294@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Andrew Dunstan <andrew(at)dunslane(dot)net> writes:
> I dug into it a bit and found that pltcl and plpython appear to use
> almost identical code, but only pltcl has this limitation documented.
> I'm inclined to say we should document this for plperl and plpython for
> stable releases and remove the limitation for all three for 8.3. I see
> that SQL level prepare calls regprocin() to resolve type names, so maybe
> we should that for the PLs when calling SPI_prepare as well.

I think parseTypeString() may be the thing to use. It's what plpgsql
uses...

regards, tom lane


From: Andrew Dunstan <andrew(at)dunslane(dot)net>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: BUG #2917: spi_prepare doesn't accept typename aliases
Date: 2007-01-25 21:33:27
Message-ID: 45B92227.9060704@dunslane.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Tom Lane wrote:
> Andrew Dunstan <andrew(at)dunslane(dot)net> writes:
>
>>> I see that SQL level prepare calls regprocin() to resolve type names,
>>> so maybe we should that for the PLs when calling SPI_prepare as well.
>>>
>> Of course, that should be regtypein()
>>
>
> [ squint... ] build_regtype_array seems a rather stupid bit of code.
> How many hundreds of cycles is it expending to convert an OID to an OID?
>
>
>

Yeah, you're right. I should have squinted too ;-)

Well, I am open to suggestions on what to do about this. I really think
we should support use of standard type aliases in the PLs.

cheers

andrew


From: Andrew Dunstan <andrew(at)dunslane(dot)net>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: BUG #2917: spi_prepare doesn't accept typename aliases
Date: 2007-01-25 21:37:21
Message-ID: 45B92311.8040000@dunslane.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Tom Lane wrote:
> Andrew Dunstan <andrew(at)dunslane(dot)net> writes:
>
>> I dug into it a bit and found that pltcl and plpython appear to use
>> almost identical code, but only pltcl has this limitation documented.
>> I'm inclined to say we should document this for plperl and plpython for
>> stable releases and remove the limitation for all three for 8.3. I see
>> that SQL level prepare calls regprocin() to resolve type names, so maybe
>> we should that for the PLs when calling SPI_prepare as well.
>>
>
> I think parseTypeString() may be the thing to use. It's what plpgsql
> uses...
>
>

OK, I'll see what I can do.

cheers

andrew.


From: Andrew Dunstan <andrew(at)dunslane(dot)net>
To:
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: BUG #2917: spi_prepare doesn't accept typename aliases
Date: 2007-01-26 15:17:06
Message-ID: 45BA1B72.8010509@dunslane.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

I wrote:
> Tom Lane wrote:
>>
>> I think parseTypeString() may be the thing to use. It's what plpgsql
>> uses...
>>
>>
>
> OK, I'll see what I can do.
>

see attached patch. If this is OK I will apply it and also fix pltcl
and plpython similarly, mutatis mutandis.

cheers

andrew

Attachment Content-Type Size
plperl-prepargs.patch text/x-patch 6.1 KB

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Andrew Dunstan <andrew(at)dunslane(dot)net>
Cc: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: BUG #2917: spi_prepare doesn't accept typename aliases
Date: 2007-01-26 15:31:08
Message-ID: 24128.1169825468@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Andrew Dunstan <andrew(at)dunslane(dot)net> writes:
> see attached patch. If this is OK I will apply it and also fix pltcl
> and plpython similarly, mutatis mutandis.

Looks alright as far as it goes, but I'd suggest making one additional
cleanup while you're in there: get rid of the direct syscache access
altogether, instead using getTypeInputInfo(). The loop body should just
consist of three function calls: parseTypeString, getTypeInputInfo,
perm_fmgr_info.

If you wanted to be a bit more ambitious maybe you could change the fact
that this code is throwing away typmod, which means that declarations
like "varchar(32)" would fail to work as expected. Perhaps it should be
fixed to save the typmods alongside the typioparams and then pass them
to InputFunctionCall instead of passing -1. On the other hand, we don't
currently enforce typmod for any function input or result arguments, so
maybe it's consistent that spi_prepare arguments ignore typmods too.
Thoughts?

regards, tom lane


From: Jim Nasby <decibel(at)decibel(dot)org>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Andrew Dunstan <andrew(at)dunslane(dot)net>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: BUG #2917: spi_prepare doesn't accept typename aliases
Date: 2007-01-26 21:26:40
Message-ID: 8C527078-0F5A-4EF9-8411-280B2E2611D7@decibel.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Jan 26, 2007, at 9:31 AM, Tom Lane wrote:
> If you wanted to be a bit more ambitious maybe you could change the
> fact
> that this code is throwing away typmod, which means that declarations
> like "varchar(32)" would fail to work as expected. Perhaps it
> should be
> fixed to save the typmods alongside the typioparams and then pass them
> to InputFunctionCall instead of passing -1. On the other hand, we
> don't
> currently enforce typmod for any function input or result
> arguments, so
> maybe it's consistent that spi_prepare arguments ignore typmods too.
> Thoughts?

I'd like to see us move towards supporting that; both for function
parameters/results as well as inside functions. It'd be nice if both
cases got fixed at once, but IMHO fixing only one now would be better
than fixing none.
--
Jim Nasby jim(at)nasby(dot)net
EnterpriseDB http://enterprisedb.com 512.569.9461 (cell)


From: Andrew Dunstan <andrew(at)dunslane(dot)net>
To: Jim Nasby <decibel(at)decibel(dot)org>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: BUG #2917: spi_prepare doesn't accept typename aliases
Date: 2007-01-26 23:11:45
Message-ID: 45BA8AB1.6040005@dunslane.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Jim Nasby wrote:
> On Jan 26, 2007, at 9:31 AM, Tom Lane wrote:
>> If you wanted to be a bit more ambitious maybe you could change the fact
>> that this code is throwing away typmod, which means that declarations
>> like "varchar(32)" would fail to work as expected. Perhaps it should be
>> fixed to save the typmods alongside the typioparams and then pass them
>> to InputFunctionCall instead of passing -1. On the other hand, we don't
>> currently enforce typmod for any function input or result arguments, so
>> maybe it's consistent that spi_prepare arguments ignore typmods too.
>> Thoughts?
>
> I'd like to see us move towards supporting that; both for function
> parameters/results as well as inside functions. It'd be nice if both
> cases got fixed at once, but IMHO fixing only one now would be better
> than fixing none.
>

I'm not going to do either in fixing this bug - I think they should be
fixed but are a separate issue. These probably belong on the TODO list.

cheers

andrew


From: Bruce Momjian <bruce(at)momjian(dot)us>
To: Andrew Dunstan <andrew(at)dunslane(dot)net>
Cc: Jim Nasby <decibel(at)decibel(dot)org>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: BUG #2917: spi_prepare doesn't accept typename
Date: 2007-01-27 02:33:38
Message-ID: 200701270233.l0R2XcJ27247@momjian.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers


OK, what is the TODO wording?

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

Andrew Dunstan wrote:
> Jim Nasby wrote:
> > On Jan 26, 2007, at 9:31 AM, Tom Lane wrote:
> >> If you wanted to be a bit more ambitious maybe you could change the fact
> >> that this code is throwing away typmod, which means that declarations
> >> like "varchar(32)" would fail to work as expected. Perhaps it should be
> >> fixed to save the typmods alongside the typioparams and then pass them
> >> to InputFunctionCall instead of passing -1. On the other hand, we don't
> >> currently enforce typmod for any function input or result arguments, so
> >> maybe it's consistent that spi_prepare arguments ignore typmods too.
> >> Thoughts?
> >
> > I'd like to see us move towards supporting that; both for function
> > parameters/results as well as inside functions. It'd be nice if both
> > cases got fixed at once, but IMHO fixing only one now would be better
> > than fixing none.
> >
>
> I'm not going to do either in fixing this bug - I think they should be
> fixed but are a separate issue. These probably belong on the TODO list.
>
> cheers
>
> andrew
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 3: Have you checked our extensive FAQ?
>
> http://www.postgresql.org/docs/faq

--
Bruce Momjian bruce(at)momjian(dot)us
EnterpriseDB http://www.enterprisedb.com

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


From: Andrew Dunstan <andrew(at)dunslane(dot)net>
To: Bruce Momjian <bruce(at)momjian(dot)us>
Cc: Jim Nasby <decibel(at)decibel(dot)org>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: BUG #2917: spi_prepare doesn't accept typename aliases
Date: 2007-01-27 02:48:22
Message-ID: 45BABD76.7020200@dunslane.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Bruce Momjian wrote:
> OK, what is the TODO wording?cheers
>

Something like:

Enforce typmod for function inputs, function results and parameters for
spi_prepare'd statements called from PLs.

cheers

andrew


From: Bruce Momjian <bruce(at)momjian(dot)us>
To: Andrew Dunstan <andrew(at)dunslane(dot)net>
Cc: Jim Nasby <decibel(at)decibel(dot)org>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: BUG #2917: spi_prepare doesn't accept typename
Date: 2007-01-27 03:26:00
Message-ID: 200701270326.l0R3Q0122089@momjian.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Andrew Dunstan wrote:
> Bruce Momjian wrote:
> > OK, what is the TODO wording?cheers
> >
>
>
> Something like:
>
> Enforce typmod for function inputs, function results and parameters for
> spi_prepare'd statements called from PLs.

Added.

--
Bruce Momjian bruce(at)momjian(dot)us
EnterpriseDB http://www.enterprisedb.com

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


From: Jim Nasby <decibel(at)decibel(dot)org>
To: Andrew Dunstan <andrew(at)dunslane(dot)net>
Cc: Bruce Momjian <bruce(at)momjian(dot)us>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: BUG #2917: spi_prepare doesn't accept typename aliases
Date: 2007-01-30 02:09:13
Message-ID: C13ADE0E-0C8B-444C-A288-6A4E2E818DB7@decibel.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

What about plpgsql variables, ie:

DECLARE
v varchar(42);
BEGIN
...

On Jan 26, 2007, at 9:48 PM, Andrew Dunstan wrote:

> Bruce Momjian wrote:
>> OK, what is the TODO wording?cheers
>>
>
>
> Something like:
>
> Enforce typmod for function inputs, function results and parameters
> for spi_prepare'd statements called from PLs.
>
>
> cheers
>
> andrew
>

--
Jim Nasby jim(at)nasby(dot)net
EnterpriseDB http://enterprisedb.com 512.569.9461 (cell)