pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: josh@agliodbs.com
Cc: sqllist <pgsql-sql@postgresql.org>
Subject: Re: Variable-length Types
Date: Sun, 15 Oct 2000 16:26:24 -0400
Message-ID: <5470.971641584@sss.pgh.pa.us> (raw)
In-Reply-To: <39E9F80C.D9BE2054@agliodbs.com>
References: <871yxi432t.fsf@matt.w80.math-hat.com>
	<39E9F80C.D9BE2054@agliodbs.com>

Josh Berkus <josh@agliodbs.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



view thread (10+ messages)  latest in thread

Message-ID: <5470.971641584@sss.pgh.pa.us>
Permalink:  ../5470.971641584@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/5470.971641584@sss.pgh.pa.us

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-sql@postgresql.org
  Cc: tgl@sss.pgh.pa.us, josh@agliodbs.com
  Subject: Re: Variable-length Types
  In-Reply-To: <5470.971641584@sss.pgh.pa.us>
  References: <871yxi432t.fsf@matt.w80.math-hat.com> <39E9F80C.D9BE2054@agliodbs.com> <5470.971641584@sss.pgh.pa.us>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox