Search Postgresql Archives

Re: CAST function for user defined type

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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/


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux