I've been working away at simple domain support.  The simple stuff
works (no constraints, simple data type).

CREATE DOMAIN domainname Typename;

I have a few questions about how to proceed.

So.. Starting with (more) complex datatypes.  varchar(), numeric(),
and the like.  There is currently no column in pg_type which stores
information similar to atttypmod.  So, I'd like to create one ->
pg_type.typmod.  The idea is that this value will be copied across to
pg_attribute with other type information if it is not null.   Since
pg_type.typeprtlen isn't used (according to docs) would it be safe to
simply rename and resize (int4) this column?

The second part of this is to apply constraints to the domain.  That
will require an equivelent to pg_trigger but linked to pg_type, say
pg_domaintrigger.  On column creation in a table I'm considering
copying the triggers from pg_domaintrigger to pg_trigger for the
column, and adding a column to pg_trigger which marks them as
originating from the domain.  Deletes of a trigger in the domain can
cascade to pg_trigger -- as can updates, etc.  Triggers in pg_trigger
with domtrgid NOT NULL would not be (directly) erasable by the ALTER
TABLE DROP CONSTRAINT stuff.

Given the above, ALTER DOMAIN may be complex.  ALTER DOMAIN ADD
CONSTRAINT may touch several hundred items -- but I wouldn't expect
this to be a frequent action.

Anyway, patch attached (hopefully it works, I've modified my source to
be in a broken state then).  It's against 7.2-HEAD.

With any luck I'm on the right track.  Thus far its making a good
weekend project -- but I suspect constraints are going to take alot
longer than that.

Something of great fun however is DROP TYPE text.   Lots of neat stuff
happens when you do that.  I want to add a RESTRICT & CASCADE
structure to DROP TYPE as well.  Cascade may be disabled though.
--
Rod Taylor

Your eyes are weary from staring at the CRT. You feel sleepy. Notice
how restful it is to watch the cursor blink. Close your eyes. The
opinions stated above are yours. You cannot imagine why you ever felt
otherwise.
Sat, 16 Feb 2002 18:53:53 -0500
"Rod Taylor" <rbt@zort.ca>
Create Domain....
"Rod Taylor" <rbt@zort.ca> writes:
> and the like.  There is currently no column in pg_type which stores
> information similar to atttypmod.  So, I'd like to create one ->
> pg_type.typmod.  The idea is that this value will be copied across to
> pg_attribute with other type information if it is not null.   Since
> pg_type.typeprtlen isn't used (according to docs) would it be safe to
> simply rename and resize (int4) this column?

Make another column.  It'll be good for you ;-) ... and you have to
learn how anyway, if you intend to finish out this project.

> Something of great fun however is DROP TYPE text.

Yeah, there's not really any support presently for dealing with
dependencies on dropped objects.  IMHO it would be a mistake to solve
that just in the context of any one kind of object (such as types);
it's a generic issue.

			regards, tom lane

Sat, 16 Feb 2002 20:32:33 -0500
Tom Lane <tgl@sss.pgh.pa.us>
Re: Create Domain.... 