Re: [HACKERS] DDL triggers [was Re: [GENERAL] database constraints]

2004-10-07 Thread Gavin Sherry
On Thu, 7 Oct 2004, David Fetter wrote: > On Thu, Oct 07, 2004 at 11:47:55AM +0700, David Garamond wrote: > > Joshua D. Drake wrote: > > >>This brings up an interesting idea. What if it were possible to set > > >>some kind of rules on DDL at database creation time? For example, I'd > > >>like to

Re: DDL triggers [was Re: [GENERAL] database constraints]

2004-10-07 Thread Tom Lane
David Fetter <[EMAIL PROTECTED]> writes: > How big a project would it be to have generalized DDL triggers? Apart > from resource allocation, what are some downsides of providing such a > facility? BEFORE triggers on the system catalogs are Right Out. In principle we could support AFTER triggers,

DDL triggers [was Re: [GENERAL] database constraints]

2004-10-07 Thread David Fetter
On Thu, Oct 07, 2004 at 11:47:55AM +0700, David Garamond wrote: > Joshua D. Drake wrote: > >>This brings up an interesting idea. What if it were possible to set > >>some kind of rules on DDL at database creation time? For example, I'd > >>like to be able to throw an error if somebody tries to nam

Re: [GENERAL] database constraints

2004-10-07 Thread Marco Colombo
On Thu, 7 Oct 2004, David Garamond wrote: With all due respect, David, everybody is entitled to his own opinion and yours is not the absolute truth. Column and table naming is not exact science. Naming every single-column PK as "id" has advantages over "_id": - you instantly know that "id" is P

Re: [GENERAL] database constraints

2004-10-07 Thread Greg Stark
David Garamond <[EMAIL PROTECTED]> writes: > With all due respect, David, everybody is entitled to his own opinion and > yours is not the absolute truth. Column and table naming is not exact science. Sure. But let me put another big vote in favour against the "id" naming scheme and for the "tabl

Re: [GENERAL] database constraints

2004-10-07 Thread David Garamond
Joshua D. Drake wrote: This brings up an interesting idea. What if it were possible to set some kind of rules on DDL at database creation time? For example, I'd like to be able to throw an error if somebody tries to name an object any of the SQL keywords. Other possible rules: * Every table must

Re: [GENERAL] database constraints

2004-10-06 Thread David Garamond
David Fetter wrote: BTW, "id" is a terrible name for a column. Better call it foo_id. I disagree with the idea that "id" is a terrible name for a column. The only negative to it, is that you will have to be explicit in your declarations when doing joins and such... ex: SELECT * FROM foo JOIN

Re: [GENERAL] database constraints

2004-10-06 Thread Joshua D. Drake
This brings up an interesting idea. What if it were possible to set some kind of rules on DDL at database creation time? For example, I'd like to be able to throw an error if somebody tries to name an object any of the SQL keywords. Other possible rules: * Every table must have a comment * noCam

Re: [GENERAL] database constraints

2004-10-06 Thread Bruno Wolff III
On Wed, Oct 06, 2004 at 08:35:21 -0700, [EMAIL PROTECTED] wrote: > * Ben <[EMAIL PROTECTED]> [2004-10-06 08:23:11 -0700]: > > ALTER TABLE foo ADD CONSTRAINT must_have_a_or_b CHECK (a::int IS NULL > AND b::int IS NOT NULL OR a::int IS NOT NULL AND b::int IS NULL); A simpler constraint is: check

Re: [GENERAL] database constraints

2004-10-06 Thread David Fetter
On Wed, Oct 06, 2004 at 10:07:43AM -0700, Joshua D. Drake wrote: > >> > >>SELECT * FROM foo > >> JOIN bar on (foo.id = bar.id) > >> > >>Personally I would rather see, and write that then: > >> > >>SELECT * FROM foo > >> JOIN bar on (foo_id = bar_id) > > > > > >With all due respect, Josh, naming y

Re: [GENERAL] database constraints

2004-10-06 Thread Joshua D. Drake
SELECT * FROM foo JOIN bar on (foo.id = bar.id) Personally I would rather see, and write that then: SELECT * FROM foo JOIN bar on (foo_id = bar_id) With all due respect, Josh, naming your columns with decipherable names, i.e. *not* having 50 different things called "id" in your db helps enormo

Re: [GENERAL] database constraints

2004-10-06 Thread David Fetter
On Wed, Oct 06, 2004 at 09:32:02AM -0700, Joshua D. Drake wrote: > >What's "reasonable?" ;) > > > >BTW, "id" is a terrible name for a column. Better call it foo_id. > > Hello, > > I disagree with the idea that "id" is a terrible name for a column. The > only negative to it, is that you will h

Re: [GENERAL] database constraints

2004-10-06 Thread Joshua D. Drake
What's "reasonable?" ;) BTW, "id" is a terrible name for a column. Better call it foo_id. Hello, I disagree with the idea that "id" is a terrible name for a column. The only negative to it, is that you will have to be explicit in your declarations when doing joins and such... ex: SELECT * FRO

Re: [GENERAL] database constraints

2004-10-06 Thread Dennis Gearon
Use a post trigger function, ON UPDATE, INSERT which essentially has this in it: if ( ISNULL(new.a) AND ISNULL(new.b) ){ RAISE NOTICE "blah blah"; } I work with PHP a lot, just a little plpgsql, so, the grammar may be wrong above. Ben <[EMAIL PROTECTED]> wrote: If I have have the table: create

Re: [GENERAL] database constraints

2004-10-06 Thread David Fetter
On Wed, Oct 06, 2004 at 08:23:11AM -0700, Ben wrote: > If I have have the table: > > create table foo > ( > a int references bar(id), > b int references baz(id) > ) > > ... how do I make sure one and only one of the columns a and b are > non-null? You could write it like this: CREA

Re: [GENERAL] database constraints

2004-10-06 Thread sklassen
* Ben <[EMAIL PROTECTED]> [2004-10-06 08:23:11 -0700]: > If I have have the table: > > create table foo > ( > a int references bar(id), > b int references baz(id) > ) > > ... how do I make sure one and only one of the columns a and b are > non-null? Is it even reasonable? ALTER TAB

[GENERAL] database constraints

2004-10-06 Thread Ben
If I have have the table: create table foo ( a int references bar(id), b int references baz(id) ) ... how do I make sure one and only one of the columns a and b are non-null? Is it even reasonable? ---(end of broadcast)--- TIP 4: Don