Skip to content

query() throwing column does not exist error, despite it existing #2795

@lukasjenks

Description

@lukasjenks

In pgAdmin/the cli, the following query:

UPDATE wq SET l_id = NULL, v_id = NULL WHERE w_id = 'cf93bc71-88c1-4bba-9e5c-fdc58d0ed14e';

works fine. However, when calling the same with the pg package in node:

const w_id_val = 'cf93bc71-88c1-4bba-9e5c-fdc58d0ed14e';
// (here client is the result of calling `const pool =  pg.Pool({...})` , 
// then `let client = await pool.connect()`);
const result = await client.query(
  `UPDATE wq
   SET l_id = null,
       v_id = null
   WHERE w_id = $1`,
  [w_id_val]
);

I get the following error:

{
   "message":"column \"w_id\" does not exist",
   "stack":"error: column \"w_id\" does not exist\n    at Connection.parseE (/Users/lukasjenks/Documents/Work/socrative-nodejs/node_modules/pg/lib/connection.js:569:11)\n    at Connection.parseMessage (/Users/lukasjenks/Documents/Work/socrative-nodejs/node_modules/pg/lib/connection.js:396:17)\n    at Socket.<anonymous> (/Users/lukasjenks/Documents/Work/socrative-nodejs/node_modules/pg/lib/connection.js:132:22)\n    at Socket.emit (events.js:314:20)\n    at Socket.EventEmitter.emit (domain.js:483:12)\n    at addChunk (_stream_readable.js:297:12)\n    at readableAddChunk (_stream_readable.js:272:9)\n    at Socket.Readable.push (_stream_readable.js:213:10)\n    at TCP.onStreamRead (internal/stream_base_commons.js:188:23)\n    at TCP.callbackTrampoline (internal/async_hooks.js:126:14)",
   "name":"error",
   "length":112,
   "severity":"ERROR",
   "code":"42703",
   "position":"68",
   "file":"parse_relation.c",
   "line":"3514",
   "routine":"errMissingColumn"
}

I can confirm the column exists with this query:

SELECT table_schema, table_name, column_name, data_type
  FROM information_schema.columns
 WHERE table_name = 'wq';
public	wq	id	uuid
public	wq	w_id	uuid
public	wq	l_id	uuid
public	wq	v_id	uuid

I can also confirm that the column (w_id) should be recognized by pg as when using pg to query the table with a SELECT statement, I get this back in the fields property in the result object returned:

  fields: [
    Field {
      name: 'id',
      tableID: 26611,
      columnID: 1,
      dataTypeID: 2950,
      dataTypeSize: 16,
      dataTypeModifier: -1,
      format: 'text'
    },
    Field {
      name: 'w_id',
      tableID: 26611,
      columnID: 3,
      dataTypeID: 2950,
      dataTypeSize: 16,
      dataTypeModifier: -1,
      format: 'text'
    },
    ...

I've also confirmed this isn't a case issue; i.e. the column name is all lowercase and using double quotes around the column name has no effect.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions