pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Table Copy.
4+ messages / 4 participants
[nested] [flat]

* Table Copy.
@ 2002-09-19 15:56 PostgreSQL Server <postgres@rsd.it>
  2002-09-19 18:10 ` Re: Table Copy. Michael Paesold <mpaesold@gmx.at>
  2002-09-19 22:48 ` Re: Table Copy. Dmitry Tkach <dmitry@openratings.com>
  2002-09-20 02:04 ` Re: Table Copy. Christopher Kings-Lynne <chriskl@familyhealth.com.au>
  0 siblings, 3 replies; 4+ messages in thread

From: PostgreSQL Server @ 2002-09-19 15:56 UTC (permalink / raw)
  To: pgsql-sql


HI!

I'm new to postgres. I need to have a table as a copy of another one.

Example:

CREATE TABLE one (
        fileda INTEGER,
        filedb INTEGER,
        filedc INTEGER );

CREATE TABLE two (
        fileda INTEGER,
        filedb INTEGER,
        filedc INTEGER );

As on insert to table one I should get the same insert on table two.
As on delete to table one I should get the same delete on table two.
As on update to table one I should get the same update on table two.

Can someone provide the examples i can study ?

Thanks in advance.

Alex






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

* Re: Table Copy.
  2002-09-19 15:56 Table Copy. PostgreSQL Server <postgres@rsd.it>
@ 2002-09-19 18:10 ` Michael Paesold <mpaesold@gmx.at>
  2 siblings, 0 replies; 4+ messages in thread

From: Michael Paesold @ 2002-09-19 18:10 UTC (permalink / raw)
  To: PostgreSQL Server <postgres@rsd.it>; pgsql-sql

Alex wrote:
> HI!
> 
> I'm new to postgres. I need to have a table as a copy of another one.
> 
> Example:
> 
> CREATE TABLE one (
>         fileda INTEGER,
>         filedb INTEGER,
>         filedc INTEGER );
> 
> CREATE TABLE two (
>         fileda INTEGER,
>         filedb INTEGER,
>         filedc INTEGER );
> 
> As on insert to table one I should get the same insert on table two.
> As on delete to table one I should get the same delete on table two.
> As on update to table one I should get the same update on table two.
> 
> Can someone provide the examples i can study ?

You could do it with RULEs. Here is an example how you would do the DELETE.

CREATE RULE copy_one_to_two AS
  ON DELETE TO one
  DO
    DELETE FROM two
    WHERE two.fileda=OLD.fileda
      AND two.filedb=OLD.filedb
      AND two.filedc=OLD.filedc;

You should change the where clause if you have a primary key on that table.
I am presuming fileda/filedb/filedc are unique in combination...
Read the section of the docs about RULEs for INSERT and UPDATE examples.

Regards,
Michael Paesold




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

* Re: Table Copy.
  2002-09-19 15:56 Table Copy. PostgreSQL Server <postgres@rsd.it>
@ 2002-09-19 22:48 ` Dmitry Tkach <dmitry@openratings.com>
  2 siblings, 0 replies; 4+ messages in thread

From: Dmitry Tkach @ 2002-09-19 22:48 UTC (permalink / raw)
  To: PostgreSQL Server <postgres@rsd.it>

what about
  CREATE TABLE one (
          fileda INTEGER,
          filedb INTEGER,
          filedc INTEGER );
   CREATE VIEW two AS SELECT * FROM one;
?

Dima

PostgreSQL Server wrote:
> HI!
> 
> I'm new to postgres. I need to have a table as a copy of another one.
> 
> Example:
> 
> CREATE TABLE one (
>         fileda INTEGER,
>         filedb INTEGER,
>         filedc INTEGER );
> 
> CREATE TABLE two (
>         fileda INTEGER,
>         filedb INTEGER,
>         filedc INTEGER );
> 
> As on insert to table one I should get the same insert on table two.
> As on delete to table one I should get the same delete on table two.
> As on update to table one I should get the same update on table two.
> 
> Can someone provide the examples i can study ?
> 
> Thanks in advance.
> 
> Alex
> 
> 
> 
> 
> ---------------------------(end of broadcast)---------------------------
> TIP 1: subscribe and unsubscribe commands go to majordomo@postgresql.org
> 





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

* Re: Table Copy.
  2002-09-19 15:56 Table Copy. PostgreSQL Server <postgres@rsd.it>
@ 2002-09-20 02:04 ` Christopher Kings-Lynne <chriskl@familyhealth.com.au>
  2 siblings, 0 replies; 4+ messages in thread

From: Christopher Kings-Lynne @ 2002-09-20 02:04 UTC (permalink / raw)
  To: PostgreSQL Server <postgres@rsd.it>; pgsql-sql

> As on insert to table one I should get the same insert on table two.
> As on delete to table one I should get the same delete on table two.
> As on update to table one I should get the same update on table two.
> 
> Can someone provide the examples i can study ?

Look up 'CREATE TRIGGER' and 'CREATE RULE' in the postgres documentation.

Chris




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


end of thread, other threads:[~2002-09-20 02:04 UTC | newest]

Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2002-09-19 15:56 Table Copy. PostgreSQL Server <postgres@rsd.it>
2002-09-19 18:10 ` Michael Paesold <mpaesold@gmx.at>
2002-09-19 22:48 ` Dmitry Tkach <dmitry@openratings.com>
2002-09-20 02:04 ` Christopher Kings-Lynne <chriskl@familyhealth.com.au>

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