문제

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.

도움이 되었습니까?

해결책

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

다른 팁

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
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top