From: | "Joel Burton" <jburton(at)scw(dot)org> |
---|---|
To: | pgsql-hackers(at)postgreSQL(dot)org, pgsql-sql(at)postgreSQL(dot)org |
Subject: | Rules with Conditions: Bug, or Misunderstanding |
Date: | 2000-11-30 00:00:22 |
Message-ID: | 3A255246.21430.688927F3@localhost |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers pgsql-sql |
Am I misunderstanding how to use rule w/conditionals, or is there a
bug in this?
--
I love to use Pgsql comments, but find the 'comment on field...'
language a bit of a pain for documenting a large database at the
last minute. So, I wrote a query that pulls together all the fields in a
database, w/descriptions (if any):
create view dev_col_comments as
select a.oid as att_oid,
relname,
attname,
description
from pg_class c,
pg_attribute a left outer join pg_description d on d.objoid=a.oid
where c.oid=a.attrelid
and (c.relkind='r' or c.relkind='v') and c.relname !~ '^pg_'
and attname not in ('xmax','xmin','cmax','cmin','ctid','oid','tableoid')
order by relname, attname;
[This uses pg7.1 syntax; you could rewrite for 7.0 w/o the 'v' for
views, and using a union rather than outer join.]
This works great. Feeling clever, I wrote two rules, so I could
update this and create comments. I need two rules, one if this is an
existing description (becoming an update to pg_description), one if
this not (becoming an insert to pg_description).
create rule dev_ins as on update to dev_col_comments where
old.description isnull do instead insert into pg_description ( objoid,
description) values (old.att_oid, new.description);
create rule dev_upd as on update to dev_col_comments where
old.description notnull do instead update pg_description set
description=new.description where objoid=old.att_oid;
This doesn't work: I get a "cannot update view w/o rule" error
message, both for fields where description was null, and for fields
where it wasn't null.
If I take out the "where old.description isnull" clause of dev_ins, it
works fine--but, only, of course, if I am sure to only pick new
descriptions. Or, if I take out the clause in dev_upd, it works too,
with the opposite caveat.
Is this a bug? Am I misunderstanding something about the way that
rule conditions should work? The docs are long but fuzzy on rules
(they seem to suggest, for instance, that "create rule foo on
update to table.column" will work, when this is not implemented yet,
so perhaps the docs are ahead of the implementation?)
Any help would be great!
I do read the pgsql lists, but always appreciate a cc, so I don't miss
any comments. TIA.
Thanks,
--
Joel Burton, Director of Information Systems -*- jburton(at)scw(dot)org
Support Center of Washington (www.scw.org)
From | Date | Subject | |
---|---|---|---|
Next Message | Tom Lane | 2000-11-30 00:25:17 | Re: [GENERAL] Warning: Don't delete those /tmp/.PGSQL.* files |
Previous Message | Joel Burton | 2000-11-29 23:49:07 | Re: [GENERAL] Warning: Don't delete those /tmp/.PGSQL.* files |
From | Date | Subject | |
---|---|---|---|
Next Message | Joseph Shraibman | 2000-11-30 00:03:36 | subselects |
Previous Message | Limin Shen | 2000-11-29 23:35:26 | SETOF |