Re: creating table without columns

From: Subodh Kumar <subodh(dot)kumar(at)epps-erp(dot)com>
To: tgl(at)sss(dot)pgh(dot)pa(dot)us
Cc: pgsql-admin(at)lists(dot)postgresql(dot)org
Subject: Re: creating table without columns
Date: 2018-10-30 13:15:49
Message-ID: CA+KMk90h8zqV9xd2pYOirxW1qLk0m9sbs7sTbhjVEUNeab0RHg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-admin

Thanks for quick response.

On Tue, Oct 30, 2018 at 6:42 PM Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:

> Subodh Kumar <subodh(dot)kumar(at)epps-erp(dot)com> 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
>

In response to

Browse pgsql-admin by date

  From Date Subject
Next Message Laurenz Albe 2018-10-30 13:18:12 Re: Getting fancy errors when accessing information_schema on 10.5
Previous Message Tom Lane 2018-10-30 13:12:43 Re: creating table without columns