Re: Bug in pg_get_ruledef?

Lists: pgsql-hackers
From: Sergio Pili <sergiop(at)sinectis(dot)com(dot)ar>
To: pgsql-hackers(at)postgresql(dot)org
Cc: Laura Celia Rivero <lrivero(at)exa(dot)unicen(dot)edu(dot)ar>, Jorge Doorn <jdoorn(at)exa(dot)unicen(dot)edu(dot)ar>
Subject: Bug in pg_get_ruledef?
Date: 2001-11-25 22:24:16
Message-ID: 3C016F90.AA8824ED@sinectis.com.ar
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Hello,

pg_get_ruledef cannot read the following rule:

test=# select version();
version
---------------------------------------------------------------------
PostgreSQL 7.2b3 on i686-pc-linux-gnu, compiled by GCC egcs-2.91.66
(1 row)

With the following tables:

test=# \d rd
Table "rd"
Column | Type | Modifiers
--------+----------+-----------
a | smallint |
b | smallint |
c | text |

Table "ri"
Column | Type | Modifiers
--------+----------+--------------
d | smallint |
e | text |
a | smallint | default 1000
b | smallint | default 2000

I create the following rule:

CREATE RULE ins_rd
AS ON INSERT TO ri
WHERE NEW.a IS NOT NULL
AND NEW.b IS NOT NULL
DO
INSERT INTO rd (a,b)
select distinct new.a,new.b

The rule works well. But when i select pg_rules:

test=# select * from pg_rules;
ERROR: Invalid attnum 3 for rangetable entry *SELECT*

Thanks in advance

Sergio.


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Sergio Pili <sergiop(at)sinectis(dot)com(dot)ar>
Cc: pgsql-hackers(at)postgresql(dot)org, Laura Celia Rivero <lrivero(at)exa(dot)unicen(dot)edu(dot)ar>, Jorge Doorn <jdoorn(at)exa(dot)unicen(dot)edu(dot)ar>
Subject: Re: Bug in pg_get_ruledef?
Date: 2001-11-25 23:05:37
Message-ID: 5661.1006729537@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Sergio Pili <sergiop(at)sinectis(dot)com(dot)ar> writes:
> test=# select * from pg_rules;
> ERROR: Invalid attnum 3 for rangetable entry *SELECT*

Problem confirmed here. Will look at it.

regards, tom lane


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Sergio Pili <sergiop(at)sinectis(dot)com(dot)ar>
Cc: pgsql-hackers(at)postgresql(dot)org, Laura Celia Rivero <lrivero(at)exa(dot)unicen(dot)edu(dot)ar>, Jorge Doorn <jdoorn(at)exa(dot)unicen(dot)edu(dot)ar>
Subject: Re: Bug in pg_get_ruledef?
Date: 2001-11-26 00:30:59
Message-ID: 6963.1006734659@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Sergio Pili <sergiop(at)sinectis(dot)com(dot)ar> writes:
> pg_get_ruledef cannot read the following rule:

Fix committed --- many thanks for the report!

Attached is the patch against current sources, if you need it.

regards, tom lane

*** src/backend/utils/adt/ruleutils.c.orig Mon Nov 19 14:51:20 2001
--- src/backend/utils/adt/ruleutils.c Sun Nov 25 19:18:32 2001
***************
*** 769,775 ****
--- 769,788 ----
appendStringInfo(buf, " WHERE ");

qual = stringToNode(ev_qual);
+
+ /*
+ * We need to make a context for recognizing any Vars in the qual
+ * (which can only be references to OLD and NEW). Use the rtable
+ * of the first query in the action list for this purpose.
+ */
query = (Query *) lfirst(actions);
+
+ /*
+ * If the action is INSERT...SELECT, OLD/NEW have been pushed
+ * down into the SELECT, and that's what we need to look at.
+ * (Ugly kluge ... try to fix this when we redesign querytrees.)
+ */
+ query = getInsertSelectQuery(query, NULL);

context.buf = buf;
context.namespaces = makeList1(&dpns);