Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/postgresql/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/google-cloud-platform/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Postgresql Knex无法从云函数在云SQL Postgres中找到表_Postgresql_Google Cloud Platform_Google Cloud Functions_Google Cloud Sql_Knex.js - Fatal编程技术网

Postgresql Knex无法从云函数在云SQL Postgres中找到表

Postgresql Knex无法从云函数在云SQL Postgres中找到表,postgresql,google-cloud-platform,google-cloud-functions,google-cloud-sql,knex.js,Postgresql,Google Cloud Platform,Google Cloud Functions,Google Cloud Sql,Knex.js,我正试图从一个用TypeScript编写的云函数连接到一个运行在cloudsql中的postgres12db 我使用以下内容创建数据库: import * as Knex from "knex" const { username, password, instance } = ... // username, password, connection name (<app-name>:<region>:<database>) const

我正试图从一个用TypeScript编写的云函数连接到一个运行在cloudsql中的postgres12db

我使用以下内容创建数据库:

import * as Knex from "knex"

const { username, password, instance } = ... // username, password, connection name (<app-name>:<region>:<database>)

const config = {
   client: 'pg',
   connection: {
      user: username,
      password: password, 
      database: 'ingredients',
      host: `/cloudsql/${instance}`,
      pool: { min: 1, max: 1}
   }
}

const knex = Knex(config as Knex.Config)
运行此代码时,在云函数日志中出现以下错误:

Unhandled error { error: select * from "tableName" where "name" ilike $1 - relation "tableName" does not exist
    at Parser.parseErrorMessage (/workspace/node_modules/pg-protocol/dist/parser.js:278:15)
    at Parser.handlePacket (/workspace/node_modules/pg-protocol/dist/parser.js:126:29)
    at Parser.parse (/workspace/node_modules/pg-protocol/dist/parser.js:39:38)
    at Socket.stream.on (/workspace/node_modules/pg-protocol/dist/index.js:10:42)
    at Socket.emit (events.js:198:13)
    at Socket.EventEmitter.emit (domain.js:448:20)
    at addChunk (_stream_readable.js:288:12)
    at readableAddChunk (_stream_readable.js:269:11)
    at Socket.Readable.push (_stream_readable.js:224:10)
    at Pipe.onStreamRead [as onread] (internal/stream_base_commons.js:94:17)
我在GCP Cloud Shell中使用以下命令创建了表(然后使用CSV中的数据填充):

在该控制台中,如果我运行查询
SELECT*fromtablename,我看到列出了正确的数据

为什么Knex没有看到表:
tableName
,但GCP Cloud Shell看到了


顺便说一句,我确实连接到了正确的数据库,因为我在Cloud SQL日志界面中看到了相同的错误日志。

看起来您正在创建表
tableName
,而没有加引号,这使得它实际上是小写的(不区分大小写)。因此,在创建模式时,请执行以下操作:

CREATE TABLE "tableName" ("name" VARCHAR(255), "otherField" VARCHAR(255), ... );

或者只使用小写的表/列名。

看起来您正在创建表
tableName
,而没有引用,这使得它实际上是小写的(不区分大小写)。因此,在创建模式时,请执行以下操作:

CREATE TABLE "tableName" ("name" VARCHAR(255), "otherField" VARCHAR(255), ... );
或者只使用小写的表/列名

CREATE TABLE "tableName" ("name" VARCHAR(255), "otherField" VARCHAR(255), ... );