Received: from maia.hub.org (maia-3.hub.org [200.46.204.243]) by mail.postgresql.org (Postfix) with ESMTP id 1B262B888AF for ; Fri, 3 Jun 2011 13:47:15 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.243]) (amavisd-maia, port 10024) with ESMTP id 65028-01-3 for ; Fri, 3 Jun 2011 16:47:07 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mail-px0-f174.google.com (mail-px0-f174.google.com [209.85.212.174]) by mail.postgresql.org (Postfix) with ESMTP id 6010AB62868 for ; Fri, 3 Jun 2011 13:47:02 -0300 (ADT) Received: by pxi15 with SMTP id 15so1414102pxi.33 for ; Fri, 03 Jun 2011 09:47:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:in-reply-to:references:date :message-id:subject:from:to:cc:content-type :content-transfer-encoding; bh=tT8E+GUsubfdFYLPU4Rm2IgOLTQyRm1rTPDkuPqUSXE=; b=SuDImkM6n5k/BxF6+spvGa73X8VaRVeRMovVAQToyG5fM7nF08pIAAKoLTUs7WjNJh YDhLox0rUK+RO7LpKpfbdECakk/MNtDnGF233XK7vNXm73P3oHS850EnRPObQJoB1qZo +YQVYyGI0LOfwSeIVFnH+NPO08acb0/lf9Ulg= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type:content-transfer-encoding; b=tlilYIGrJFc21oYzje05pKrWFqJgGKmWMHVuMuo0vwN5eRSHu+y/r1Iuahq7J6jl36 jBTbI3cvk35DkYblMIdHoe1XTTLSpHdq9UAh6raRHTJQe29PtZMzrElYvG+pPyLgH/uf jvBfmkJavU5s8fvSQ5+FlTMKxTmeasz5KHhnM= MIME-Version: 1.0 Received: by 10.68.34.72 with SMTP id x8mr843598pbi.312.1307119621555; Fri, 03 Jun 2011 09:47:01 -0700 (PDT) Received: by 10.68.56.70 with HTTP; Fri, 3 Jun 2011 09:47:01 -0700 (PDT) In-Reply-To: <27042.1307113140@sss.pgh.pa.us> References: <201106031238.p53CcA8P075374@wwwmaster.postgresql.org> <27042.1307113140@sss.pgh.pa.us> Date: Fri, 3 Jun 2011 12:47:01 -0400 Message-ID: Subject: Re: BUG #6050: Dump and restore of view after a schema change: can't restore the view From: Robert Haas To: Tom Lane Cc: Daniel Cristian Cruz , pgsql-bugs@postgresql.org Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.898 tagged_above=-5 required=5 tests=BAYES_00=-1.9, FREEMAIL_FROM=0.001, RFC_ABUSE_POST=0.001 X-Spam-Level: X-Archive-Number: 201106/35 X-Sequence-Number: 30414 On Fri, Jun 3, 2011 at 10:59 AM, Tom Lane wrote: > "Daniel Cristian Cruz" writes: >> CREATE TABLE a ( >> =A0id_a serial primary key, >> =A0v text >> ); >> CREATE TABLE b ( >> =A0id_b serial primary key, >> =A0id_a integer REFERENCES a (id_a), >> =A0v text >> ); >> CREATE TABLE c ( >> =A0id_c serial primary key, >> =A0id_b integer references b (id_b), >> =A0v text >> ); > >> CREATE VIEW cba AS >> =A0SELECT c.v AS vc, b.v AS vb, a.v AS va >> =A0FROM c >> =A0JOIN b USING (id_b) >> =A0JOIN a USING (id_a); > >> ALTER TABLE c ADD id_a integer; > >> [ view definition now fails due to multiple "id_a" columns ] > > I'm inclined to write this off as "so don't do that". =A0There's nothing > that pg_dump can do to make this work: it has to use the USING syntax > for the join, and that doesn't offer any way to qualify the column name > on just one side. =A0The only possible fix would be to try to make ALTER > TABLE reject the addition of the conflicting column name to "c" in the > first place. =A0That doesn't seem very practical; it would require ALTER > TABLE to do a tremendous amount of analysis, and exclusively lock all > the dependent views, and then lock all the other tables used in the > views, and so on. > > Personally my advice is to avoid USING: it wasn't one of the SQL > committee's better ideas. I don't understand why we can't just translate the USING into some equivalent construct that doesn't involve USING. I proposed that a while ago and you shot it down, but I didn't find the reasoning very compelling. --=20 Robert Haas EnterpriseDB: http://www.enterprisedb.com The Enterprise PostgreSQL Company