sqlpostgresqlquoted-identifier

"syntax error at or near 'order'"" in PostgreSQL


I'm trying to add a column named order to my table. I realize that order is a reserved word in SQL. So, how do I do it? My command:

   alter table mytable add column order integer;

I've also tried:

   alter table mytable add column 'order' integer;

PostgreSQL 9.1.


Solution

  • Use this:

    alter table mytable add column "order" integer;
    

    But, you might want to consider using a non-reserved name instead, like sort_order or something similar that reflects what the column is used for (and isn't a reserved word).