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

From: Robert Haas <robertmhaas(at)gmail(dot)com>
To: "Colin 't Hart" <colinthart(at)gmail(dot)com>
Cc: Andrew Dunstan <andrew(at)dunslane(dot)net>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: What happened to the is_<type> family of functions proposal?
Date: 2010-09-21 15:03:28
Message-ID: AANLkTikAKE5ERpaZcEPte14Ct8E3Soweb0yRYC4Nmv10@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Mon, Sep 20, 2010 at 11:31 AM, Colin 't Hart <colinthart(at)gmail(dot)com> wrote:
>> I think to_date is the wrong gadget to use here. You should probably be using the date input routine and trapping any data exception. e.g.:
>>
>>    test_date := date_in(textout(some_text));
>>
>> In plpgsql you'd put that inside a begin/exception/end block that traps SQLSTATE '22000' which is the class covering data exceptions.
>
> So it's not possible using pure SQL unless one writes a function?

I think that is true.

> Are the is_<type> family of functions still desired?

I think it would be useful to have a way of testing whether a cast to
a given type will succeed. The biggest problem with the
exception-catching method is not that it requires writing a function
(which, IMHO, is no big deal) but that exception handling is pretty
slow and inefficient. You end up doing things like... write a regexp
to see whether the data is in approximately the right format and then
if it is try the cast inside an exception block. Yuck.

(On the other hand, whether the work that was done in 2002 is still
relevant to today's code is questionable. Things have changed a lot.)

> Also, where are the to_<type> conversions done?

I think maybe you are looking for the type input functions?

select typname, typinput::regprocedure from pg_type;

There are also some functions with names of the form to_<type>. You
can get a list of those with the following psql command:

\dfS to_*

--
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise Postgres Company

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Robert Haas 2010-09-21 15:12:55 Re: .gitignore files, take two
Previous Message Tom Lane 2010-09-21 15:02:30 Re: .gitignore files, take two