PostgreSQL Comment
- Only one comment string is stored for each object, so to modify a comment, issue a new COMMENT command for the same object. To remove a comment, write NULL in place of the text string. Comments are automatically dropped when their object is dropped.
- For most kinds of object, only the object's owner can set the comment. Roles don't have owners, so the rule for COMMENT ON ROLE is that you must be superuser to comment on a superuser role, or have the CREATEROLE privilege to comment on non-superuser roles. Of course, a superuser can comment on anything.
- Adding comment to field when i create table
postgres=# create table comment_log--comment on table's column
(
userid int not null,
phonenumber int
);
CREATE TABLE
postgres=# comment on column comment_log.userid is 'The user ID';--You can also add a comment to the table:
COMMENT
postgres=# comment on column comment_log.phonenumber is 'The phone number including the area code';
COMMENT
postgres=# \d+ comment_log;
Table "benz2.comment_log"
Column | Type | Modifiers | Storage | Stats target | Description
-------------+---------+-----------+---------+--------------+------------------------------------------
userid | integer | not null | plain | | The user ID
phonenumber | integer | | plain | | The phone number including the area code
postgres=# comment on table comment_log is 'Our comment logs';Additionally: int index is invalid.
COMMENT
postgres=# postgres=# \dt+ comment_log;
List of relations
Schema | Name | Type | Owner | Size | Description
--------+-------------+-------+-------+---------+------------------
benz2 | comment_log | table | u2 | 0 bytes | Our comment logs
(1 row)
--If you want to create an index on a column, you do that using the create index statement:
postgres=# \d comment_log--If you want an index over both columns use:
Table "benz2.comment_log"
Column | Type | Modifiers
-------------+---------+-----------
userid | integer | not null
phonenumber | integer |
postgres=# create index on comment_log(phonenumber);
CREATE INDEX
postgres=# \d comment_log
Table "benz2.comment_log"
Column | Type | Modifiers
-------------+---------+-----------
userid | integer | not null
phonenumber | integer |
Indexes:
"comment_log_phonenumber_idx" btree (phonenumber)
postgres=# create index on comment_log(userid, phonenumber);--You probably want to define the userid as the primary key. This is done using the following syntax (and not using int index):
CREATE INDEX
postgres=# \d comment_log
Table "benz2.comment_log"
Column | Type | Modifiers
-------------+---------+-----------
userid | integer | not null
phonenumber | integer |
Indexes:
"comment_log_phonenumber_idx" btree (phonenumber)
"comment_log_userid_phonenumber_idx" btree (userid, phonenumber)
postgres=# create table comment_logNote:-Defining a column as the primary key implicitly makes it not null
(
UserId int primary key,
PhoneNumber int
);
CREATE TABLE
--Removing comments
COMMENT ON TABLE comment_log IS NULL;
select obj_description('benz2.comments_log'::regclass);
Comments
Post a Comment