Re: Variable-length Types

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: josh(at)agliodbs(dot)com
Cc: sqllist <pgsql-sql(at)postgresql(dot)org>
Subject: Re: Variable-length Types
Date: 2000-10-15 20:26:24
Message-ID: 5470.971641584@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Josh Berkus <josh(at)agliodbs(dot)com> writes:
> I'm a bit confused on custom type declarations, actually. I'd like to
> create a custom type for American phone numbers, such that:
> ...

> 1. Can I reference a custom function (phoneformat) in a type definition?

Of course. The input and output converters for the new type would be
the natural place to do the reformatting. You'd probably make the input
converter do error checking, insertion of default area code, and
reduction to a pure digit string, and then make the output converter
insert the fluff data like parentheses and dashes.

However, building a new type for this seems like overkill, because you'd
also have to supply a set of functions and operators for the type. It
would be a lot less work just to provide a normalization function
interpret_phone_no(text) returns text
which could be invoked explicitly, eg
insert into tab values (..., interpret_phone_no('5551212'), ...)
or implicitly in ON INSERT and ON UPDATE triggers for the table.

> 3. What sort of trouble am I going to get into trying to pull data from
> a custom type into an external interface (i.e. PHP4)?

Good question --- the interface code might or might not have a sensible
default behavior for types it doesn't recognize.

regards, tom lane

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Josh Berkus 2000-10-15 20:36:31 Re: Variable-length Types
Previous Message Bruce Momjian 2000-10-15 18:50:46 Re: Regular expression query