0

I am trying to create a table with the following query using the pg npm module (v7):

CREATE TABLE subscriptions(
    id SERIAL PRIMARY KEY,
    stripe_id VARCHAR(40) UNIQUE NOT NULL,
    user INTEGER REFERENCES users,
    plan VARCHAR(40) NOT NULL,
    active BOOLEAN NOT NULL,
    start DATE NOT NULL,
    end DATE DEFAULT NULL
  );

This seems to match the docs but it is throwing an error:

 error: syntax error at or near "user"

The users table has a serial primary key for id, anyone know why this isn't working?

Edit: here's the docs for reference - https://www.postgresql.org/docs/9.4/static/ddl-constraints.html#DDL-CONSTRAINTS-FK

I'm using postgresql version 9.4.

2
  • @AvantikaSaini The users table does exist, it has a column for "id" rather than "user", but I understood from the docs that this is OK - see the third example in the docs section referenced above. Commented Oct 3, 2017 at 9:19
  • stackoverflow.com/q/22256124/330315 Commented Oct 3, 2017 at 10:47

1 Answer 1

1

user is a reserved keyword in postgresql. You may use any other column name in its place

Refer the postgresql documentation for the complete list of keywords - Key Words List

According to it, end is also reserved. So the last line of your code will generate an error

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

1 Comment

Thanks, that's solved it and looks like "end" is also a reserved keyword.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.