0

I recently started coding in javascript. Been trying to use pg module to interact with my postgres db. But it keeps saying relation does not exist even though everything is okay and the table does exist. Any help will be appreciated.

const Pool = require('pg').Pool

const pool = new Pool({
    user: 'postgres',
    host: 'localhost',
    database: 'test',
    password: 'test#123',
    port: '5432',
})


pool.query("SELECT * FROM clients", (error, results) => {
    if (error) throw error
    console.log(results)
})

module.exports = pool

Error:

error: relation "clients" does not exist
    at Parser.parseErrorMessage (C:\Users\Maaz\Desktop\Code\acube_backend\node_modules\pg-protocol\dist\parser.js:287:98)
    at Parser.handlePacket (C:\Users\Maaz\Desktop\Code\acube_backend\node_modules\pg-protocol\dist\parser.js:126:29)
    at Parser.parse (C:\Users\Maaz\Desktop\Code\acube_backend\node_modules\pg-protocol\dist\parser.js:39:38)
    at Socket.<anonymous> (C:\Users\Maaz\Desktop\Code\acube_backend\node_modules\pg-protocol\dist\index.js:11:42)
    at Socket.emit (node:events:513:28)
    at addChunk (node:internal/streams/readable:315:12)
    at readableAddChunk (node:internal/streams/readable:289:9)
    at Socket.Readable.push (node:internal/streams/readable:228:10)
    at TCP.onStreamRead (node:internal/stream_base_commons:190:23) {
  length: 106,
  severity: 'ERROR',
  code: '42P01',
  detail: undefined,
  hint: undefined,
  position: '15',
  internalPosition: undefined,
  internalQuery: undefined,
  where: undefined,
  schema: undefined,
  table: undefined,
  column: undefined,
  dataType: undefined,
  constraint: undefined,
  file: 'parse_relation.c',
  line: '1384',
  routine: 'parserOpenTable'
}
Bergi
  • 630,263
  • 148
  • 957
  • 1,375
Nez
  • 39
  • 5
  • Share your data base schema - tables and database. PG is case sensitive so ensure you show exactly what your DB/table names are. – jeeves Oct 18 '22 at 10:43
  • Maybe you are connected to the wrong database, or the wrong port, or the wrong host entirely, or have the wrong default search_path. But one way or another, the table does not exist in the place you are looking for it. – jjanes Oct 18 '22 at 14:38

0 Answers0