How can this be legal syntax

Поиск
Список
Период
Сортировка
Искать

How can this be legal syntax

От:
"Asko Oja" <ascoja@gmail.com>
Дата:
I was quite amazed to find that this piece of code actually works while reviewing code.
I would prefer if it gave an error :)

test=# create or replace function test(i_input text) returns text as
$$
declare                                         
    result text;
begin          
    SELECT
        CASE
        WHEN lower(i_input) ~ '^[a-z]' THEN 'S'
        WHEN i_input ~ '[0-9]' THEN 'N'
        ELSE 'ERROR'
        INTO result
        END;
    return result;
end;             
$$
language plpgsql security definer;
CREATE FUNCTION
test=# select * from test('aaaa' );
 test
------
 S
(1 row)

test=# create or replace function test(i_input text) returns text as $$
declare
    result text;
begin
    SELECT
        CASE
        WHEN lower(i_input) ~ '^[a-z]' INTO result THEN 'S'
        WHEN i_input ~ '[0-9]' THEN 'N'
        ELSE 'ERROR'
        END;
    return result;
end;
$$ language plpgsql security definer;
CREATE FUNCTION
test=# select * from test('aaaa' );
 test
------
 S
(1 row)

Re: How can this be legal syntax

От:
Alvaro Herrera <alvherre@commandprompt.com>
Дата:
Asko Oja escribió:
> I was quite amazed to find that this piece of code actually works while
> reviewing code.
> I would prefer if it gave an error :)

Yeah, me too.  The functions posted by Josh Drake yesterday about
constraint exclusion had something like

select * from into temp table ...;
(temp is a declared variable name).

Nasty.

-- 
Alvaro Herrera                                http://www.CommandPrompt.com/
PostgreSQL Replication, Consulting, Custom Development, 24x7 support

Re: How can this be legal syntax

От:
Tom Lane <tgl@sss.pgh.pa.us>
Дата:
Alvaro Herrera  writes:
> Asko Oja escribi�:
>> I was quite amazed to find that this piece of code actually works while
>> reviewing code.
>> I would prefer if it gave an error :)

> Yeah, me too.

As the plpgsql docs say, "The INTO clause can appear almost anywhere in
the SQL command".  You can write some pretty ugly code if you choose to
:-(.  Although the docs also threaten to tighten this up, it's been like
that for so long that I'm worried about how much user code we'll break
if we do.
		regards, tom lane

Re: How can this be legal syntax

От:
"Jaime Casanova" <jcasanov@systemguards.com.ec>
Дата:
On Tue, Dec 16, 2008 at 12:16 PM, Tom Lane  wrote:
> it's been like
> that for so long that I'm worried about how much user code we'll break
> if we do.
>

code making something like that is actually broken, what a "fix" here
will do is making that obvious...

-- 
Atentamente,
Jaime Casanova
Soporte y capacitación de PostgreSQL
Asesoría y desarrollo de sistemas
Guayaquil - Ecuador
Cel. +59387171157

FAQ