Skip to content

Unexpected results when querying a table called 'user' #28

Closed

Description

@pifantastic

Queries to all other tables work as expected. When I query a table called 'user', it seems to return records from some other table, perhaps postgres' table internally representing database users.

  client.query("SELECT * FROM user", function(err, data) {
    console.log(client, err, data);
  });

returns

{ _queryQueue: [], _namedQueries: {}, _activeQuery: { text: 'SELECT * FROM user', values: [], callback: [Function], rows: [ [Object] ] }, _config: { database: 'mydb_development', user: 'mydbuser', password: 'mydbpass', host: undefined, port: 5432 }, _events: { connect: [Function], _row: [Function], _error: [Function], _readyForQuery: [Function] }, _connected: true } null { rows: [ { current_user: 'mydbuser' } ] }

However, if I duplicate my users table and name it differently, say 'user_copy', everything works as expected. The easy workaround is to just change the name of my user table.

Activity

  1. pifantastic commented on Apr 25, 2011

    @pifantastic
    Author

    Gah, this appears to be a postgres thing and not related to your module. I apologize!

  2. pifantastic commented on Apr 25, 2011

    @pifantastic
    Author

    As a follow up, what I was doing wrong: user is a reserved word in Postgres so a query like SELECT * FROM user returns the current database user. This is fixed by properly quoting the table name:

      client.query('SELECT * FROM "user"', function(err, data) {
        console.log(client, err, data);
      });
    

    works as expected. TIL.

  3. added a commit that references this issue on Dec 18, 2019
  4. added a commit that references this issue on Apr 28, 2020
  5. added a commit that references this issue on Nov 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions