Thread: command to Describe RULE

command to Describe RULE

From
Date:

I create a table (addresses) & its "historification".
When an address is modified, it's moved to the historification which is
basically a copy on "update" or "delete".
I seem to have a proble & I wanna find the RULE I created to alter them.
What command should I issue for that.
I seem to not be able to find any \d command for that ...
Could some one hint me ?

Tx,

Thomas,

===============================



-- This table is really useless as such
-- *************************************
CREATE TABLE historification ( pkh SERIAL,
                -- This will be the moment the record is "archived"
                               dateend TIMESTAMP DEFAULT CURRENT_TIMESTAMP);



-- Here is a basic address table
CREATE TABLE addresses ( pk SERIAL,
                         street CHAR(50) NOT NULL,
                         street2 CHAR(50),
                         zip CHAR(10) NOT NULL,
                         city CHAR(30) NOT NULL,
                         -- I have a table countries where the countries
                         -- iso-codes are stored
                         Country CHAR(2) REFERENCES COUNTRIES,
                         datemodified TIMESTAMP DEFAULT CURRENT_TIMESTAMP);


-- Here is the PostgreSQL historification
CREATE TABLE AddressHistorics ()
       INHERITS (historification, addresses);



CREATE RULE update_address AS
    ON UPDATE TO addresses
    DO
        INSERT INTO AddressHistorics (pk, street, street2, zip, city,
country, datemodified)
            VALUES (old.pk, old.street, old.street2, old.zip, old.city,
old.country, old.datemodified);


CREATE RULE delete_address AS
    ON DELETE TO Addresses
    DO
        INSERT INTO AddressHistorics (pk, street, street2, zip, city,
country, datemodified)
            VALUES (old.pk, old.street, old.street2, old.zip, old.city,
old.country, old.datemodified);


--
Thomas SMETS
rue J. Wytsmanstraat 62
1050 Bruxelles
yahoo-id : smetsthomas



Re: command to Describe RULE

From
"PGMailList"
Date:
select * from pg_rules

http://www.pgexplorer.com


----- Original Message -----
From: <tsmets@brutele.be>
To: <pgsql-general@postgresql.org>
Sent: Wednesday, March 27, 2002 3:19 AM
Subject: [GENERAL] command to Describe RULE


>
>
> I create a table (addresses) & its "historification".
> When an address is modified, it's moved to the historification which is
> basically a copy on "update" or "delete".
> I seem to have a proble & I wanna find the RULE I created to alter them.
> What command should I issue for that.
> I seem to not be able to find any \d command for that ...
> Could some one hint me ?
>
> Tx,
>
> Thomas,
>
> ===============================
>
>
>
> -- This table is really useless as such
> -- *************************************
> CREATE TABLE historification ( pkh SERIAL,
>                 -- This will be the moment the record is "archived"
>                                dateend TIMESTAMP DEFAULT
CURRENT_TIMESTAMP);
>
>
>
> -- Here is a basic address table
> CREATE TABLE addresses ( pk SERIAL,
>                          street CHAR(50) NOT NULL,
>                          street2 CHAR(50),
>                          zip CHAR(10) NOT NULL,
>                          city CHAR(30) NOT NULL,
>                          -- I have a table countries where the countries
>                          -- iso-codes are stored
>                          Country CHAR(2) REFERENCES COUNTRIES,
>                          datemodified TIMESTAMP DEFAULT
CURRENT_TIMESTAMP);
>
>
> -- Here is the PostgreSQL historification
> CREATE TABLE AddressHistorics ()
>        INHERITS (historification, addresses);
>
>
>
> CREATE RULE update_address AS
>     ON UPDATE TO addresses
>     DO
>         INSERT INTO AddressHistorics (pk, street, street2, zip, city,
> country, datemodified)
>             VALUES (old.pk, old.street, old.street2, old.zip, old.city,
> old.country, old.datemodified);
>
>
> CREATE RULE delete_address AS
>     ON DELETE TO Addresses
>     DO
>         INSERT INTO AddressHistorics (pk, street, street2, zip, city,
> country, datemodified)
>             VALUES (old.pk, old.street, old.street2, old.zip, old.city,
> old.country, old.datemodified);
>
>
> --
> Thomas SMETS
> rue J. Wytsmanstraat 62
> 1050 Bruxelles
> yahoo-id : smetsthomas
>
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 3: if posting/reading through Usenet, please send an appropriate
> subscribe-nomail command to majordomo@postgresql.org so that your
> message can get through to the mailing list cleanly
>