Re: SOLVED - [SQL] foreign keys and lots of tables

2011-05-19 Thread Gary Stainburn
anyway. Gary On Thursday 19 May 2011 01:09:07 David W Noon wrote: > On Wed, 18 May 2011 20:10:19 +0100, Gary Stainburn wrote about [SQL] > > foreign keys and lots of tables: > >I have the following tables (individual seat allocation removed to > >make it simpler) > >

Re: [SQL] foreign keys and lots of tables

2011-05-18 Thread David W Noon
On Wed, 18 May 2011 20:10:19 +0100, Gary Stainburn wrote about [SQL] foreign keys and lots of tables: >I have the following tables (individual seat allocation removed to >make it simpler) Omitting details makes the problem more difficult to comprehend. [snip] >create table book

[SQL] foreign keys and lots of tables

2011-05-18 Thread Gary Stainburn
I have the following tables (individual seat allocation removed to make it simpler) create table coaches ( -- carriages c_id serial primary key, c_namevarchar(20) not null ); create table trains ( -- one for each train t_id serial primary key ); create table train_coaches

Re: [SQL] Foreign keys and fixed values...

2009-07-30 Thread Daryl Richter
Hi- On Jul 29, 2009, at 4:16 PM, Kjell Rune Skaaraas wrote: Hello, I'm having a problem using foreign keys, or at least in a way i find good. Basicly I have a table I wish to use as a foreign key with lookup "id" and "code", like: 1,a 1,b 1,c 2,a 2,d I have of course an UNIQUE on (id,c

[SQL] Foreign keys and fixed values...

2009-07-29 Thread Kjell Rune Skaaraas
Hello, I'm having a problem using foreign keys, or at least in a way i find good. Basicly I have a table I wish to use as a foreign key with lookup "id" and "code", like: 1,a 1,b 1,c 2,a 2,d I have of course an UNIQUE on (id,code). However, in the table I want the key to apply to, I only hav

Re: [SQL] foreign keys with on delete cascade and triggers

2006-01-12 Thread Tom Lane
Dirk Jagdmann <[EMAIL PROTECTED]> writes: > Now I'd like to know if the current order of deletions in PostgreSQL > is intended in the top-down way or if that could be changed? Sorry, I don't see much chance of changing it. regards, tom lane ---(end

Re: [SQL] foreign keys with on delete cascade and triggers

2006-01-12 Thread Dirk Jagdmann
Hello Tom, > If you want the whole transaction rolled back, raise an error instead > of returning NULL. You're right, that's working. But now I have a slightly different problem. I assume that the trigger which watches the cascaded deletions first deletes the row in the monitored table and then

Re: [SQL] foreign keys with on delete cascade and triggers

2006-01-11 Thread Tom Lane
Dirk Jagdmann <[EMAIL PROTECTED]> writes: > The idea behind the sample commands below is, that the whole deletion > should be denied, because a trigger in a cascaded table blocked the > deletion. The trigger works as expected and prevents rows with a value > of "5" being deleted from table "b". How

[SQL] foreign keys with on delete cascade and triggers

2006-01-11 Thread Dirk Jagdmann
Hello, I often create foreign keys with "on delete cascade" so I can conviniently delete rows in multiple tables which are referenced by (a chain) of foreign keys. Now I've run into an issue and I'd like to have some opinions if the current behaviour of PostgreSQL is desired. If have made my tests

Re: [SQL] FOREIGN KEYs ... I think ...

2006-01-05 Thread Marc G. Fournier
Thanks to everyone for the responses ... ended up doing a trigger on the comments table that updates another table to maintain a "pointer" to the active record ... sped up the query that was hampering us from ~26 000ms to 47ms ... the killer part of the query was that each time it was havin g

Re: [SQL] FOREIGN KEYs ... I think ...

2006-01-05 Thread Leif B. Kristensen
On Thursday 05 January 2006 04:58, [EMAIL PROTECTED] wrote: >That's not what foreign keys do. The only thing a foreign key > provides is a guarantee that if any records in B (the referencing > table) still reference a record in table A (the referenced table) > then you cannot delete that reference

Re: [SQL] FOREIGN KEYs ... I think ...

2006-01-04 Thread nospam
> Now, what I want to do is add a FOREIGN KEY (again, I think) that when > incident_summary.status is changed (either closed, or reopened), the > associated records in incident_comments are changed to the same state ... As the other responders mentioned, from the schema you described, it doesn't l

Re: [SQL] FOREIGN KEYs ... I think ...

2006-01-04 Thread Jim Johannsen
Marc Is the "assumption" that anytime there are comments the status changes? If I'm reading between the lines correctly, there could be a large number of comments before the status changes. So no need to change status until explicitly needed. If there is a specific "comment" th

Re: [SQL] FOREIGN KEYs ... I think ...

2006-01-04 Thread Marc G. Fournier
On Wed, 4 Jan 2006, Tom Lane wrote: "Marc G. Fournier" <[EMAIL PROTECTED]> writes: Now, what I want to do is add a FOREIGN KEY (again, I think) that when incident_summary.status is changed (either closed, or reopened), the associated records in incident_comments are changed to the same state ..

Re: [SQL] FOREIGN KEYs ... I think ...

2006-01-04 Thread Tom Lane
"Marc G. Fournier" <[EMAIL PROTECTED]> writes: > Now, what I want to do is add a FOREIGN KEY (again, I think) that when > incident_summary.status is changed (either closed, or reopened), the > associated records in incident_comments are changed to the same state ... Why not just get rid of the s

[SQL] FOREIGN KEYs ... I think ...

2006-01-04 Thread Marc G. Fournier
I'm not sure if I'm looking at (for) the right thing or not, but if I am, then I'm not finding any useful examples :( I have two tables, simplified as: CREATE TABLE incident_summary ( id serial, subject text, status boolean ); CREATE TABLE incident_comments ( id serial, incident_id

Re: [SQL] foreign keys again

2002-10-18 Thread wishy wishy
hi folks, For a certain table A, I need to find out the names of the columns who have a foreign key to a specific table B using the catalog.Has anyone done this before entirely using pgsql.I have been through the archieves and have not been able to find the required information. thanks kprasad

[SQL] Foreign Keys and Inheritance

2001-06-06 Thread Dennis Muhlestein
If I have table A, which contains a primary key, and table B which inherits from A. How can I Create a Foreign Key on table C that references A, but will also pass if a record in inserted in to B. for instance: create table A ( prim_key char(20) not null primary key ); create table B

Re: [SQL] Foreign Keys

2001-02-05 Thread Colin Faber
Foreign keys are not supported in that version :p see: http://www.postgresql.org/devel-corner/docs/ "" wrote: > I have PostgreSQL 6.5, and I can't get foreign keys to work! What seems to > be the problem?

[SQL] Foreign Keys

2001-02-05 Thread
I have PostgreSQL 6.5, and I can't get foreign keys to work! What seems to be the problem?