Thread: Problem with Create Domain example
The example given in create domain seems to be broken. ISTM it requires some extra escaping to be usable (at least in my goings on today it sure was, and I the entries in pg_constraint sure seem to indicate this as well). I suggest that the examples should be updated as per the following patch. Oh.. and Andrew @ Supernews had nothing to do with this ;-) -- Robert Treat Build A Brighter Lamp :: Linux Apache {middleware} PostgreSQL
Attachment
On Sat, Apr 30, 2005 at 06:12:27PM -0400, Robert Treat wrote: > --- 167,174 ---- > <programlisting> > CREATE DOMAIN us_postal_code AS TEXT > CHECK( > ! VALUE ~ '^\\d{5}$' > ! OR VALUE ~ '^\\d{5}-\\d{4}$' > ); Huh, why not VALUE ~ '^\\d{5}(-\\d{4})?$' ? -- Alvaro Herrera (<alvherre[@]dcc.uchile.cl>) "Cuando no hay humildad las personas se degradan" (A. Christie)
On Saturday 30 April 2005 21:14, Alvaro Herrera wrote: > On Sat, Apr 30, 2005 at 06:12:27PM -0400, Robert Treat wrote: > > --- 167,174 ---- > > <programlisting> > > CREATE DOMAIN us_postal_code AS TEXT > > CHECK( > > ! VALUE ~ '^\\d{5}$' > > ! OR VALUE ~ '^\\d{5}-\\d{4}$' > > ); > > Huh, why not > > VALUE ~ '^\\d{5}(-\\d{4})?$' > > ? Not sure what your driving at here... my point is that the \ escaping is incorrect in the current examples. If you want to argue that we could make the check constraint simpler (or is that more advanced) that seems like another issue. IMHO having the OR'd checks is better because it shows that you can "stack" constraints inside a domain if you want. -- Robert Treat Build A Brighter Lamp :: Linux Apache {middleware} PostgreSQL
On Sat, Apr 30, 2005 at 10:08:32PM -0400, Robert Treat wrote: > On Saturday 30 April 2005 21:14, Alvaro Herrera wrote: > > On Sat, Apr 30, 2005 at 06:12:27PM -0400, Robert Treat wrote: > > > --- 167,174 ---- > > > <programlisting> > > > CREATE DOMAIN us_postal_code AS TEXT > > > CHECK( > > > ! VALUE ~ '^\\d{5}$' > > > ! OR VALUE ~ '^\\d{5}-\\d{4}$' > > > ); > > > > Huh, why not > > > > VALUE ~ '^\\d{5}(-\\d{4})?$' > > > > ? > > Not sure what your driving at here... my point is that the \ > escaping is incorrect in the current examples. > > If you want to argue that we could make the check constraint simpler > (or is that more advanced) that seems like another issue. IMHO > having the OR'd checks is better because it shows that you can > "stack" constraints inside a domain if you want. That was pretty much my thought. It's extremely easy to turn regexes into unmaintainable garbage, whereas the original code is maintainable :) Cheers, D -- David Fetter david@fetter.org http://fetter.org/ phone: +1 510 893 6100 mobile: +1 415 235 3778 Remember to vote!
On Sat, Apr 30, 2005 at 07:45:29PM -0700, David Fetter wrote: > > Not sure what your driving at here... my point is that the \ > > escaping is incorrect in the current examples. > > That was pretty much my thought. It's extremely easy to turn regexes > into unmaintainable garbage, whereas the original code is maintainable :) Yes, that's true. I'll go back to my lair now. -- Alvaro Herrera (<alvherre[@]dcc.uchile.cl>) Al principio era UNIX, y UNIX habló y dijo: "Hello world\n". No dijo "Hello New Jersey\n", ni "Hello USA\n".
Robert Treat <xzilla@users.sourceforge.net> writes: > The example given in create domain seems to be broken. ISTM it requires some > extra escaping to be usable (at least in my goings on today it sure was, and > I the entries in pg_constraint sure seem to indicate this as well). I > suggest that the examples should be updated as per the following patch. Applied, thanks. regards, tom lane
On Sunday 01 May 2005 11:58, Tom Lane wrote: > Robert Treat <xzilla@users.sourceforge.net> writes: > > The example given in create domain seems to be broken. ISTM it requires > > some extra escaping to be usable (at least in my goings on today it sure > > was, and I the entries in pg_constraint sure seem to indicate this as > > well). I suggest that the examples should be updated as per the > > following patch. > > Applied, thanks. > Is there any plans to back patch this into 8.0.x? It kind of bothers me to think anyone trying to give domains a swing on the new database might get stopped in thier tracks because they cant make the documentation example from the website work. If not I'll add a comment to the site, but backpatching seems better. -- Robert Treat Build A Brighter Lamp :: Linux Apache {middleware} PostgreSQL
Robert Treat wrote: > Is there any plans to back patch this into 8.0.x? Yeah, I was wondering about that -- I've backported the patch to REL8_0_STABLE. -Neil