I think we need an explicit parsetree node for CAST

Поиск
Список
Период
Сортировка
От Tom Lane
Тема I think we need an explicit parsetree node for CAST
Дата
Msg-id 17389.947988230@sss.pgh.pa.us
обсуждение исходный текст
Ответы Re: [HACKERS] I think we need an explicit parsetree node for CAST  (Bruce Momjian <pgman@candle.pha.pa.us>)
Re: [HACKERS] I think we need an explicit parsetree node for CAST  (Bruce Momjian <pgman@candle.pha.pa.us>)
Re: [HACKERS] I think we need an explicit parsetree node for CAST  (Bruce Momjian <pgman@candle.pha.pa.us>)
Re: [HACKERS] I think we need an explicit parsetree node for CAST  (Don Baccus <dhogaza@pacifier.com>)
Список pgsql-hackers
I noticed today that the system drops any "typmod" modifier associated
with a type name being casted to.  For example,

regression=# select '1.23456'::numeric(7,2);?column?
---------- 1.23456            --- should be 1.23
(1 row)

regression=# select CAST ('1234567.89' AS numeric(4,1)); ?column?
------------1234567.89            --- should raise a numeric-overflow error
(1 row)

These particular cases can be fixed with a one-line patch, I think,
because there is storage in an A_Const node to hold a reference to
a Typename, which includes typmod.  parse_expr.c is just forgetting
to pass the typmod to parser_typecast().

BUT: there isn't any equally simple patch when the value being casted
is not a constant.  For instance
select field1 :: numeric(7,2) from table1;

cannot work properly now, because gram.y transforms it into
select numeric(field1) from table;

which (a) drops the typmod and (b) bypasses all of the intelligence
that should be used to determine how to coerce the type.

What I think we need is to add a new parsetree node type that explicitly
represents a CAST operator, and then modify parse_expr.c to transform
that node type into an appropriate function call (or, perhaps, nothing
at all if the source value is already the right type).

Comments?
        regards, tom lane


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

Предыдущее
От: Tom Lane
Дата:
Сообщение: Re: [HACKERS] flex
Следующее
От: Bruce Momjian
Дата:
Сообщение: Re: [HACKERS] TODO list