Postgresql 如何使用knex和postgres避免错误42702(不明确列)

Postgresql 如何使用knex和postgres避免错误42702(不明确列),postgresql,knex.js,Postgresql,Knex.js,我有两个表,类别和子类别 两者都有描述字段 我配置了以下查询 const get = (req, res) => { app.db({ s: 'subCategory', c: 'category' }) .select('s.id', 's.description', { category: 'c.description' }) .whereRaw('?? = ??', ['c.id', 's.categoryId']) .whe

我有两个表,类别和子类别

两者都有描述字段

我配置了以下查询

 const get = (req, res) => {
    app.db({ s: 'subCategory', c: 'category' })
        .select('s.id', 's.description', { category: 'c.description' })
        .whereRaw('?? = ??', ['c.id', 's.categoryId'])
        .where({ deletedAt: null })
        .then(subCategorys => res.json(subCategorys))
        .catch(err => res.status(500).send(err))
}
我重命名了类别列描述字段, 但是它显示了重复列的错误,我有另一个方法,我用这种方式重命名它,它可以处理那些同名的列,它显示了错误42702(即列的模糊错误)

我正在使用postgresql并将knex重命名为db

这个方法中有一些东西需要更改才能正常工作,否则我真的需要使用knex.raw创建整个查询


错误:
{“length”:111,“name”:“error”,“severity”:“error”,“code”:“42702”,“position”:“152”,“file”:“parse_relation.c”,“line”:“791”,“routine”:“colNameToVar”}

您需要定义别名不明确的列。
如果表上的
deletedAt
不明确,您需要在查询中设置
s.deletedAt
,用表别名限定所有列名(如
deletedAt
)。您是对的,我添加了
。whereNull('s.deletedAt')
,非常感谢