Received: from magus.postgresql.org ([87.238.57.229]) by malur.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1TYj5s-0007x4-Cb for pgsql-bugs@postgresql.org; Wed, 14 Nov 2012 19:57:52 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1TYj5q-0002ey-IP for pgsql-bugs@postgresql.org; Wed, 14 Nov 2012 19:57:52 +0000 Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.5/8.14.5) with ESMTP id qAEJvhM0024459; Wed, 14 Nov 2012 14:57:44 -0500 (EST) From: Tom Lane To: zoulx1982@163.com cc: pgsql-bugs@postgresql.org Subject: Re: BUG #7658: the result of pg_get_viewdef can NOT execute directly In-reply-to: References: Comments: In-reply-to zoulx1982@163.com message dated "Wed, 14 Nov 2012 07:26:08 +0000" Date: Wed, 14 Nov 2012 14:57:43 -0500 Message-ID: <24458.1352923063@sss.pgh.pa.us> X-Pg-Spam-Score: -2.1 (--) X-Archive-Number: 201211/71 X-Sequence-Number: 34629 zoulx1982@163.com writes: > postgres=# create table t1(a int, b int); > CREATE TABLE > postgres=# create table t2(c int, d int); > CREATE TABLE > postgres=# create view v as select * from t1 t where a in (select a from t2 > t); > CREATE VIEW > postgres=# select pg_get_viewdef('v'); > pg_get_viewdef > ------------------------------------------------------------------ > SELECT t.a, t.b FROM t1 t WHERE (t.a IN (SELECT t.a FROM t2 t)); > (1 row) This is fixed in HEAD as a consequence of commit http://git.postgresql.org/gitweb/?p=postgresql.git&a=commitdiff&h=11e131854f8231a21613f834c40fe9d046926387 --- I get SELECT t.a, t.b FROM t1 t WHERE (t.a IN (SELECT t.a FROM t2 t_1)); which is a valid representation of the view. At the time we felt it was not worth the risk of back-patching. I'm still inclined to think that, since this example doesn't seem to correspond to any real-world use case (the original query is surely a mistake no?). regards, tom lane