Lee White
Lee White

Reputation: 3719

Strange SQL statement error in SQLAlchemy-Flask

I am using SQLAlchemy in Flask to connect to my Postgres server, and now I want to execute some raw SQL to insert a column into a table. I am getting this error, however:

sqlalchemy.exc.ProgrammingError: (ProgrammingError) syntax error at or near "user"
LINE 1: ALTER TABLE user ADD COLUMN permissions INTEGER
                    ^
 'ALTER TABLE user ADD COLUMN permissions INTEGER' {}

As you can see, it says there is an SQL error, although I have no idea what I could be doing wrong.

This is the very simple function that executes the command:

@staticmethod
def addColumn():
    db.engine.execute('ALTER TABLE user ADD COLUMN permissions INTEGER')

The db object otherwise works perfectly, and there is nothing wrong with the connection or anything of the sort.

I feel like I'm overlooking something very simple, but I just can't figure out what it is. Does anybody have any idea?

Upvotes: 0

Views: 356

Answers (2)

Joachim Isaksson
Joachim Isaksson

Reputation: 180917

The PostgreSQL docs say that USER is a reserved keyword, and needs to be quoted to be used as an identifier.

Key Word      PostgreSQL      SQL 99      SQL 92
USER          reserved        reserved    reserved

Upvotes: 2

jaadooviewer
jaadooviewer

Reputation: 368

Is user a reserved word and thus needing to be referenced specially in SQL statement?

Upvotes: 1

Related Questions