10

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?

3
  • 1
    For the record, here is the comment section of the documentation
    – Sahap Asci
    Jan 11, 2017 at 6:03
  • 1
    You should also add a check constraint that makes sure the column does not store any other value then mentioned in the comment. Mar 9, 2017 at 7:21
  • 1
    @a_horse_with_no_name I've incorporated your suggestion in the answer.
    – dezso
    Mar 9, 2017 at 10:20

1 Answer 1

15

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));
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.