Drop Down MenusCSS Drop Down MenuPure CSS Dropdown Menu

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
Comments are attached to a column using the comment statement:
postgres=# create table comment_log 
(
userid int not null,
phonenumber int
);
CREATE TABLE
--comment on table's column
postgres=# comment on column comment_log.userid is 'The user ID';
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
--You can also add a comment to the table:
postgres=# comment on table comment_log is 'Our comment logs';
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)
Additionally: int index is invalid.
--If you want to create an index on a column, you do that using the create index statement:
postgres=# \d comment_log                           
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)
--If you want an index over both columns use:
postgres=# create index on comment_log(userid, 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)
"comment_log_userid_phonenumber_idx" btree (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):
postgres=# create table comment_log 
(
UserId int primary key,
PhoneNumber int
);
CREATE TABLE
Note:-Defining a column as the primary key implicitly makes it not null

--Removing comments
COMMENT ON TABLE comment_log IS NULL;
select obj_description('benz2.comments_log'::regclass);

Comments

Popular posts from this blog

Oracle DBMS SCHEDULER Examples

How to find the server is whether standby (slave) or primary(master) in Postgresql replication ?

7 Steps to configure BDR replication in postgresql

How to Get Table Size, Database Size, Indexes Size, schema Size, Tablespace Size, column Size in PostgreSQL Database

vacuumlo - removing large objects orphans from a database PostgreSQL