Search code examples
typescriptpostgresqlpg

TypeScript: postgres column doesn't exist


I am using pg library to make query on postgres by typeScript. I have created a db class like this:

import { Pool } from 'pg';


const pool = new Pool({
    host: process.env.PG_HOST,
    port: parseInt(process.env.PG_PORT),
    user: process.env.PG_USER,
    password: process.env.PG_PASSWORD,
    database: process.env.PG_DATABASE,
    idleTimeoutMillis: 30000,
    ssl: true
});

export default pool;

Now In my class When I am trying to select a query:

  const result = await pool.query('SELECT email FROM User LIMIT 10');

I got :

stack:'error: column "email" does not exist\n    at Parser.parseErrorMessage ... at TLSSocket.emit (node:events:526:28)\n    at addChunk (node:internal/streams/readable:315:12)\n    at readableAddChunk (node:internal/streams/readable:289:9)\n    at TLSSocket.Readable.push (node:internal/streams/readable:228:10)\n    at TLSWrap.onStreamRead (node:internal/stream_base_commons:190:23)\n    at TLSWrap.callbackTrampoline (node:internal/async_hooks:130:17)'

But I have an email column In the user Table:

enter image description here


Solution

  • Try the following as your query:

    SELECT email FROM "User" LIMIT 10
    

    You need to quote the table name if you did it when creating the table.