Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1gHTpB-0001Tz-RO for pgsql-admin@arkaria.postgresql.org; Tue, 30 Oct 2018 13:12:49 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1gHTp9-00025K-Vg for pgsql-admin@arkaria.postgresql.org; Tue, 30 Oct 2018 13:12:47 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1gHTp9-00025D-OP for pgsql-admin@lists.postgresql.org; Tue, 30 Oct 2018 13:12:47 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1gHTp7-0006Vx-En for pgsql-admin@lists.postgresql.org; Tue, 30 Oct 2018 13:12:47 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id w9UDChOu013597; Tue, 30 Oct 2018 09:12:43 -0400 From: Tom Lane To: Subodh Kumar cc: pgsql-admin@lists.postgresql.org Subject: Re: creating table without columns In-reply-to: References: Comments: In-reply-to Subodh Kumar message dated "Tue, 30 Oct 2018 17:22:29 +0530" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <13595.1540905163.1@sss.pgh.pa.us> Date: Tue, 30 Oct 2018 09:12:43 -0400 Message-ID: <13596.1540905163@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Subodh Kumar writes: > I have run below query it is created 'test' table without columns > but table row count is 2. > please give me clarity about this, i thought it may give syntax error but > not > either it must have 2 rows data but both are not happened. > with ins_test as (select 1 as srno > union > select 2) > select into test from ins_test; I think you meant to write with ins_test as (select 1 as srno union select 2) select * into test from ins_test; or possibly with ins_test as (select 1 as srno union select 2) select srno into test from ins_test; What you did write has no columns in the SELECT result clause, so the INTO creates a table of no columns --- but you get the expected number of rows. Postgres allows zero-column tables, and zero-column selects, because otherwise there are too many weird corner cases; for instance ALTER TABLE DROP COLUMN would have to reject dropping the last column. The SQL standard has a different opinion about which way is less ugly ... regards, tom lane