Re: DOMAINs and CASTs

Поиск
Список
Период
Сортировка
От Jaime Casanova
Тема Re: DOMAINs and CASTs
Дата
Msg-id BANLkTinCuFwCLPxTO6wd+pdd+nEOKDj9Gg@mail.gmail.com
обсуждение исходный текст
Ответ на Re: DOMAINs and CASTs  (Darren Duncan <darren@darrenduncan.net>)
Ответы Re: DOMAINs and CASTs
Список pgsql-hackers
On Sat, May 14, 2011 at 8:42 PM, Darren Duncan <darren@darrenduncan.net> wrote:
>
> First of all, what if "cast(timestamp as int)" was already defined?  Which
> cast then would you expect to be invoked here?
>
>  '1800-01-01 00:00:00'::int
>

i will expect an error in that case... what you're doing there is
casting an "unknown" to integer, for that to be valid you need an
intermediate cast to timestamp or in my case to datetime

> ... the one for timestamp or the one for datetime?
>

the one of the type i cast before cast to int; for example, "select
'1800-01-01 00:00:00'::timestamp with time zone::int" i expect the
cast of timestamp with time zone to int and in "select '1800-01-01
00:00:00'::datetime::int" the for datetime to int

> Second of all, what if you had 2 domains defined over timestamp and they
> overlapped and they both defined a cast as you did, with generic syntax?
>  And you were casting a value in both domains as an int?
>

i'm not following you, currently i only can define one cast (base type
of the domain to base type of target), but if i can create casts on
domains (and they worked) i can create different behaviours just
creating different functions for every domain and an specific cast for
that domain

> I think it would be best that the generic cast syntax only be useable for
> casts defined on the base type, and if you want a domain-specific one you
> should use the function syntax such as your datetime2int().
>
> That way it is easier for users to predict what behavior will occur, and
> implementation will be easier too.
>

really? how getting an error when i already have a cast on the domain
is predictable?

--
Jaime Casanova         www.2ndQuadrant.com
Professional PostgreSQL: Soporte y capacitación de PostgreSQL


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

Предыдущее
От: "Gelman"
Дата:
Сообщение: Fw: DOMAINs and CASTs
Следующее
От: Darren Duncan
Дата:
Сообщение: Re: DOMAINs and CASTs