Re: CAST function for user defined type

Поиск
Список
Период
Сортировка
От Ron Peterson
Тема Re: CAST function for user defined type
Дата
Msg-id 20070122162122.GA19861@yellowbank.com
обсуждение исходный текст
Ответ на Re: CAST function for user defined type  (Martijn van Oosterhout <kleptog@svana.org>)
Ответы Re: CAST function for user defined type  (Tom Lane <tgl@sss.pgh.pa.us>)
Список pgsql-general
On Mon, Jan 22, 2007 at 04:36:20PM +0100, Martijn van Oosterhout wrote:
> On Mon, Jan 22, 2007 at 09:44:52AM -0500, Ron Peterson wrote:
> > I've created my own type: y_octet_16.  Now I'm trying to create a CAST
> > function for this type, but I'm not quite getting it.
>
> Quick question: do you mean:
>
> >   val
> >     y_octet_16
>       ^^^^^^^^^^
> > VALUES
> >   ( 'aaa', encode( y_uuid_generate(), 'hex' )::y_byte_16 );
> or                                               ^^^^^^^^^
>
> I'm not sure from your example of the difference? byte vs octet.

Phghtht, I got tripped up by my own pedantry.  I'm using the specific
term 'octet' to refer to eight bits, rather than the colloquial 'byte',
but instinctively typed 'byte' in my cast.  So that's just a typo.

That cleared one hurdle, but I'm still not there yet.

% select encode( y_uuid_generate(), 'hex' );
              encode
----------------------------------
 fe43d07c0c624786bebfcb3357a2a13a
(1 row)

% select 'fe43d07c0c624786bebfcb3357a2a13a'::y_octet_16;
            y_octet_16
----------------------------------
 fe43d07c0c624786bebfcb3357a2a13a

That works, but if I cast the output of 'encode' directly as below, my
cast function doesn't work.  The error message indicates that it's not
seeing a hex string as input.  When things are connected up this way,
what should the cast function expect to see as input?

% select encode( y_uuid_generate(), 'hex' )::y_octet_16;
ERROR:  input string contains invalid characters

Best.

--
Ron Peterson
https://www.yellowbank.com/

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

Предыдущее
От: Tom Lane
Дата:
Сообщение: Re: Is there an equivalent of the W3c HTML checker for SQL?
Следующее
От: Tom Lane
Дата:
Сообщение: Re: Enable/Disable Triggers