From: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
---|---|
To: | "Justin Dearing" <zippy1981(at)gmail(dot)com> |
Cc: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: Default value of column not respecting character length or domain restraints. |
Date: | 2007-04-01 07:02:26 |
Message-ID: | 6446.1175410946@sss.pgh.pa.us |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
"Justin Dearing" <zippy1981(at)gmail(dot)com> writes:
> It seems I can feed a default value to a domain that won't fit in the
> underlying base type. I have the domain html_colors as so:
> CREATE DOMAIN html_color AS char(7) CHECK (VALUE ~ '^#[A-Fa-f0-9]{6}$');
> I then defined a column of html_colors as so:
> ALTER TABLE users ALTER COLUMN profile_color SET DEFAULT '#FFFFRFF';
> This worked fine and I didn't notice it until I added arecord to the
> users table and got the error:
> ERROR: value too long for type character(7).
> This behavior seems undesirable to me. Is this a known bug or is there
> a reason for this?
Well, the default isn't checked against constraints until it's used
at runtime. This is appropriate in a number of situations because
time-varying defaults are not uncommon (eg "default now()" for a
timestamp column). Also, defaults with side effects are not uncommon
--- think "default nextval('seq')" for a serial --- and causing those
side-effects to happen at CREATE TABLE time seems undesirable.
In short, I understand your annoyance, but the cure seems worse than
the disease. It's not like you won't find out soon enough if you
establish a constant default that doesn't meet your constraints.
regards, tom lane
From | Date | Subject | |
---|---|---|---|
Next Message | Ron Mayer | 2007-04-01 10:44:26 | Re: Arrays instead of join tables |
Previous Message | Jonathan Vanasco | 2007-03-31 22:51:41 | queries stop using indexes |