pg.ddx.io pgsql-admin@postgresql.org mailing list archive
help / color / mirror / Atom feedcreating table without columns
5+ messages / 4 participants
[nested] [flat]
* creating table without columns
@ 2018-10-30 11:52 Subodh Kumar <subodh.kumar@epps-erp.com>
0 siblings, 3 replies; 5+ messages in thread
From: Subodh Kumar @ 2018-10-30 11:52 UTC (permalink / raw)
To: pgsql-admin@lists.postgresql.org
Hello Everyone,
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;
select * from test;
thank you.
Regards:
Subodh Kumar
Postgresql Developer
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: creating table without columns
@ 2018-10-30 12:53 Greg Spiegelberg <gspiegelberg@gmail.com>
parent: Subodh Kumar <subodh.kumar@epps-erp.com>
2 siblings, 0 replies; 5+ messages in thread
From: Greg Spiegelberg @ 2018-10-30 12:53 UTC (permalink / raw)
To: Subodh Kumar <subodh.kumar@epps-erp.com>; +Cc: pgsql-admin@lists.postgresql.org
On Tue, Oct 30, 2018, 6:45 AM Subodh Kumar <subodh.kumar@epps-erp.com>
wrote:
> Hello Everyone,
> 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;
>
> select * from test;
>
See VALUES.
:)
-Greg
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: creating table without columns
@ 2018-10-30 13:00 Christoph Berg <myon@debian.org>
parent: Subodh Kumar <subodh.kumar@epps-erp.com>
2 siblings, 0 replies; 5+ messages in thread
From: Christoph Berg @ 2018-10-30 13:00 UTC (permalink / raw)
To: Subodh Kumar <subodh.kumar@epps-erp.com>; +Cc: pgsql-admin@lists.postgresql.org
Re: Subodh Kumar 2018-10-30 <CA+KMk93CwQBP8SMeu_wcGdrj_ZTLVQVDpL-zbCd2vdy0hfWYrw@mail.gmail.com>
> Hello Everyone,
> 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;
You missed "srno":
with ins_test as (select 1 as srno
union
select 2)
select srno into test from ins_test;
^^^^
You can also "select from tbl;" -- omitting the target list.
The easier way to get a table without columns, but with rows is this:
create table test();
insert into test default values;
insert into test default values;
Christoph
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: creating table without columns
@ 2018-10-30 13:12 Tom Lane <tgl@sss.pgh.pa.us>
parent: Subodh Kumar <subodh.kumar@epps-erp.com>
2 siblings, 1 reply; 5+ messages in thread
From: Tom Lane @ 2018-10-30 13:12 UTC (permalink / raw)
To: Subodh Kumar <subodh.kumar@epps-erp.com>; +Cc: pgsql-admin@lists.postgresql.org
Subodh Kumar <subodh.kumar@epps-erp.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
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: creating table without columns
@ 2018-10-30 13:15 Subodh Kumar <subodh.kumar@epps-erp.com>
parent: Tom Lane <tgl@sss.pgh.pa.us>
0 siblings, 0 replies; 5+ messages in thread
From: Subodh Kumar @ 2018-10-30 13:15 UTC (permalink / raw)
To: tgl@sss.pgh.pa.us; +Cc: pgsql-admin@lists.postgresql.org
Thanks for quick response.
On Tue, Oct 30, 2018 at 6:42 PM Tom Lane <tgl@sss.pgh.pa.us> wrote:
> Subodh Kumar <subodh.kumar@epps-erp.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
>
^ permalink raw reply [nested|flat] 5+ messages in thread
end of thread, other threads:[~2018-10-30 13:15 UTC | newest]
Thread overview: 5+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2018-10-30 11:52 creating table without columns Subodh Kumar <subodh.kumar@epps-erp.com>
2018-10-30 12:53 ` Greg Spiegelberg <gspiegelberg@gmail.com>
2018-10-30 13:00 ` Christoph Berg <myon@debian.org>
2018-10-30 13:12 ` Tom Lane <tgl@sss.pgh.pa.us>
2018-10-30 13:15 ` Subodh Kumar <subodh.kumar@epps-erp.com>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox