Re: Allowing empty target list in SELECT (1b4f7f93b4693858cb983af3cd557f6097dab67b)

Lists: pgsql-hackers
From: Amit Langote <amitlangote09(at)gmail(dot)com>
To: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Allowing empty target list in SELECT (1b4f7f93b4693858cb983af3cd557f6097dab67b)
Date: 2014-05-02 03:57:04
Message-ID: CA+HiwqHJcqOjQHEdKpAv8B-pnwCGijLZzS1uLGWk0qaAZgmzTw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Hi,

I
​s the following behavior perceived fix-worthy?

-- note the
​'​
​1's
in the output
​s

​po​
stgres=# CREATE TABLE test AS SELECT;
SELECT 1

postgres=# insert into test select;
INSERT 0 1​

​My guess why ​this happens is because changes made in the commit in
$SUBJECT only pertain to fixing syntax errors and nothing else.

--
Amit


From: Amit Langote <amitlangote09(at)gmail(dot)com>
To: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Allowing empty target list in SELECT (1b4f7f93b4693858cb983af3cd557f6097dab67b)
Date: 2014-05-02 04:30:25
Message-ID: CA+HiwqEgsaArsh6R40e+-pwS==276MbFSiRYZMEEgpv+24QL+Q@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Fri, May 2, 2014 at 12:57 PM, Amit Langote <amitlangote09(at)gmail(dot)com> wrote:
> I
> s the following behavior perceived fix-worthy?
>
>
> -- note the
> '
> 1's
> in the output
> s
>
> po
> stgres=# CREATE TABLE test AS SELECT;
> SELECT 1
>
> postgres=# insert into test select;
> INSERT 0 1
>

Or maybe, it just means 1 'null' row/record and not no row at all?

--
Amit


From: Rajeev rastogi <rajeev(dot)rastogi(at)huawei(dot)com>
To: Amit Langote <amitlangote09(at)gmail(dot)com>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Allowing empty target list in SELECT (1b4f7f93b4693858cb983af3cd557f6097dab67b)
Date: 2014-05-02 06:03:50
Message-ID: BF2827DCCE55594C8D7A8F7FFD3AB7713DDE577B@SZXEML508-MBX.china.huawei.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On 02 May 2014 10:00, Amit Longote Wrote:

> > I
> > s the following behavior perceived fix-worthy?
> >
> >
> > -- note the
> > '
> > 1's
> > in the output
> > s
> >
> > po
> > stgres=# CREATE TABLE test AS SELECT;
> > SELECT 1
> >
> > postgres=# insert into test select;
> > INSERT 0 1
> >
>
> Or maybe, it just means 1 'null' row/record and not no row at all?

It just creates an item pointer and corresponding to that heap tuple header (without data or bitmask for NULL) gets stored as part of this insertion.
So though it does not insert anything (not even NULL) but still it reserve one row position.
So while SELECT, it will not display anything but it will show actual number of rows.

Even below syntax is also allowed:

CREATE TABLE no_column_table();

IMO, this might be useful for dynamic use of table (later column might be added using 'ALTER') or to use as abstract ancestor in class hierarchy.

Thanks and Regards,
Kumar Rajeev Rastogi


From: David Rowley <dgrowleyml(at)gmail(dot)com>
To: Amit Langote <amitlangote09(at)gmail(dot)com>
Cc: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Allowing empty target list in SELECT (1b4f7f93b4693858cb983af3cd557f6097dab67b)
Date: 2014-05-02 07:14:12
Message-ID: CAApHDvpVUCLBiqOF+eJXwjx0Zeccr7KpYqfW0Ti=cqCTGCP1XA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Fri, May 2, 2014 at 3:57 PM, Amit Langote <amitlangote09(at)gmail(dot)com>wrote:

>
> Hi,
>
> I
> ​s the following behavior perceived fix-worthy?
>
>
> -- note the
> ​'​
> ​1's
> in the output
> ​s
> ​
>
> ​po​
> stgres=# CREATE TABLE test AS SELECT;
> SELECT 1
>
> postgres=# insert into test select;
> INSERT 0 1​
>
> ​My guess why ​this happens is because changes made in the commit in
> $SUBJECT only pertain to fixing syntax errors and nothing else.
>
>
Are you proposing that this does not insert a 0 column row?

I don't find the current behaviour wrong. If it didn't insert the row then
the query in the following would return 0 rows.

begin work;
create table nocols ();
insert into nocols select;
insert into nocols select;

create table test (value int);
insert into test values(1);

select * from nocols cross join test; -- give 2 rows with the value 1
rollback;

Why should the above results be any different than if I created the nocols
table with a column then dropped it?
Certainly removing all of the records on the drop of the last column would
be wrong.

Regards

David Rowley

--
> Amit
>


From: Albe Laurenz <laurenz(dot)albe(at)wien(dot)gv(dot)at>
To: "Amit Langote *EXTERN*" <amitlangote09(at)gmail(dot)com>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Allowing empty target list in SELECT (1b4f7f93b4693858cb983af3cd557f6097dab67b)
Date: 2014-05-02 07:16:07
Message-ID: A737B7A37273E048B164557ADEF4A58B17CF567A@ntex2010i.host.magwien.gv.at
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Amit Langote wrote:
>> Is the following behavior perceived fix-worthy?
>>
>>
>> -- note the '1's in the outputs
>>
>> postgres=# CREATE TABLE test AS SELECT;
>> SELECT 1
>>
>> postgres=# insert into test select;
>> INSERT 0 1
>
> Or maybe, it just means 1 'null' row/record and not no row at all?

Right, I'd say you end up with a table with two 0-tuples.

Maybe odd, but it shouldn't be a problem.

Yours,
Laurenz Albe


From: Amit Langote <amitlangote09(at)gmail(dot)com>
To: David Rowley <dgrowleyml(at)gmail(dot)com>
Cc: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Allowing empty target list in SELECT (1b4f7f93b4693858cb983af3cd557f6097dab67b)
Date: 2014-05-02 07:30:54
Message-ID: CA+HiwqFUmF0jBarfPidNgogg=NgoZvc+SwAQwypmvMXzLCtJgA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Fri, May 2, 2014 at 4:14 PM, David Rowley <dgrowleyml(at)gmail(dot)com> wrote:
>
>
> Why should the above results be any different than if I created the nocols
> table with a column then dropped it?
> Certainly removing all of the records on the drop of the last column would
> be wrong.
>

I see, dropping the only column in a table does exhibit a similar behavior.

--
Amit