Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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 :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading