【问题标题】:Get return type OID of functions with node-postgres使用 node-postgres 获取函数的返回类型 OID
【发布时间】:2019-11-22 17:20:06
【问题描述】:

当使用node-postgres 查询 Postgres 数据库时,成功的查询将返回具有oid 属性的pg.Result 类型。

查询集合返回函数时,oidnull

从函数中选择时,有没有办法获得返回类型的oid

【问题讨论】:

    标签: postgresql node-postgres


    【解决方案1】:

    Result.oid 属性与返回类型无关。

    在 Postgres 12 之前,您可以使用 CREATE TABLE ... WITH OIDS 在表中包含自动分配的 oid 列。

    在将单行INSERT 放入表WITH OIDS 的特殊情况下,服务器的CommandComplete response 包含新行的oid。对于所有其他 INSERTs,oid 为零,对于所有其他命令,响应不包含 oid

    node-postgres source 表明Result.oid 属性派生自此响应。对于SELECT 响应,永远不会分配oid,因此无论您要查询什么,null 都会被分配。这个值(以及一般的 OID 列)的有限用途可能解释了为什么 oid 属性是 undocumented

    返回类型与结果的相关联,而不是与整个结果相关联。您可以使用例如:

    获取列的类型 OID
    result.fields[0].dataTypeId
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-10-04
      • 2016-07-01
      • 2018-11-06
      • 2014-08-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-09-14
      相关资源
      最近更新 更多