Re: [HACKERS] Why type coercion is not performed for parameters?

Поиск
Список
Период
Сортировка
От Marko Tiikkaja
Тема Re: [HACKERS] Why type coercion is not performed for parameters?
Дата
Msg-id CAL9smLAKJ+KP-JGhxLu9kbiiXgd2A7Yr1m4S5ak8m0JTwyd0Mw@mail.gmail.com
обсуждение исходный текст
Ответ на [HACKERS] Why type coercion is not performed for parameters?  (Konstantin Knizhnik <k.knizhnik@postgrespro.ru>)
Ответы Re: [HACKERS] Why type coercion is not performed for parameters?  (Konstantin Knizhnik <k.knizhnik@postgrespro.ru>)
Список pgsql-hackers
On Fri, May 5, 2017 at 10:58 AM, Konstantin Knizhnik <k.knizhnik@postgrespro.ru> wrote:
If I evaluate expression typename('literal'), then type coercion is performed and the function is successfully resolved, i.e.

    SELECT regnamespace('"pg_catalog"');

But if I want to prepare this query, I get the error:

    postgres=#  prepare foo as SELECT regnamespace($1);
    ERROR:  function regnamespace(unknown) does not exist
    LINE 1: prepare foo as SELECT regnamespace($1);

Certainly, I can explicitly specify parameter type:

    prepare foo (text) as SELECT regnamespace($1);

and it will work. But it is not always possible.

There are other similar examples which have even bigger issues, such as   now() - interval '6 hours'.  now() - interval $1  won't even parse.
 
Why do I need it? I want to implement autoprepare.
My original intention was to let parse_analyze_varparams to infer type of parameters from the context.
But it is not always possible  and sometime leads to different behavior of query.
For example if the query:

     select count(*) from test_range_gist where ir @> 10;

is replaced with

     select count(*) from test_range_gist where ir @> $1;

then type of parameter will be int4range rather then int, which corresponds to the different operator.

But you know that the type of the literal "10" is int.  If you're throwing that information away, surely that's a bug in your code.


.m

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

Предыдущее
От: Magnus Hagander
Дата:
Сообщение: Re: [HACKERS] [patch] Build pgoutput with MSVC
Следующее
От: Konstantin Knizhnik
Дата:
Сообщение: Re: [HACKERS] Why type coercion is not performed for parameters?