Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lxoqa-0002V2-Fa for pgsql-general@arkaria.postgresql.org; Mon, 28 Jun 2021 10:50:38 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1lxoqZ-0007wE-6c for pgsql-general@arkaria.postgresql.org; Mon, 28 Jun 2021 10:50:35 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lxoqY-0007w6-RE for pgsql-general@lists.postgresql.org; Mon, 28 Jun 2021 10:50:34 +0000 Received: from mx3.intershop.de ([195.110.60.3]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lxoqR-0001fW-VZ for pgsql-general@lists.postgresql.org; Mon, 28 Jun 2021 10:50:33 +0000 Received: from mymail.intershop.de (jenex19-1.ad.intershop.net [10.0.87.121]) by mx3.intershop.de (Postfix) with ESMTPS id B52BE100087; Mon, 28 Jun 2021 12:50:23 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=intershop.de; s=2017020601; t=1624877423; bh=42y8gjcEgjlgaZ8M5Ln4MLzOt0RWobrBVZx3UHa6W3c=; h=From:To:CC:Subject:Date:From; b=Gokpdtn7jiih6h5gUYGuXy+OSdpOmIS1KFiqSsG1/gToPGnQGOSY+umRebRc4pvdw gFe6GsL/xEyawmszmMYRZ/sqEzbIKjIF17afLA0Bs3kK0OZtk4305rFfbC2Kpy5ejl kBmWxhArabfNVRN1lEWQ0b7zT6j9XxVJmK3BljMKhCu+U2smIAWmVFor1Dkl4w3Aus IgegxzmPTXdWOFUPmC+cUPcoCKVd/767wITTn9ZySE/RjWZiVJb3ZRlXaXkPFUBwbN zdHZIlEMP6Rpa4U4ClGaAIgq7Wu9zrTOYnDk6Glu0hKobpUsy/VE7cziznypMS2/RR rPasOedDfLi5dhXx0Q47u9YaT3H22QIJjqmBdNLbZb4Mvn54O3dhiheMlBhsaO4+y/ ogh/DHfE3HUSvtUmYbBdkaYAmw/Pvap3x2TijUCYcW0f71MsTNarGIBkeLNuf540V0 XsHjJdWvC9/HhcH33ZWZPR2EmT5YXQBpwkMi4dPWunXhyyuauk9GITX4+xrt+KgA2d fviHaKNFwU/tFAv/EVA2+ed2P8Yq5Cw1hlFutsluGr9OAGzkG4vHmNfPpzXR4Z6b7u zt6bIcJo4dHJjE2pQ3XWWHUn00vr3GPFRGuRoDFamHedkoOPPjuSQRRuKejQs+TF+Z BRmcHOVm01TX8nVhfd+5YNkI= Received: from JENEX19-1.ad.intershop.net (10.0.87.121) by JENEX19-1.ad.intershop.net (10.0.87.121) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.858.12; Mon, 28 Jun 2021 12:50:23 +0200 Received: from JENEX19-1.ad.intershop.net ([fe80::fca3:adda:19c9:b9ff]) by JENEX19-1.ad.intershop.net ([fe80::fca3:adda:19c9:b9ff%13]) with mapi id 15.02.0858.012; Mon, 28 Jun 2021 12:50:23 +0200 From: Marc Mamin To: Tom Lane CC: Joe Conway , pgsql-general Subject: schema prefixes in default values (was RE: removing "serial" from table definitions). Thread-Topic: schema prefixes in default values (was RE: removing "serial" from table definitions). Thread-Index: AddsC2TmjwjzyuwOQyqvb10KDfRS8A== Date: Mon, 28 Jun 2021 10:50:23 +0000 Message-ID: <0fd15744721c4d64ae0373429e687e80@intershop.de> Accept-Language: de-DE, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [195.110.60.24] x-tm-snts-smtp: 4D734698FEADEBD04D775921599B81DB08BB201ABDB774198FDCFF6D482321D62000:8 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-Virus-Scanned: clamav-milter 0.103.2 at mx3.intershop.de X-Virus-Status: Clean List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Marc Mamin writes: > > Yes, I undersand that serial is just a hint at table creation time, but= is there a place in catalog where we can see if the table was created usin= g 'serial' ? >=20 > No. Where the docs say "these are equivalent", they mean that very liter= ally. >=20 > > The difference we see between the source and target database is that a = schema prefix is displayed with the sequence on one side, and not on the ot= her.. >=20 > This likely has to do with the search_path settings being different in th= e sessions inspecting the two DBs. I do not think it is related to serial-= ness at all, it's just the normal behavior of regclass_out for the OID cons= tant that's the argument of nextval(). >=20 > regards, tom lane Hello, it seems that our problem had nothing to do with serial, but with the way s= chema prefixes are handled in column default values. pg_attrdef.adsrc: filled when the defaut value is defined. contains a schema prefix only wh= en required at this creation time. Is constant afterwards. pg_get_expr(adbin, adrelid) the returned expession is dynamic: the schema prefix is returned only w= hen the sequence schema is not part of the current search_path. =20 This behavior is understandable but it make it uncomfortable to compare tab= le definitions between different sources. Moreover a pg_dump->restore might in some cases modify the value of pg_attr= def.adsrc best regards, Marc Mamin =20 as test: =20 set search_path=3D'admin'; create table foo1 (n1 serial); set search_path=3D'oms'; create table admin.foo2 (n2 serial); select a.attname, ad.adsrc, pg_get_expr(adbin, adrelid) FROM pg_attribute a JOIN pg_attrdef ad ON (a.attnum=3Dad.adnum and a.attrelid=3Dad.adreli= d) WHERE a.attrelid IN (Select oid from pg_class where relname in('foo1',= 'foo2')); n1 nextval('foo1_n1_seq'::regclass) nextval('admin.foo1_n1_= seq'::regclass) n2 nextval('admin.foo2_n2_seq'::regclass) nextval('admin.foo2_n2= _seq'::regclass) =20 =20 set search_path=3D'admin'; select a.attname, ad.adsrc, pg_get_expr(adbin, adrelid) FROM pg_attribute a JOIN pg_attrdef ad ON (a.attnum=3Dad.adnum and a.attrelid=3Dad.adreli= d) WHERE a.attrelid IN (Select oid from pg_class where relname in('foo1',= 'foo2')); =20 n1 nextval('foo1_n1_seq'::regclass) nextval('foo1_n1_seq'::= regclass) n2 nextval('admin.foo2_n2_seq'::regclass) nextval('foo2_n2_seq'::= regclass)