Обсуждение: Re: [COMMITTERS] pgsql: Remove typename from A_Const.

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

Re: [COMMITTERS] pgsql: Remove typename from A_Const.

От
Tom Lane
Дата:
alvherre@postgresql.org (Alvaro Herrera) writes:
> Remove typename from A_Const.

I'm thinking this could be cleaned up further.  The patch as applied
removes the ::int4 typename decoration that had been inserted by
makeIntConst(), while leaving in place the ::float8 decoration inserted
by makeFloatConst().  The kindest thing that can be said about that
is that it's inconsistent.  Now as far as I can see in a look through
gram.y, these routines (and makeAConst) were used only in places where
the typename qualification was really unnecessary, that is typmods
and GUC variable values and so on, not general expression contexts where
we might really need to determine a data type for the constant.  So what
I'm thinking is that we should get rid of the ::float8 decoration too,
and thereby be able to revert some of the ugly code added elsewhere such
as guc.c.

Is there a reason it was done this way that I'm missing?
        regards, tom lane


Re: [COMMITTERS] pgsql: Remove typename from A_Const.

От
Alvaro Herrera
Дата:
Tom Lane escribió:
> alvherre@postgresql.org (Alvaro Herrera) writes:
> > Remove typename from A_Const.
> 
> I'm thinking this could be cleaned up further.  The patch as applied
> removes the ::int4 typename decoration that had been inserted by
> makeIntConst(), while leaving in place the ::float8 decoration inserted
> by makeFloatConst().  The kindest thing that can be said about that
> is that it's inconsistent.

That's very kind, yes :-)  I think that cast can be removed safely.

> Now as far as I can see in a look through
> gram.y, these routines (and makeAConst) were used only in places where
> the typename qualification was really unnecessary, that is typmods
> and GUC variable values and so on, not general expression contexts where
> we might really need to determine a data type for the constant.  So what
> I'm thinking is that we should get rid of the ::float8 decoration too,
> and thereby be able to revert some of the ugly code added elsewhere such
> as guc.c.

Hmm, I'm not sure but I think the typecast is needed in the guc.c code
in order to pass the fact that the Const is an Interval.  This is used
to process things such as 

set time zone interval '-8:30' ;

Perhaps this can be detected by some other mechanism but currently it's
being driven by the cast.

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


Re: [COMMITTERS] pgsql: Remove typename from A_Const.

От
Tom Lane
Дата:
Alvaro Herrera <alvherre@commandprompt.com> writes:
> Tom Lane escribi�:
>> I'm thinking is that we should get rid of the ::float8 decoration too,
>> and thereby be able to revert some of the ugly code added elsewhere such
>> as guc.c.

> Hmm, I'm not sure but I think the typecast is needed in the guc.c code
> in order to pass the fact that the Const is an Interval.

Yeah, I had just found that out --- it's not so much that we care that
it's an interval, as that the original input might have had typmod
restrictions that need to be applied to the interval value.  Definitely
a kluge to support a corner case ...

Anyway, I'm in the middle of testing removal of the ::float8 cast
--- we can at least simplify parse_type.c's handling of typmods here.
I also see that we can eliminate some manual construction of A_Const's
in gram.y, since makeFloatConst and friends no longer do any unwanted
extra stuff.
        regards, tom lane