testing nested case-when scoping

Lists: pgsql-hackers
From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Cc: Heikki Linnakangas <heikki(dot)linnakangas(at)enterprisedb(dot)com>
Subject: testing nested case-when scoping
Date: 2011-06-15 11:43:35
Message-ID: BANLkTikJt3wab9XSisT-NUBh1jeC3q=yiQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Hello Heikki,

probably I found a bug in patch:

CREATE FUNCTION fx(i integer) RETURNS integer
LANGUAGE plpgsql
AS $$begin raise notice '>>%<<', i; return i; end;$$;

CREATE FUNCTION fx1(integer) RETURNS text
LANGUAGE sql
AS $_$ select case $1 when 1 then 'A' else 'B' end$_$;

CREATE FUNCTION fx2(text) RETURNS text
LANGUAGE sql
AS $_$ select case $1 when 'A' then 'a' else 'b' end$_$;

CREATE TABLE foo (
a integer
);

COPY foo (a) FROM stdin;
1
0
\.

postgres=# select fx2(fx1(fx(a))) from foo;
NOTICE: >>1<<
ERROR: invalid expression parameter reference (1 levels up, while
stack is only 1 elements deep)

Regards

Pavel


From: Robert Haas <robertmhaas(at)gmail(dot)com>
To: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
Cc: PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>, Heikki Linnakangas <heikki(dot)linnakangas(at)enterprisedb(dot)com>
Subject: Re: testing nested case-when scoping
Date: 2011-07-05 14:21:29
Message-ID: CA+TgmoaQya-Dyc66HO+RJZ+6HSs=ADtGmiZ++74WmUyjuTYU1w@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Wed, Jun 15, 2011 at 7:43 AM, Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com> wrote:
> Hello Heikki,
>
> probably I found a bug in patch:
>
> CREATE FUNCTION fx(i integer) RETURNS integer
>    LANGUAGE plpgsql
>    AS $$begin raise notice '>>%<<', i; return i; end;$$;
>
> CREATE FUNCTION fx1(integer) RETURNS text
>    LANGUAGE sql
>    AS $_$ select case $1 when 1 then 'A' else 'B' end$_$;
>
> CREATE FUNCTION fx2(text) RETURNS text
>    LANGUAGE sql
>    AS $_$ select case $1 when 'A' then 'a' else 'b' end$_$;
>
> CREATE TABLE foo (
>    a integer
> );
>
> COPY foo (a) FROM stdin;
> 1
> 0
> \.
>
> postgres=# select fx2(fx1(fx(a))) from foo;
> NOTICE:  >>1<<
> ERROR:  invalid expression parameter reference (1 levels up, while
> stack is only 1 elements deep)

I can't reproduce this. Perhaps it was fixed by one of the later commits?

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


From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Robert Haas <robertmhaas(at)gmail(dot)com>
Cc: PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>, Heikki Linnakangas <heikki(dot)linnakangas(at)enterprisedb(dot)com>
Subject: Re: testing nested case-when scoping
Date: 2011-07-05 15:57:16
Message-ID: CAFj8pRDzDm1Z-mYgd7wyetyQnJZBeBcnVviL76zqPiW5eVr0Mw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

2011/7/5 Robert Haas <robertmhaas(at)gmail(dot)com>:
> On Wed, Jun 15, 2011 at 7:43 AM, Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com> wrote:
>> Hello Heikki,
>>
>> probably I found a bug in patch:
>>
>> CREATE FUNCTION fx(i integer) RETURNS integer
>>    LANGUAGE plpgsql
>>    AS $$begin raise notice '>>%<<', i; return i; end;$$;
>>
>> CREATE FUNCTION fx1(integer) RETURNS text
>>    LANGUAGE sql
>>    AS $_$ select case $1 when 1 then 'A' else 'B' end$_$;
>>
>> CREATE FUNCTION fx2(text) RETURNS text
>>    LANGUAGE sql
>>    AS $_$ select case $1 when 'A' then 'a' else 'b' end$_$;
>>
>> CREATE TABLE foo (
>>    a integer
>> );
>>
>> COPY foo (a) FROM stdin;
>> 1
>> 0
>> \.
>>
>> postgres=# select fx2(fx1(fx(a))) from foo;
>> NOTICE:  >>1<<
>> ERROR:  invalid expression parameter reference (1 levels up, while
>> stack is only 1 elements deep)
>
> I can't reproduce this.  Perhaps it was fixed by one of the later commits?
>

I don't checked it again, because Tom rejected Heikki's design.

Regards

Pavel

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