I was bemused to notice that pg_dump is currently unable to dump the
regression database.  The domain regression test leaves an empty table
(one with zero columns), which causes pg_dump to produce

--
-- TOC entry 172 (OID 675837)
-- Name: domnotnull; Type: TABLE; Schema: public; Owner: postgres
--

CREATE TABLE domnotnull (
);


This is rejected on restore:

ERROR:  DefineRelation: please inherit from a relation or define an attribute

I believe that the table would be correctly restored if we simply
removed that error check in DefineRelation.  On the other hand, for
ordinary hand-entered CREATE TABLE commands it seems like a useful
error check.

Should we remove this error check, thereby effectively making
zero-column tables first-class citizens?  If not, what shall we say to
people who complain that their dump is broken?

			regards, tom lane

Thu, 12 Dec 2002 16:08:06 -0500
Tom Lane <tgl@sss.pgh.pa.us>
Creating a zero-column table
Tom Lane kirjutas R, 13.12.2002 kell 02:08:
> I was bemused to notice that pg_dump is currently unable to dump the
> regression database.  The domain regression test leaves an empty table
> (one with zero columns), which causes pg_dump to produce
> 
> --
> -- TOC entry 172 (OID 675837)
> -- Name: domnotnull; Type: TABLE; Schema: public; Owner: postgres
> --
> 
> CREATE TABLE domnotnull (
> );
> 
> 
> This is rejected on restore:
> 
> ERROR:  DefineRelation: please inherit from a relation or define an attribute
> 
> I believe that the table would be correctly restored if we simply
> removed that error check in DefineRelation.  On the other hand, for
> ordinary hand-entered CREATE TABLE commands it seems like a useful
> error check.
> 
> Should we remove this error check, thereby effectively making
> zero-column tables first-class citizens? 

I would vote for removing the check. I see no reason why one should not
be able to define a zero-column table. While we cant currently do
anything useful (except select oid :) with it now, it does not mean that
it would not serve as a valid base table for inheritance hierarchies in
future. 

I'm probably going to propose an implicit zero-column base table for all
user defined tables (say any_table) so that one can get a list of all
tuple ids in all tables by doing a simple 
"select tableoid,oid from any_table". This will of course not be very
useful for tables with no oids and where there is no index on oid.


-- 
Hannu Krosing <hannu@tm.ee>

13 Dec 2002 02:21:00 +0500
Hannu Krosing <hannu@tm.ee>
Re: Creating a zero-column table
At 04:08 PM 12/12/2002 -0500, Tom Lane wrote:
>Should we remove this error check, thereby effectively making
>zero-column tables first-class citizens?

It's a bit daft, but I suspect it's the way to go. There has to be a 
non-zero chance that a future version of pg_dump may want to add attributes 
to tables in a piecemeal fashion (cyclic FKs? Yuk).



----------------------------------------------------------------
Philip Warner                    |     __---_____
Albatross Consulting Pty. Ltd.   |----/       -  \
(A.B.N. 75 008 659 498)          |          /(@)   ______---_
Tel: (+61) 0500 83 82 81         |                 _________  \
Fax: (+61) 03 5330 3172          |                 ___________ |
Http://www.rhyme.com.au          |                /           \|
                                  |    --________--
PGP key available upon request,  |  /
and from pgp5.ai.mit.edu:11371   |/


Fri, 13 Dec 2002 14:10:00 +1100
Philip Warner <pjw@rhyme.com.au>
Re: Creating a zero-column table
Tom Lane writes:

> Should we remove this error check, thereby effectively making
> zero-column tables first-class citizens?

Yes.

-- 
Peter Eisentraut   peter_e@gmx.net


Sat, 14 Dec 2002 01:27:29 +0100 (CET)
Peter Eisentraut <peter_e@gmx.net>
Re: Creating a zero-column table
On Fri, 2002-12-13 at 19:27, Peter Eisentraut wrote:
> Tom Lane writes:
> 
> > Should we remove this error check, thereby effectively making
> > zero-column tables first-class citizens?
> 
> Yes.
> 

I've never been one for actively going against the sql standards (which
this case would seem to do) so if it is done lets make sure we add
documentation to point out that we aren't compliant on this issue.

Robert Treat



16 Dec 2002 09:37:12 -0500
Robert Treat <xzilla@users.sourceforge.net>
Re: Creating a zero-column table
Robert Treat writes:

> I've never been one for actively going against the sql standards (which
> this case would seem to do) so if it is done lets make sure we add
> documentation to point out that we aren't compliant on this issue.

This could be a reasonable place to hook in the "SQL flagger"
(non-conforming syntax checker), which a conforming SQL implementation
needs to have anyhow.

-- 
Peter Eisentraut   peter_e@gmx.net


Tue, 17 Dec 2002 00:45:30 +0100 (CET)
Peter Eisentraut <peter_e@gmx.net>
Re: Creating a zero-column table