Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1a48dC-0003if-0e for pgsql-bugs@arkaria.postgresql.org; Wed, 02 Dec 2015 14:43:42 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84) (envelope-from ) id 1a48dB-00039j-De for pgsql-bugs@arkaria.postgresql.org; Wed, 02 Dec 2015 14:43:41 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84) (envelope-from ) id 1a48cY-0002BP-UW for pgsql-bugs@postgresql.org; Wed, 02 Dec 2015 14:43:03 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84) (envelope-from ) id 1a48cR-0002Y1-RK for pgsql-bugs@postgresql.org; Wed, 02 Dec 2015 14:43:01 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id tB2EgrnK014693; Wed, 2 Dec 2015 09:42:53 -0500 From: Tom Lane To: amsl.sm@gmail.com cc: pgsql-bugs@postgresql.org Subject: Re: BUG #13789: pg_admin produces table definitiona instead of a view In-reply-to: <20151201213353.2771.86443@wrigleys.postgresql.org> References: <20151201213353.2771.86443@wrigleys.postgresql.org> Comments: In-reply-to amsl.sm@gmail.com message dated "Tue, 01 Dec 2015 21:33:53 +0000" Date: Wed, 02 Dec 2015 09:42:53 -0500 Message-ID: <14692.1449067373@sss.pgh.pa.us> X-Pg-Spam-Score: -1.9 (-) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org amsl.sm@gmail.com writes: > I have a view defined with the following sql statement: > CREATE OR REPLACE VIEW my_view AS > ( > select s.id as start_id > from start s > group by s.id > order by start_date desc > ); Note that this view definition isn't even legal unless start.id is a primary key, otherwise you get ERROR: column "s.start_date" must appear in the GROUP BY clause or be used in an aggregate function > When pg_admin exports this view it outputs it as as table not view: > CREATE TABLE my_view ( > start_id integer > ); This is not a bug; if you look further down you'll find something like CREATE RULE "_RETURN" AS ON SELECT TO my_view DO INSTEAD SELECT s.id AS start_id FROM start s GROUP BY s.id ORDER BY s.start_date DESC; which converts the table to a view (admittedly in a not-very-obvious way). Because of the dependency on start's primary key, the view can't simply be defined up at the top of the dump. This is how pg_dump chooses to break the circularity. regards, tom lane -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs