snippetsqlModerate
How to add comment to a column in a table in Postgres?
Viewed 0 times
commentpostgrescolumnhowtableadd
Problem
I'm new to Postgres. I would like add a comment to my column
I have tried this sql code:
But which didn't help me, can anyone help me?
mod in a table called app-user-bookingsI 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:
It makes sense to add a check to prevent wrong values appearing:
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.