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 1kk83Y-00020T-58 for pgsql-bugs@arkaria.postgresql.org; Tue, 01 Dec 2020 15:59:08 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1kk83W-00078K-AL for pgsql-bugs@arkaria.postgresql.org; Tue, 01 Dec 2020 15:59:06 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kk83W-00078D-3k for pgsql-bugs@lists.postgresql.org; Tue, 01 Dec 2020 15:59:06 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kk83T-0008Av-TM for pgsql-bugs@lists.postgresql.org; Tue, 01 Dec 2020 15:59:05 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 0B1FwudY1396480; Tue, 1 Dec 2020 10:58:57 -0500 From: Tom Lane To: marc@guidance.nl cc: pgsql-bugs@lists.postgresql.org Subject: Re: BUG #16758: create temporary table with the same name loses defaults, indexes In-reply-to: <16758-840e84a6cfab276d@postgresql.org> References: <16758-840e84a6cfab276d@postgresql.org> Comments: In-reply-to PG Bug reporting form message dated "Tue, 01 Dec 2020 14:09:49 +0000" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <1396478.1606838336.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Tue, 01 Dec 2020 10:58:56 -0500 Message-ID: <1396479.1606838336@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk PG Bug reporting form writes: > In 12.5 (and later), in a clean, empty database (in this case the defaul= t > 12.5 docker image), when I execute the following lines: > create table xx (name text NOT NULL default '', PRIMARY KEY(name)); > create temporary table xx > (like xx including DEFAULTS including CONSTRAINTS including INDE= XES); Hm, interesting. Without having dug into the code, I bet what is happening is that after creating pg_temp.xx, the LIKE code is looking to see "what indexes exist on table xx?", to which the answer is "none" because it finds pg_temp.xx. We need to nail down the schema in which xx is sought for that step. As a workaround, you could nail down the schema manually: create temporary table xx (like public.xx including DEFAULTS including CONSTRAINTS including INDEXES); The ordering of these operations got rearranged recently to fix some other bugs, so it doesn't surprise me if it used to work differently. regards, tom lane