pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Ondřej Bouda <bouda@edookit.com>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: pgsql-bugs@postgresql.org
Subject: Re: BUG #12106: pg_dump does not resolve circular dependency
Date: Sun, 30 Nov 2014 22:55:28 +0100
Message-ID: <op.xp5q6qlrxzlyat@gracie> (raw)
In-Reply-To: <9283.1417365074@sss.pgh.pa.us>
References: <20141130153705.5731.4615@wrigleys.postgresql.org>
	<9283.1417365074@sss.pgh.pa.us>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-bugs>

On Sun, 30 Nov 2014 17:31:14 +0100, Tom Lane <tgl@sss.pgh.pa.us> wrote:

> bouda@edookit.com writes:
>> A function may reference itself via default values of some of its  
>> arguments.
>> It is rather tricky to create one, but it is possible:
>
> Unless you can demonstrate a credible use-case for this, I don't think
> it's worth adding complexity to pg_dump for.
>
> 			regards, tom lane

I admin I have no real world use case for the mentioned situation,  
although I think it should be documented as a pg_dump limitation, at least.

I suggest adding a new section called Limitations on the pg_dump  
documentation page, which would list all currently known limitations.  
Looking at the object attributes and their possible dependencies on other  
objects, I found these cases not handled by pg_dump (i.e., resulting in an  
erroneous dump):


1) Function argument default referring to other objects, causing a  
circular dependency (even referring to the function itself) - this is the  
originally reported one.


2) Domain default calling a function - which therefore must return that  
domain type. E.g.,

CREATE DOMAIN dom AS INT;

CREATE FUNCTION get_default_dom() RETURNS dom
AS $$ SELECT 42::dom; $$ LANGUAGE sql;

ALTER DOMAIN dom SET DEFAULT get_default_dom();

For these, pg_dump emits CREATE FUNCTION first, then CREATE DOMAIN. The  
CREATE FUNCTION fails as the domain has not been created yet. Worse, it  
even emits no warnings - the pg_dump output looks entirely clear.


3) View referring to itself (or other view which in turn refers to the  
first one...). E.g.,

CREATE VIEW selfview (o) AS SELECT NULL::regclass;
CREATE OR REPLACE VIEW selfview (o) AS SELECT 'selfview'::regclass;

Here, pg_dump emits CREATE VIEW selfview AS SELECT 'selfview'::regclass AS  
o; - which fails (ERROR:  relation "selfview" does not exist). Similarly  
to 2), no warnings are given, i.e., one finds out only when actually  
trying to restore the dump.


Generally, any object may be referenced by expressions like  
'seq'::regclass within:
- table column defaults
- domain defaults
- function argument defaults
- view definitions
Any of them may result in a circular dependency which pg_dump is unable to  
cut.


I am aware of the fact all these cases might look silly (except for case  
2), maybe), but still - mentioning them in the docs might help.

In addition, it would be nice if pg_dump could at least detect the  
circular dependency in cases 2) and 3) and issue a warning, similarly to  
case 1).


Ondřej Bouda

P.S. Sorry for not coming out with a patch right away - I am a newbie  
here...


-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs



view thread (6+ messages)  latest in thread

Message-ID: <op.xp5q6qlrxzlyat@gracie>
Permalink:  ../op.xp5q6qlrxzlyat@gracie/
Also on:    postgresql.org/message-id/op.xp5q6qlrxzlyat@gracie

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-bugs@postgresql.org
  Cc: bouda@edookit.com, tgl@sss.pgh.pa.us
  Subject: Re: BUG #12106: pg_dump does not resolve circular dependency
  In-Reply-To: <op.xp5q6qlrxzlyat@gracie>
  References: <20141130153705.5731.4615@wrigleys.postgresql.org> <9283.1417365074@sss.pgh.pa.us> <op.xp5q6qlrxzlyat@gracie>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox