Re: Custom type literal conversion

From: Chris Bandy <bandy(dot)chris(at)gmail(dot)com>
To: hubert depesz lubaczewski <depesz(at)gmail(dot)com>
Cc: pgsql-general <pgsql-general(at)postgresql(dot)org>
Subject: Re: Custom type literal conversion
Date: 2014-09-24 19:02:00
Message-ID: CAMDg7Wz6ghkU7rt7HxkqJr6t6Ls_qtoTBSuxK5srfagpHc_YVQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Wed, Sep 24, 2014 at 8:40 AM, hubert depesz lubaczewski <depesz(at)gmail(dot)com
> wrote:

> On Wed, Sep 24, 2014 at 2:45 PM, Chris Bandy <bandy(dot)chris(at)gmail(dot)com>
> wrote:
>
>> I would like to create a new type for version strings that sorts
>> numerically. The composite type below was quick to write and does not
>> require superuser privileges. However, it doesn't respond to type casts the
>> way I'd like.
>>
>> Is there a way to implement this type's literal conversion without
>> resorting to a base type?
>>
>
> I think you need to define casts too, but in any way - check if "semver"
> extension (available on pgxn) doesn't solve your problem.
>
>
Casts from what? The following is not sufficient:

=> CREATE CAST (unknown AS myversion) WITH FUNCTION myversion(unknown);
CREATE CAST
=> SELECT '1.0.9+jenkins'::myversion;
ERROR: malformed record literal: "1.0.9+jenkins"

And cast on "record" isn't valid:

=> CREATE CAST (record AS myversion) WITH FUNCTION myversion(unknown);
ERROR: source data type record is a pseudo-type

I know about the semver extension, but I'm interested in a solution that
does not require extension/superuser access.

Thanks
-- Chris

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Oleg Bartunov 2014-09-24 19:07:55 Re: JSONB spaces in text presentation
Previous Message Tom Lane 2014-09-24 18:19:10 Re: Why can't I select un-grouped columns when grouping by a (non-primary) unique key?