Thread: create rule

create rule

From
chunxia xu
Date:
This won't work:

CREATE TABLE pub_gene (
        pub_gene_id  serial PRIMARY KEY,
        name varchar(200) default NULL
);

CREATE TABLE term (
         term_id serial PRIMARY KEY,
         name varchar(200) default NULL,
         pub_gene_id  INTEGER references pub_gene
                       ON UPDATE CASCADE
                       ON DELETE SET NULL
);

CREATE RULE pub_gene_insert_term AS -- INSERT rule
ON INSERT TO pub_gene
DO
  insert into term(term_id, name, date_entered,
entered_by )
  values (nextval('term_term_id_seq'),
          (select name from pub_gene where
pub_gene_id=currval('pub_gene_pub_gene_id_seq'))
         )
  );


__________________________________________________
Do You Yahoo!?
Yahoo! - Official partner of 2002 FIFA World Cup
http://fifaworldcup.yahoo.com

Re: create rule

From
Oliver Elphick
Date:
On Mon, 2002-06-03 at 23:37, chunxia xu wrote:
> This won't work:
>
> CREATE TABLE pub_gene (
>         pub_gene_id  serial PRIMARY KEY,
>         name varchar(200) default NULL
> );
>
> CREATE TABLE term (
>          term_id serial PRIMARY KEY,
>          name varchar(200) default NULL,
>          pub_gene_id  INTEGER references pub_gene
>                        ON UPDATE CASCADE
>                        ON DELETE SET NULL
> );
>
> CREATE RULE pub_gene_insert_term AS -- INSERT rule
> ON INSERT TO pub_gene
> DO
>   insert into term(term_id, name, date_entered,
> entered_by )
>   values (nextval('term_term_id_seq'),
>           (select name from pub_gene where
> pub_gene_id=currval('pub_gene_pub_gene_id_seq'))
>          )
>   );

1. Too many closing parentheses;
2. Table "term" does not contain the fields "date_entered" and
"entered_by".

--
Oliver Elphick                                Oliver.Elphick@lfix.co.uk
Isle of Wight                              http://www.lfix.co.uk/oliver
GPG: 1024D/3E1D0C1C: CA12 09E0 E8D5 8870 5839  932A 614D 4C34 3E1D 0C1C

     "But without faith it is impossible to please him; for
      he that cometh to God must believe that he is, and
      that he is a rewarder of them that diligently seek
      him."       Hebrews 11:6

Attachment