Re: PL/pgsSQL EXECUTE USING INTO

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: PL/pgsSQL EXECUTE USING INTO
Дата
Msg-id 16328.1282236769@sss.pgh.pa.us
обсуждение исходный текст
Ответ на PL/pgsSQL EXECUTE USING INTO  (Heikki Linnakangas <heikki.linnakangas@enterprisedb.com>)
Список pgsql-hackers
Heikki Linnakangas <heikki.linnakangas@enterprisedb.com> writes:
> While testing the recent issue with unknown params in EXECUTE USING, I 
> accidentally did this:

>    EXECUTE 'SELECT ''foo'' || $1' USING 'bar' INTO t;

> The mistake I made? I put the USING and INTO clauses in wrong order, 
> INTO needs to go first. We should throw an error on that, but it looks 
> like the INTO clause is just silently ignored.

This is more interesting than it looks.  It appears that the plpgsql
parser interprets the USING's argument expression as being'bar' INTO t
so it generates a plplgsql expression with querySELECT 'bar' INTO t
and the only reason that you don't get a failure is that
exec_simple_check_plan fails to notice the intoClause, so it thinks
this represents a "simple expression", which means it evaluates the
'bar' subexpression and ignores the INTO altogether.  That's
certainly a bug in exec_simple_check_plan :-(

I think that accepting this order of the clauses would require some
duplication of code in the stmt_dynexecute production.  It might be
worth doing anyway, because if you made this mistake then certainly
others will.
        regards, tom lane


В списке pgsql-hackers по дате отправления:

Предыдущее
От: Robert Haas
Дата:
Сообщение: Re: wip: functions median and percentile
Следующее
От: Heikki Linnakangas
Дата:
Сообщение: Re: Re: [COMMITTERS] pgsql: Coerce 'unknown' type parameters to the right type in the