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.

Emile Paffard-Wray
  • 1,006
  • 2
  • 9
  • 17
  • @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. – Emile Paffard-Wray Oct 03 '17 at 09:19
  • https://stackoverflow.com/q/22256124/330315 –  Oct 03 '17 at 10:47

1 Answers1

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

Avantika Saini
  • 792
  • 4
  • 9