Re: What happened to the is_<type> family of functions proposal?

From: Darren Duncan <darren(at)darrenduncan(dot)net>
To: pgsql-hackers(at)postgresql(dot)org
Subject: Re: What happened to the is_<type> family of functions proposal?
Date: 2010-09-25 08:05:00
Message-ID: 4C9DAD2C.7070404@darrenduncan.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Craig Ringer wrote:
> On 25/09/2010 11:51 AM, Darren Duncan wrote:
>> There should just be a single syntax that works for all types, in the
>> general case, for testing whether a value is a member of that type, or
>> alternately whether a value can be cast to a particular type.
<snip>
>> Pg already gets it right in this regard by having a single general
>> syntax for type casting, the "<value>::<type-name>" and value membership
>> of a type should be likewise.
>
> or the standard:
>
> CAST(value AS typename)

Indeed. The exact syntax doesn't matter to me but the point is that the type
name is its own lexical element, conceptually a function argument, rather than
being a substring of another one.

>> Maybe to test if a value can be cast as a type, you can continue the ::
>> mnemonic, say adding a "?" for yes and a "!" for no.
>>
>> For example, "<value>?::<type-name>" tests if the value can be cast as
>> the type and "<value>!::<type-name>" or "not <value>?::<type-name>"
>> tests the opposite. An expression like this results in a boolean.
>
> Personal opinion here: Blech, if I wanted to use Perl6 I'd do so ;-)

I see that someone has been paying attention.

Yes, the idea of using ? or ! to derive a boolean expression from some other
expression did indeed come from Perl 6. The ? means "is so", ! means "is not".
A very useful mnemonic in general.

> Good shorthand, I guess, but a CAST syntax extension or alternate CAST
> version would be a bonus for readability.

Well, sure. But something consistent with cast syntax that Pg provides.

-- Darren Duncan

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Gurjeet Singh 2010-09-25 08:36:24 Re: What happened to the is_<type> family of functions proposal?
Previous Message Craig Ringer 2010-09-25 07:01:02 Re: What happened to the is_<type> family of functions proposal?