从带有 NodeJS 的表中选择 * // 错误:{ 错误:关系"mytable"不存在



我在从PostgreSQL数据库进行SELECT查询时收到以下错误

ERROR: { error: relation "free_subnets" does not exist
at Connection.parseE (/home/ec2-user/environment/node_modules/pg/lib/connection.js:604:11)
at Connection.parseMessage (/home/ec2-user/environment/node_modules/pg/lib/connection.js:401:19)
at Socket.<anonymous> (/home/ec2-user/environment/node_modules/pg/lib/connection.js:121:22)
at Socket.emit (events.js:198:13)
at addChunk (_stream_readable.js:288:12)
at readableAddChunk (_stream_readable.js:269:11)
at Socket.Readable.push (_stream_readable.js:224:10)
at TCP.onStreamRead [as onread] (internal/stream_base_commons.js:94:17)
name: 'error',
length: 103,
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: '874',
routine: 'parserOpenTable' }

如果我使用 psql 命令并在那里进行选择,它可以工作。

\dt 为我提供了关系:


Schema    |     Name     | Type  |  Owner   
-------------+--------------+-------+----------
subnet_calc | free_subnets | table | postgres

Search_path已设置为:subnet_calc,公共

我已经使用用户 postgres 创建了表,所以我是架构subnet_calc和表free_subnets的所有者。

我的虚拟nodejs代码如下:

const pg = require('pg');

const cs = 'postgres://postgres:password@anydb.rds.amazonaws.com:5432/subnet_calculator';
const client = new pg.Client(cs);
client.connect();
client.query('SELECT * FROM subnet_calc.free_subnets', function(result) {
console.log(result);
});

可能是什么问题?

提前感谢您的帮助!

我可以解决这个问题。这是我的失败,这些表是在数据库帖子中创建的,而不是在subnet_calculator中创建的。

我将结束这个问题。

您需要像这样为其设置搜索路径:

db.query("SET search_path TO 'subnet_calc';")

然后执行查询:

const query = `SELECT * FROM free_subnets`
db.query(query)

相关内容

  • 没有找到相关文章

最新更新