Pregunta

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.

¿Fue útil?

Solución

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).

Otros consejos

I think you don't need "column". Plus "order" is a keyword in SQL, so you should use a different name for your column. Follow this syntax:

ALTER TABLE table_name ADD column_name datatype

Source: W3Schools

You are using order which is a reserved keyword you should consider renaming that to something like orders. And the problem should go away.

ALTER TABLE table_name
ADD COLUMN "order" integer
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top