1

I just noticed you can write both in PostgreSQL. Is there any difference or is it just a "simplified" syntax. As far as I know, both of these does exactly the same.

ALTER TABLE table DROP my_column;

vs

ALTER TABLE table DROP COLUMN my_column;

EDIT: I've searched around for this, but couldn't find anything. That includes the documentation.

3
  • 2
    have you checked the documentation? Commented Jan 5, 2015 at 8:59
  • @Watercolours I think you don't understand PostgreSQL Documentation, see my answer for details Commented Jan 5, 2015 at 9:28
  • 1
    I did read the docs, but missed the line that said it could be omitted. As well as the [] being optional. My bad. Anyways, going to leave the question here for others in the future. Commented Jan 5, 2015 at 9:32

3 Answers 3

3

According to here, COLUMN is optional i.e. the statements are equivalent. Personally, I'd keep it for clarity

Sign up to request clarification or add additional context in comments.

Comments

3

Both syntax have same meaning,its your wish to choose among the two syntax, for the below example Keyword COLUMN can used for more clarity.

ALTER TABLE table DROP COLUMN col1, 
                  DROP COLUMN col2, 
                  DROP COLUMN col3, 
                       .... 
                  DROP COLUMN col_n;  

The document itself is described that the keyword COLUMN is optional, because as per the documentation

ALTER TABLE [ IF EXISTS ] [ ONLY ] name [ * ]
    action [, ... ]
ALTER TABLE [ IF EXISTS ] [ ONLY ] name [ * ]
    RENAME [ COLUMN ] column_name TO new_column_name
ALTER TABLE [ IF EXISTS ] [ ONLY ] name [ * ]
    RENAME CONSTRAINT constraint_name TO new_constraint_name
ALTER TABLE [ IF EXISTS ] name
    RENAME TO new_name
ALTER TABLE [ IF EXISTS ] name
    SET SCHEMA new_schema
ALTER TABLE ALL IN TABLESPACE name [ OWNED BY role_name [, ... ] ]
    SET TABLESPACE new_tablespace [ NOWAIT ]

where action is one of:

    ADD [ COLUMN ] column_name data_type [ COLLATE collation ] [ column_constraint [ ... ] ]
    DROP [ COLUMN ] [ IF EXISTS ] column_name [ RESTRICT | CASCADE ]

FYI, keywords written inside [] indicates optional

ex. DROP [ COLUMN ] here COLUMN is optional

1 Comment

yes the word inside [] are optional, but some of those optional words change the way the request is processed (eg: IF EXISTS )
2

As decribed in documentation, it can be omitted.

The key word COLUMN is noise and can be omitted.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.