【问题标题】:I get wrong results when joining tables in node js with pg使用 pg 连接节点 js 中的表时,我得到错误的结果
【发布时间】:2018-11-04 22:00:00
【问题描述】:

当我使用 node.js 中的 pg 向数据库发送 LEFT JOIN 查询时,我有一个名为“ExternalCategories”的表,我得到了难以理解的结果

'SELECT * FROM "ExternalCategories" a Left JOIN "externalcat" b ON a."parentCategoryId"=b.id'

我明白了:

    {
"id": 34,
"name": "Ordinateurs et Resea",
"img": null,
"views": 0,
"parentCategoryId": null
},
{
"id": null,
"name": null,
"img": null,
"views": null,
"parentCategoryId": null
},
{
"id": 1,
"name": "Vêtements",
"img": null,
"views": 0,
"parentCategoryId": null
},
{
"id": 34,
"name": "Ordinateurs et Resea",
"img": null,
"views": 0,
"parentCategoryId": null
},

但是当我在 Datagrip 或 pgAdmin4 中运行相同的查询时,我得到了正确的数据 Results in datagrip

【问题讨论】:

    标签: node.js postgresql express node-postgres


    【解决方案1】:

    考虑通过别名来区分返回的列名

    'SELECT a.id AS a1,  a.name AS c2... FROM ExternalCategories a ....'
    

    【讨论】:

      猜你喜欢
      • 2022-01-18
      • 2018-10-27
      • 1970-01-01
      • 1970-01-01
      • 2020-05-12
      • 1970-01-01
      • 1970-01-01
      • 2013-03-30
      • 2021-08-09
      相关资源
      最近更新 更多