Re: pgsql: Instead of supposing (wrongly, in the general - Mailing list pgsql-committers

From Neil Conway
Subject Re: pgsql: Instead of supposing (wrongly, in the general
Date
Msg-id 41BBEF27.9050308@samurai.com
Whole thread Raw
In response to pgsql: Instead of supposing (wrongly, in the general case) that the  (tgl@svr1.postgresql.org (Tom Lane))
Responses Re: pgsql: Instead of supposing (wrongly, in the
List pgsql-committers
Tom Lane wrote:
> Instead of supposing (wrongly, in the general case) that the rowtype
> of an inheritance child table is binary-compatible with the rowtype of
> its parent, invent an expression node type that does the conversion
> correctly.  Fixes the new bug exhibited by Kris Shannon as well as a
> lot of old bugs that would only show up when using multiple inheritance
> or after altering the parent table.

Attached is a patch adding regression tests for this change. I'll apply
it to HEAD later tonight or tomorrow baring any objections. I just used
the two test cases posted in the -hackers thread; Tom, if you have any
other test cases for this behavior in mind, just let me know.

-Neil
--- src/test/regress/expected/inherit.out
+++ src/test/regress/expected/inherit.out
@@ -623,3 +623,31 @@
  32 | one | two | three
 (1 row)

+-- Tests for casting between the rowtypes of parent and child
+-- tables. See the pgsql-hackers thread beginning Dec. 4/04
+create table base (i integer);
+create table derived () inherits (base);
+insert into derived (i) values (0);
+select derived::base from derived;
+ derived
+---------
+ (0)
+(1 row)
+
+drop table derived;
+drop table base;
+create table p1(ff1 int);
+create table p2(f1 text);
+create function p2text(p2) returns text as 'select $1.f1' language sql;
+create table c1(f3 int) inherits(p1,p2);
+insert into c1 values(123456789, 'hi', 42);
+select p2text(c1.*) from c1;
+ p2text
+--------
+ hi
+(1 row)
+
+drop function p2text(p2);
+drop table c1;
+drop table p2;
+drop table p1;
--- src/test/regress/sql/inherit.sql
+++ src/test/regress/sql/inherit.sql
@@ -146,7 +146,25 @@

 -- Test changing the type of inherited columns
 insert into d values('test','one','two','three');
+alter table a alter column aa type integer using bit_length(aa);
+select * from d;

-alter table a alter column aa type integer using bit_length(aa);
+-- Tests for casting between the rowtypes of parent and child
+-- tables. See the pgsql-hackers thread beginning Dec. 4/04
+create table base (i integer);
+create table derived () inherits (base);
+insert into derived (i) values (0);
+select derived::base from derived;
+drop table derived;
+drop table base;

+create table p1(ff1 int);
+create table p2(f1 text);
+create function p2text(p2) returns text as 'select $1.f1' language sql;
+create table c1(f3 int) inherits(p1,p2);
+insert into c1 values(123456789, 'hi', 42);
+select p2text(c1.*) from c1;
+drop function p2text(p2);
+drop table c1;
+drop table p2;
+drop table p1;
-select * from d;

pgsql-committers by date:

Previous
From: tgl@svr1.postgresql.org (Tom Lane)
Date:
Subject: pgsql: Upgrade formrdesc() so that it can correctly initialize the
Next
From: petere@svr1.postgresql.org (Peter Eisentraut)
Date:
Subject: pgsql: Fix problems with certain shells (e.g., FreeBSD, Cygwin) clearing