Column COMMENTs in CREATE TABLE?

From: Marko Tiikkaja <marko(at)joh(dot)to>
To: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Column COMMENTs in CREATE TABLE?
Date: 2016-07-02 16:55:06
Message-ID: a0a02aca-9f0c-4754-8d3c-fad21218b748@joh.to
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi,

Currently we have CREATE TABLE statements in a git repository that look
roughly like this:

CREATE TABLE foo(
-- the first field
f1 int NOT NULL,
-- the second field
f2 int NOT NULL,
...
);

But the problem is that those comments don't obviously make it all the
way to the database, so e.g. \d+ tblname won't show you that precious
information. If you want them to make it all the way to the database,
you'd have to add COMMENT ON statements *after* the CREATE TABLE, which
means that either column comments have to be maintained twice, or the
CREATE TABLE statement won't have them, so you have to go back and forth
in your text editor to see the comments. Both solutions are suboptimal.

What I would prefer is something like this:

CREATE TABLE foo(
f1 int NOT NULL COMMENT
'the first field',
f2 int NOT NULL COMMENT
'the second field',
...
);

which would ensure the comments are both next to the field definition
they're documenting and that they make it all the way to the database.
I looked into the biggest products, and MySQL supports this syntax. I
couldn't find any similar syntax in any other product.

The downside is that this would require us to make COMMENT a fully
reserved keyword, which would quite likely break at least one
application out in the wild. Another option would be to make the syntax
something like [ COLUMN COMMENT '...' ], but that's not exactly a
beautiful solution either.

I still think this would be a really valuable feature if we can come up
with a decent syntax for it. Does anyone have any ideas? Or does
anybody want to shoot this proposal down right off the bat?

.m

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message David G. Johnston 2016-07-02 17:06:49 Re: Column COMMENTs in CREATE TABLE?
Previous Message CharSyam 2016-07-02 16:17:40 Typo Patch