TypeScript:postgres 列不存在
TypeScript: postgres column doesn't exist
我正在使用 pg 库通过 typeScript 在 postgres 上进行查询。我创建了一个数据库 class 是这样的:
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;
现在在我的 class 中,当我尝试 select 查询时:
const result = await pool.query('SELECT email FROM User LIMIT 10');
我得到了:
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)'
但是我在用户Table:
中有一个电子邮件列
尝试以下查询:
SELECT email FROM "User" LIMIT 10
如果在创建 table 时需要引用 table 名称。
我正在使用 pg 库通过 typeScript 在 postgres 上进行查询。我创建了一个数据库 class 是这样的:
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;
现在在我的 class 中,当我尝试 select 查询时:
const result = await pool.query('SELECT email FROM User LIMIT 10');
我得到了:
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)'
但是我在用户Table:
中有一个电子邮件列尝试以下查询:
SELECT email FROM "User" LIMIT 10
如果在创建 table 时需要引用 table 名称。