pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
foreign key implementation
9+ messages / 8 participants
[nested] [flat]

* foreign key implementation
@ 2000-01-13 11:14 Pausas Fuentes, Jaume <JPausas@alehop.com>
  2000-01-13 21:21 ` Re: [SQL] foreign key implementation Oliver Elphick <olly@lfix.co.uk>
  2000-01-27 17:27 ` Re: [SQL] foreign key implementation Jan Wieck <wieck@debis.com>
  0 siblings, 2 replies; 9+ messages in thread

From: Pausas Fuentes, Jaume @ 2000-01-13 11:14 UTC (permalink / raw)
  To: pgsql-sql

Hi

Anybody have an implementation of the sql foreign key?

Reading the manual it says that I must use the create trigger command 
but how to implement a procedure to do what foreing key does?
 
             Jaume Pausas




^ permalink  raw  reply  [nested|flat] 9+ messages in thread

* Re: [SQL] foreign key implementation
  2000-01-13 11:14 foreign key implementation Pausas Fuentes, Jaume <JPausas@alehop.com>
@ 2000-01-13 21:21 ` Oliver Elphick <olly@lfix.co.uk>
  1 sibling, 0 replies; 9+ messages in thread

From: Oliver Elphick @ 2000-01-13 21:21 UTC (permalink / raw)
  To: Pausas Fuentes, Jaume <JPausas@alehop.com>; +Cc: pgsql-sql; olly@linda.lfix.co.uk

"Pausas Fuentes, Jaume" wrote:
  >Hi
  >
  >Anybody have an implementation of the sql foreign key?
  >
  >Reading the manual it says that I must use the create trigger command 
  >but how to implement a procedure to do what foreing key does?

You need the refint package out of contrib.

Then use commands like these:

create database bray;
\connect bray

-- refint functions (from postgresql-contrib package).  These are
-- needed until foreign keys are implemented in PostgreSQL
\i contrib/spi/refint.sql

create table area 
(
        id              char(2)         primary key,
        name            text            not null,
        vat_class       char(1)         default 'S'
);

create trigger area_fref
        before DELETE or UPDATE on area
        for each row execute procedure
        check_foreign_key (1, 'restrict', 'id',
                'customer', 'area'
                );

create table customer
(
        acs_code        char(8),
...
        area            char(2)         references area (id),
...
);

create trigger customer_pkref2
        before INSERT or UPDATE on customer
        for each row execute procedure
        check_primary_key ('area', 'area', 'id');


-- 
Oliver Elphick                                Oliver.Elphick@lfix.co.uk
Isle of Wight                              http://www.lfix.co.uk/oliver
               PGP key from public servers; key ID 32B8FAA1
                 ========================================
     "For the LORD is good; his mercy is everlasting; and 
      his truth endureth to all generations."         
                                     Psalms 100:5 





^ permalink  raw  reply  [nested|flat] 9+ messages in thread

* Re: [SQL] foreign key implementation
  2000-01-13 11:14 foreign key implementation Pausas Fuentes, Jaume <JPausas@alehop.com>
@ 2000-01-27 17:27 ` Jan Wieck <wieck@debis.com>
  1 sibling, 0 replies; 9+ messages in thread

From: wieck@debis.com @ 2000-01-27 17:27 UTC (permalink / raw)
  To: Pausas Fuentes, Jaume <JPausas@alehop.com>; +Cc: pgsql-sql

> Hi
>
> Anybody have an implementation of the sql foreign key?
>
> Reading the manual it says that I must use the create trigger command
> but how to implement a procedure to do what foreing key does?

    The  current development tree includes this. Will be released
    with version 7.0. Not completely  finished  up  to  now,  but
    enough to get a feeling.


Jan

--

#======================================================================#
# It's easier to get forgiveness for being wrong than for being right. #
# Let's break this rule - forgive me.                                  #
#========================================= wieck@debis.com (Jan Wieck) #





^ permalink  raw  reply  [nested|flat] 9+ messages in thread

* Foreign Key Implementation
@ 2000-04-04 23:19 Drozdowski, Catharine I <Drozdowski.Catharine@emeryworld.com>
  2000-04-05 01:04 ` Re: Foreign Key Implementation Mathijs Brands <mathijs@ilse.nl>
  2000-04-05 06:27 ` Re: Foreign Key Implementation Alexey V. Meledin <avm@webclub.ru>
  0 siblings, 2 replies; 9+ messages in thread

From: Drozdowski, Catharine I @ 2000-04-04 23:19 UTC (permalink / raw)
  To: pgsql-sql

Hi All,
I had my first go at Postgres today. So far so good. But I need to know how
to implement foreign keys using postgres. I did not find anything in the
documentation and several searches on "foreign" key produced nothing. 

Does Postgres have foreign key functionality. And if not why and when???

thanks for your kind consideration to a naive, novice. 

Catharine 

Catharine Drozdowski
Emery WorldWide
Oracle Database Administrator
PHONE: (503) 450 5712





^ permalink  raw  reply  [nested|flat] 9+ messages in thread

* Re: Foreign Key Implementation
  2000-04-04 23:19 Foreign Key Implementation Drozdowski, Catharine I <Drozdowski.Catharine@emeryworld.com>
@ 2000-04-05 01:04 ` Mathijs Brands <mathijs@ilse.nl>
  2000-04-05 08:25   ` Re: Foreign Key Implementation Kovacs Zoltan Sandor <tip@pc10.radnoti-szeged.sulinet.hu>
  1 sibling, 1 reply; 9+ messages in thread

From: Mathijs Brands @ 2000-04-05 01:04 UTC (permalink / raw)
  To: Drozdowski, Catharine I <Drozdowski.Catharine@emeryworld.com>; +Cc: pgsql-sql

On Tue, Apr 04, 2000 at 11:19:56PM -0000, Drozdowski, Catharine I allegedly wrote:
> Hi All,
> I had my first go at Postgres today. So far so good. But I need to know how
> to implement foreign keys using postgres. I did not find anything in the
> documentation and several searches on "foreign" key produced nothing. 
> 
> Does Postgres have foreign key functionality. And if not why and when???

I'm no expert on this, but PostgreSQL does have a foreign key implementation,
albeit a somewhat cumbersome IMO. You should look the refint (referential
integrity) stuff in the contrib directory of the sourcetree. Since I don't
have a sourcetree lying around at the moment, I can't verify the exact name
of the directory. The goodies may be located in the SDI (or something similar)
directory. What it boils down to is that you use triggers to enforce referential
integrity. It works just fine, but is a bit labourious to setup.

My 0.02 EU,

Mathijs



^ permalink  raw  reply  [nested|flat] 9+ messages in thread

* Re: Foreign Key Implementation
  2000-04-04 23:19 Foreign Key Implementation Drozdowski, Catharine I <Drozdowski.Catharine@emeryworld.com>
  2000-04-05 01:04 ` Re: Foreign Key Implementation Mathijs Brands <mathijs@ilse.nl>
@ 2000-04-05 08:25   ` Kovacs Zoltan Sandor <tip@pc10.radnoti-szeged.sulinet.hu>
  0 siblings, 0 replies; 9+ messages in thread

From: Kovacs Zoltan Sandor @ 2000-04-05 08:25 UTC (permalink / raw)
  To: Mathijs Brands <mathijs@ilse.nl>; +Cc: Drozdowski, Catharine I <Drozdowski.Catharine@emeryworld.com>; pgsql-sql

> I'm no expert on this, but PostgreSQL does have a foreign key implementation,
> albeit a somewhat cumbersome IMO. You should look the refint (referential
> integrity) stuff in the contrib directory of the sourcetree. Since I don't
> have a sourcetree lying around at the moment, I can't verify the exact name
> of the directory. The goodies may be located in the SDI (or something similar)
> directory. What it boils down to is that you use triggers to enforce referential
> integrity. It works just fine, but is a bit labourious to setup.
The old contrib/spi/refint.c is obsolete now. You should use the new
implementation. Go to www.postgresql.org and search for Jan Wieck's TODO
page about reference integrity, you will find the exact syntax there.
Examples can be found in the mailing list, also on www.postgresql.org.

Regards,
Zoltan




^ permalink  raw  reply  [nested|flat] 9+ messages in thread

* Re: Foreign Key Implementation
  2000-04-04 23:19 Foreign Key Implementation Drozdowski, Catharine I <Drozdowski.Catharine@emeryworld.com>
@ 2000-04-05 06:27 ` Alexey V. Meledin <avm@webclub.ru>
  2000-04-05 08:50   ` Re: Foreign Key Implementation Moray McConnachie <moray.mcconnachie@computing-services.oxford.ac.uk>
  2000-04-05 09:43   ` Re: Foreign Key Implementation Kovacs Zoltan Sandor <tip@pc10.radnoti-szeged.sulinet.hu>
  1 sibling, 2 replies; 9+ messages in thread

From: Alexey V. Meledin @ 2000-04-05 06:27 UTC (permalink / raw)
  To: Drozdowski, Catharine I <Drozdowski.Catharine@emeryworld.com>; pgsql-sql

Hi,
  I!

Wednesday, April 05, 2000, 3:19:56 AM, you wrote:


DCI>But I need to know how to implement foreign keys using postgres. I did not find anything in the
DCI> documentation and several searches on "foreign" key produced nothing.
There is no way to implement foreign keys. Data will always be copy
when you'll try to pass it as FK.
DCI> Does Postgres have foreign key functionality. And if not why and when???
postgresql 7.0 coming

So, with posgres 6.* you can implement only relational integrity. I
Use Erwin and it's macroses to implement automatic RI creation.


Regards, Alexey V. Meledin
InterForge Developers Group, Saint-Petersburg
look_to: <www.etcompany.ru><www.businessweb.ru>
<www.inplan.spb.ru><www.pia.ru>>>>>>>>>>>>>>>>>
mail_to: <avm@webclub.ru><nick_as: <cureman>>>>





^ permalink  raw  reply  [nested|flat] 9+ messages in thread

* Re: Foreign Key Implementation
  2000-04-04 23:19 Foreign Key Implementation Drozdowski, Catharine I <Drozdowski.Catharine@emeryworld.com>
  2000-04-05 06:27 ` Re: Foreign Key Implementation Alexey V. Meledin <avm@webclub.ru>
@ 2000-04-05 08:50   ` Moray McConnachie <moray.mcconnachie@computing-services.oxford.ac.uk>
  1 sibling, 0 replies; 9+ messages in thread

From: Moray McConnachie @ 2000-04-05 08:50 UTC (permalink / raw)
  To: Drozdowski, Catharine I <Drozdowski.Catharine@emeryworld.com>; pgsql-sql

But don't forget that in 7.0, which we see is hopefully coming in ten days'
time, foreign keys are almost entirely supported.
Look at the mailing list of pgsql-general for last month, and see several
people replying to a question I posted with the syntax...
Yrs,
Moray
----------------------------------------------------------------
Moray.McConnachie@computing-services.oxford.ac.uk
----- Original Message -----
From: "Alexey V. Meledin" <avm@webclub.ru>
To: "Drozdowski, Catharine I" <Drozdowski.Catharine@emeryworld.com>;
<pgsql-sql@postgresql.org>
Sent: Wednesday, April 05, 2000 7:27 AM
Subject: Re: [SQL] Foreign Key Implementation


> Hi,
>   I!
>
> Wednesday, April 05, 2000, 3:19:56 AM, you wrote:
>
>
> DCI>But I need to know how to implement foreign keys using postgres. I did
not find anything in the
> DCI> documentation and several searches on "foreign" key produced nothing.
> There is no way to implement foreign keys. Data will always be copy
> when you'll try to pass it as FK.
> DCI> Does Postgres have foreign key functionality. And if not why and
when???
> postgresql 7.0 coming
>
> So, with posgres 6.* you can implement only relational integrity. I
> Use Erwin and it's macroses to implement automatic RI creation.
>
>
> Regards, Alexey V. Meledin
> InterForge Developers Group, Saint-Petersburg
> look_to: <www.etcompany.ru><www.businessweb.ru>
> <www.inplan.spb.ru><www.pia.ru>>>>>>>>>>>>>>>>>
> mail_to: <avm@webclub.ru><nick_as: <cureman>>>>
>
>
>




^ permalink  raw  reply  [nested|flat] 9+ messages in thread

* Re: Foreign Key Implementation
  2000-04-04 23:19 Foreign Key Implementation Drozdowski, Catharine I <Drozdowski.Catharine@emeryworld.com>
  2000-04-05 06:27 ` Re: Foreign Key Implementation Alexey V. Meledin <avm@webclub.ru>
@ 2000-04-05 09:43   ` Kovacs Zoltan Sandor <tip@pc10.radnoti-szeged.sulinet.hu>
  1 sibling, 0 replies; 9+ messages in thread

From: Kovacs Zoltan Sandor @ 2000-04-05 09:43 UTC (permalink / raw)
  To: Alexey V. Meledin <avm@webclub.ru>; +Cc: Drozdowski, Catharine I <Drozdowski.Catharine@emeryworld.com>; pgsql-sql

The documentation in 7.0 is rather obsolete, sorry for inconvenience. The
release will hopefully contain all information. Here is an example for
basic foreign key definition:

create table group(id serial, name varchar(20));
create table member(id serial, name varchar(30), group int4
 references group(id));

The following has the same result:

create table group(id serial, name varchar(20));
create table member(id serial, name varchar(30), group int4,
 foreign key id references group(id)
 on update restrict on delete restrict);

I hope this helps.

Regards,
Zoltan




^ permalink  raw  reply  [nested|flat] 9+ messages in thread


end of thread, other threads:[~2000-04-05 09:43 UTC | newest]

Thread overview: 9+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2000-01-13 11:14 foreign key implementation Pausas Fuentes, Jaume <JPausas@alehop.com>
2000-01-13 21:21 ` Oliver Elphick <olly@lfix.co.uk>
2000-01-27 17:27 ` Jan Wieck <wieck@debis.com>
2000-04-04 23:19 Foreign Key Implementation Drozdowski, Catharine I <Drozdowski.Catharine@emeryworld.com>
2000-04-05 01:04 ` Re: Foreign Key Implementation Mathijs Brands <mathijs@ilse.nl>
2000-04-05 08:25   ` Re: Foreign Key Implementation Kovacs Zoltan Sandor <tip@pc10.radnoti-szeged.sulinet.hu>
2000-04-05 06:27 ` Re: Foreign Key Implementation Alexey V. Meledin <avm@webclub.ru>
2000-04-05 08:50   ` Re: Foreign Key Implementation Moray McConnachie <moray.mcconnachie@computing-services.oxford.ac.uk>
2000-04-05 09:43   ` Re: Foreign Key Implementation Kovacs Zoltan Sandor <tip@pc10.radnoti-szeged.sulinet.hu>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox