fix: infer postgres field (#3663)

This commit is contained in:
ChengLei Shao 2024-03-09 10:08:32 +08:00 committed by GitHub
parent 677eb152e0
commit 46daba1e6e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 8 additions and 4 deletions

View File

@ -34,7 +34,7 @@ describe('view inference', function () {
await db.sync();
const viewName = 'user_posts';
const viewName = 'test_view';
const dropViewSQL = `DROP VIEW IF EXISTS ${viewName}`;
await db.sequelize.query(dropViewSQL);

View File

@ -153,10 +153,14 @@ export default class PostgresQueryInterface extends QueryInterface {
// handle column alias
const from = ast[0].from;
const findAs = from.find((from) => from.as === columnExprTable);
if (columnExprTable === null && column.expr.type === 'column_ref') {
columnExprTable = from[0].table;
} else {
const findAs = from.find((from) => from.as === columnExprTable);
if (findAs) {
columnExprTable = findAs.table;
if (findAs) {
columnExprTable = findAs.table;
}
}
return columnUsage.column_name === column.expr.column && columnUsage.table_name === columnExprTable;