Create Domain.... - Mailing list pgsql-hackers

From Rod Taylor
Subject Create Domain....
Date
Msg-id 008e01c1b745$311cec10$8001a8c0@jester
Whole thread Raw
Responses Re: Create Domain....
List pgsql-hackers
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.


pgsql-hackers by date:

Previous
From: Tom Lane
Date:
Subject: Re: Odd statistics behaviour in 7.2
Next
From: Hervé Piedvache
Date:
Subject: Trouble with pg_dumpall import with 7.2