Re: DOMAINs and CASTs

From: Jaime Casanova <jaime(at)2ndquadrant(dot)com>
To: Darren Duncan <darren(at)darrenduncan(dot)net>
Cc: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: DOMAINs and CASTs
Date: 2011-05-15 06:43:05
Message-ID: BANLkTinCuFwCLPxTO6wd+pdd+nEOKDj9Gg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Sat, May 14, 2011 at 8:42 PM, Darren Duncan <darren(at)darrenduncan(dot)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

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Darren Duncan 2011-05-15 07:13:16 Re: DOMAINs and CASTs
Previous Message Gelman 2011-05-15 01:56:26 Fw: DOMAINs and CASTs