Re: Can I create a TYPE (or DOMAIN) with arguments?

From: Erik Jones <erik(at)myemma(dot)com>
To: "R(dot)A(dot)" <adeveloper(at)bluebottle(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Can I create a TYPE (or DOMAIN) with arguments?
Date: 2008-01-10 14:58:07
Message-ID: AD51AA17-B989-434F-BF0A-1337CC1ED356@myemma.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Jan 9, 2008, at 3:53 AM, R.A. wrote:

> Hello,
>
> I'm trying to create a composite type with an argument, to create
> one field of this type like character varying(x), but I don't know
> if this can be done with PostgreSQL. I want something like:
> CREATE TYPE mytype AS (
> tx character varying(x),
> t2nd integer
> );
> I need to limit the number of chars in this field tx. And different
> lengths will be used when creating tables with this type (so a
> Domain will suffer the same problem). I'm not looking for a
> solution like a separate column with maxChars and a Check, because
> lots of columns will be required (and others design reasons).

Postgres doesn't support parameterized type declarations directly
(that I've ever heard of), but you could probably write a function
that uses EXECUTE to do this.

Erik Jones

DBA | Emma®
erik(at)myemma(dot)com
800.595.4401 or 615.292.5888
615.292.0777 (fax)

Emma helps organizations everywhere communicate & market in style.
Visit us online at http://www.myemma.com

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Stefan Schwarzer 2008-01-10 15:02:33 Re: Installation problem: failed to initialize lc_messages to ""
Previous Message Alvaro Herrera 2008-01-10 14:54:29 Re: 8.3 Beta Incompatible Data Disaster