Received: from maia.hub.org (maia-2.hub.org [200.46.204.251]) by mail.postgresql.org (Postfix) with ESMTP id 3D312635050 for ; Thu, 8 Jul 2010 18:15:05 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.251]) (amavisd-maia, port 10024) with ESMTP id 26562-02-8 for ; Thu, 8 Jul 2010 21:14:56 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by mail.postgresql.org (Postfix) with ESMTP id 85FFC634AC4 for ; Thu, 8 Jul 2010 18:13:53 -0300 (ADT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.2/8.14.2) with ESMTP id o68LDmX4011225; Thu, 8 Jul 2010 17:13:48 -0400 (EDT) To: Richard Huxton cc: arnaud.listes@codata.eu, pgsql-odbc@postgresql.org Subject: Re: [GENERAL] 'default nextval()' loses schema-qualification in dump ? In-reply-to: <4C342FA5.3050105@archonet.com> References: <4C32FF36.8030604@codata.eu> <27289.1278426134@sss.pgh.pa.us> <4C334593.7030300@codata.eu> <28564.1278429458@sss.pgh.pa.us> <4C342318.7040502@codata.eu> <4C342FA5.3050105@archonet.com> Comments: In-reply-to Richard Huxton message dated "Wed, 07 Jul 2010 08:41:25 +0100" Date: Thu, 08 Jul 2010 17:13:47 -0400 Message-ID: <11224.1278623627@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.91 tagged_above=-10 required=5 tests=BAYES_00=-1.9, T_RP_MATCHES_RCVD=-0.01 X-Spam-Level: X-Archive-Number: 201007/13 X-Sequence-Number: 10356 Richard Huxton writes: > If you start psql with the "-E" option and do \d myschema.mytable you'll > be able to see how it gets the sequence-name. About half-way down the > list of queries it runs you'll see a reference to pg_get_expr(...) - > that turns an internal representation into a useful usable one. > I don't know why psqlODBC isn't using that. The function has been around > for a while. Hmm - it's present back in 7.4 although it's not used in \d > - that does reference adsrc directly. > Just grabbed the source download for the latest version and it still > looks like it's using adsrc (I just searched for that and pg_get_expr). > There should probably be a change in info.c around line 2091 to add a > check for a recent version of PG (8+) and use pg_get_expr. Check on the > odbc mailing-list - there may be an updated version available for you to > test. Seems like psqlODBC shouldn't be fetching the default value at all, or at least should not be trying to turn around and pass it back to the server (if that's what's really happening). It would be far easier and safer to omit the target column from the INSERT statement, or write DEFAULT if that's inconvenient. Even if you collect the correct expression by using pg_get_expr(), what if someone ALTERs the default while you're connected? I'm suspicious that this coding technique is a hangover from back when you couldn't write "insert into foo values(default, default)", which is to say PG 7.2 or before. regards, tom lane