Обсуждение: Named constraints
I am trying to create a named constraint, but it doesn't seem to take the name. I got an example from the referential integrity page http://techdocs.postgresql.org/techdocs/hackingreferentialintegrity.php After looking the examples I created SQL script create table Users ( UserID serial primary key, GroupID integer constraint fkgroup references Groups, LocationID integer constraint fklocations references Locations, Password varchar(20) NOT NULL, Name varchar(16) NOT NULL, LongName varchar(20) NOT NULL, Email varchar(50) ); It creates the table, but lists the triggers Triggers: RI_ConstraintTrigger_13682386, RI_ConstraintTrigger_13682392 Is there a different syntax I should be using?
On Wed, 22 May 2002, Francisco Reyes wrote: > I am trying to create a named constraint, but it doesn't seem to take the > name. > > I got an example from the referential integrity page > http://techdocs.postgresql.org/techdocs/hackingreferentialintegrity.php > > After looking the examples I created SQL script > > create table Users > ( > UserID serial primary key, > GroupID integer > constraint fkgroup > references Groups, > LocationID integer > constraint fklocations > references Locations, > Password varchar(20) NOT NULL, > Name varchar(16) NOT NULL, > LongName varchar(20) NOT NULL, > Email varchar(50) > ); > > It creates the table, but lists the triggers > Triggers: RI_ConstraintTrigger_13682386, > RI_ConstraintTrigger_13682392 > > Is there a different syntax I should be using? Nope, that's right, it's just that the trigger names aren't the same as the constraint name. If you violate the constraint it should use the given names, and when drop constraint works with fk constraints it'll use them as well.
On Wed, 22 May 2002, Stephan Szabo wrote: > On Wed, 22 May 2002, Francisco Reyes wrote: > > GroupID integer > > constraint fkgroup > > references Groups, > > Nope, that's right, it's just that the trigger > names aren't the same as the constraint name. Would be nice if the triggers used more meaninful names. > If you violate the constraint it should use the > given names, and when drop constraint works with > fk constraints it'll use them as well. Is there a way to list the constraints? I did not see any '\d' parameter to list them.
On Wed, 22 May 2002, Francisco Reyes wrote: > On Wed, 22 May 2002, Stephan Szabo wrote: > > > On Wed, 22 May 2002, Francisco Reyes wrote: > > > GroupID integer > > > constraint fkgroup > > > references Groups, > > > > Nope, that's right, it's just that the trigger > > names aren't the same as the constraint name. > > Would be nice if the triggers used more meaninful names. I don't actually think that'd be too hard, although the names would have to have something added to make them more unique. Jan would probably know why the current naming was chosen. > > > If you violate the constraint it should use the > > given names, and when drop constraint works with > > fk constraints it'll use them as well. > > Is there a way to list the constraints? > I did not see any '\d' parameter to list them. The only way I know of to get the constraint name for foreign keys requires reading tgconstrname from pg_trigger.