Does the following zero-column behavior strike anyone else as being a 
little strange? I can take a look at fixing this, I'm just curious if 
there's a consensus that the status quo isn't optimal.

(1)

neilc=# create table zero_col ();
CREATE TABLE
neilc=# select * from zero_col;

--
(0 rows)

-- Why is there a blank line before the "--" that indicates the
-- end of the result set? That seems inconsistent with the way
-- we present a normal empty result set:

neilc=# create table abc (a int);
CREATE TABLE
neilc=# select * from abc;
  a
---
(0 rows)

(2)

neilc=# insert into zero_col default values;
INSERT 17218 1
neilc=# insert into zero_col default values;
INSERT 17219 1
neilc=# select * from zero_col;

--
(2 rows)

-- If the result set contains two rows, ISTM the psql output
-- should emit either two or three blank lines before the "--"
-- that indicates the end of the result set

(3)

neilc=# select * from zero_col order by random();
ERROR:  ORDER/GROUP BY expression not found in targetlist

-- ISTM that ought to work

(4)

neilc=# create view zero_col_view as select * from zero_col;
ERROR:  view must have at least one column

-- ISTM that ought to work as well: if we allow zero-column tables,
-- is there a good reason for disallowing zero-column views?

-Neil


Sat, 22 May 2004 20:28:43 -0400
Neil Conway <neilc@samurai.com>
zero-column table behavior
Neil Conway <neilc@samurai.com> writes:
> Does the following zero-column behavior strike anyone else as being a 
> little strange? I can take a look at fixing this, I'm just curious if 
> there's a consensus that the status quo isn't optimal.

I think that psql's table-pretty-printing logic gets slightly confused
when there are zero columns.  It's never seemed high enough priority
to worry about to me, but if you wanna take a look, go for it.

> neilc=# select * from zero_col order by random();
> ERROR:  ORDER/GROUP BY expression not found in targetlist

> -- ISTM that ought to work

I agree, that's a bug (and a weird one).  I will look at this one.

> neilc=# create view zero_col_view as select * from zero_col;
> ERROR:  view must have at least one column

> -- ISTM that ought to work as well: if we allow zero-column tables,
> -- is there a good reason for disallowing zero-column views?

I'm not sure if that error is just overzealousness or if it is
protecting some implementation assumption.  Try removing the error check
and see if things work or not ...

			regards, tom lane

Sun, 23 May 2004 11:49:55 -0400
Tom Lane <tgl@sss.pgh.pa.us>
Re: zero-column table behavior 
[resending...]

On Sat, 22 May 2004 20:28:43 -0400, Neil Conway <neilc@samurai.com>
wrote:
>-- Why is there a blank line before the "--" that indicates the
>-- end of the result set?

"--" separates the header line from the *start* of the result set.  The
empty line is the header line, containing zero column headers.

>-- If the result set contains two rows, ISTM the psql output
>-- should emit either two or three blank lines before the "--"
>-- that indicates the end of the result set

One empty header line before "--" and then two empty data lines.

Servus
 Manfred

Mon, 24 May 2004 18:00:36 +0200
Manfred Koizar <mkoi-pg@aon.at>
Re: zero-column table behavior