Thread: Table Comments

Table Comments

From
Carlos Mennens
Date:
I saw in the documentation for PostgreSQL that I can add 'comments' to
table entries when creating columns:

http://www.postgresql.org/docs/8.1/static/tutorial-table.html

CREATE TABLE weather (
    city            varchar(80),
    temp_lo         int,           -- low temperature
    temp_hi         int,           -- high temperature
    prcp            real,          -- precipitation
    date            date
);

I did a search and don't understand in what aspect are the 'comments'
relevant / visible? I don't see the comments when I attempt to list /
describe the table with \d weather;

Any suggestions?

Re: Table Comments

From
Bill Moran
Date:
In response to Carlos Mennens <carlos.mennens@gmail.com>:

> I saw in the documentation for PostgreSQL that I can add 'comments' to
> table entries when creating columns:
>
> http://www.postgresql.org/docs/8.1/static/tutorial-table.html
>
> CREATE TABLE weather (
>     city            varchar(80),
>     temp_lo         int,           -- low temperature
>     temp_hi         int,           -- high temperature
>     prcp            real,          -- precipitation
>     date            date
> );
>
> I did a search and don't understand in what aspect are the 'comments'
> relevant / visible? I don't see the comments when I attempt to list /
> describe the table with \d weather;

You're confusing table comments with SQL comments.

SQL comments (which you show above) comment the SQL and are lost if
the SQL code is not preserved.  i.e., they do not affect what the
SQL does, thus they are not stored anywhere in the database.  They're
a great help for documenting queries in you application code, though.

To add comments to a table (which it seems that you want) use the
COMMENT ON command to add them:
http://www.postgresql.org/docs/8.4/static/sql-comment.html

--
Bill Moran
http://www.potentialtech.com
http://people.collaborativefusion.com/~wmoran/

Re: Table Comments

From
"Octavio Alvarez"
Date:
On Wed, 15 Sep 2010 08:53:16 -0700, Carlos Mennens
<carlos.mennens@gmail.com> wrote:

> CREATE TABLE weather (
>     temp_lo         int,           -- low temperature
> );
>
> I did a search and don't understand in what aspect are the 'comments'
> relevant / visible? I don't see the comments when I attempt to list /
> describe the table with \d weather;

Those are comments to the SQL code, not comments to the columns. Comments
to SQL code are fully ignored by PostgreSQL on execution.

Those are useful if you have an SQL script and you want to document
something there.

For column comments you might want to take a look at the COMMENT command.

Re: Table Comments

From
Steve Crawford
Date:
On 09/15/2010 08:53 AM, Carlos Mennens wrote:
> I saw in the documentation for PostgreSQL that I can add 'comments' to
> table entries when creating columns:
>
> http://www.postgresql.org/docs/8.1/static/tutorial-table.html
>
> CREATE TABLE weather (
>      city            varchar(80),
>      temp_lo         int,           -- low temperature
>      temp_hi         int,           -- high temperature
>      prcp            real,          -- precipitation
>      date            date
> );
>
> I did a search and don't understand in what aspect are the 'comments'
> relevant / visible? I don't see the comments when I attempt to list /
> describe the table with \d weather;
>
> Any suggestions?
>
>
Don't confuse "--" with "COMMENT ON".

A -- is SQL's comment "character",  like # in Bash, // in C, etc. so you
can comment the SQL statements in your code.

The "COMMENT ON" statement lets you add descriptions to database objects
(tables, individual columns, etc.). See
http://www.postgresql.org/docs/8.1/static/sql-comment.html for more on
the COMMENT statement.

Cheers,
Steve


Re: Table Comments

From
Carlos Mennens
Date:
Thank you all for that information.