Pg-promise: Conflict with table name "user"

Created on 7 Jul 2016  路  2Comments  路  Source: vitaly-t/pg-promise

I used to have a table "user" (with id, email, name...etc.)

Using the following query;

db.one("select * from user where email=$1", request.body.email).then(function (data)

The result inside data was: { current_user: 'postgres'} which looks like data from the database user name rather than the user in my user table.

Renaming my table to something else solved the problem.

invalid / unrelated question

Most helpful comment

@sefo user is a reserved word in postgres. It's an alias for current_user function so when you do select * from user; internally it translates to select current_user; which, as you may have guessed, it returns the DB user used in the connection.

Try to avoid reserved names when naming your tables, columns, functions or anything else. users or user_accounts might be a better choice here.

All 2 comments

That's not likely, there must be something else you are missing.

Plus, this library does not interpret or change the data, you get it exactly as node-postgres provides it.

@sefo user is a reserved word in postgres. It's an alias for current_user function so when you do select * from user; internally it translates to select current_user; which, as you may have guessed, it returns the DB user used in the connection.

Try to avoid reserved names when naming your tables, columns, functions or anything else. users or user_accounts might be a better choice here.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

paleite picture paleite  路  4Comments

vitaly-t picture vitaly-t  路  3Comments

dzaman picture dzaman  路  3Comments

Juanflugel picture Juanflugel  路  3Comments

cmelone picture cmelone  路  3Comments