HiveBrain v1.2.0
Get Started
← Back to all entries
snippetsqlModerate

How to add comment to a column in a table in Postgres?

Submitted by: @import:stackexchange-dba··
0
Viewed 0 times
commentpostgrescolumnhowtableadd

Problem

I'm new to Postgres. I would like add a comment to my column mod in a table called app-user-bookings

I have tried this sql code:

alter table app_user_bookings
modify column mod 
int default 1 
comment "1# mobile booking,    2# admin booking,    3# web booking, 4# tell call";


But which didn't help me, can anyone help me?

Solution

To update comment, don't use alter command.

Here is the PostgreSQL syntax:

comment on column app_user_bookings.mod is '1# mobile booking,    2# admin booking,    3# web booking, 4# tell call'


It makes sense to add a check to prevent wrong values appearing:

ALTER TABLE app_user_bookings
ADD CHECK (mod IN (1,2,3,4));

Code Snippets

comment on column app_user_bookings.mod is '1# mobile booking,    2# admin booking,    3# web booking, 4# tell call'
ALTER TABLE app_user_bookings
ADD CHECK (mod IN (1,2,3,4));

Context

StackExchange Database Administrators Q#160667, answer score: 18

Revisions (0)

No revisions yet.