Re: UPDATE/INSERT on multiple co-dependent tables

From: Karsten Hilbert <Karsten(dot)Hilbert(at)gmx(dot)net>
To: pgsql-sql <pgsql-sql(at)postgresql(dot)org>
Subject: Re: UPDATE/INSERT on multiple co-dependent tables
Date: 2004-11-14 08:47:24
Message-ID: 20041114094724.J568@hermes.hilbert.loc
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

> Is it possible for an UPDATE/INSERT query string to function in such a
> way that it requires two like fields in different tables to be equal
> to/'in sync with' one another:
>
> Example: I have two tables: registration & schedules....
> they both record a class_id, start_date, end_date... I want to make
> sure that if the schedule_id field is updated in the registration table;
> that class_id, start_date & end_date fields automatically change to
> match the schedules.id record in the schedules table....
Sounds like you want a foreign key with ON UPDATE CASCADE. If
that doesn't work for some reason or other you might be able
to achieve what you need with an explicit trigger on update of
registration.schedule_id.

Karsten
--
GPG key ID E4071346 @ wwwkeys.pgp.net
E167 67FD A291 2BEA 73BD 4537 78B9 A9F9 E407 1346

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Jakub Kaniewski 2004-11-14 13:13:05 View and subselect related questions
Previous Message Tom Lane 2004-11-14 00:02:04 Re: select using regexp does not use indexscan