Skip to content

Commit 728fe06

Browse files
author
Bergwinkl Thomas
committed
fixed missing table name for .star() with alias case
1 parent 233e352 commit 728fe06

2 files changed

Lines changed: 26 additions & 2 deletions

File tree

lib/dialect/postgres.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -650,14 +650,20 @@ Postgres.prototype.visitColumn = function(columnNode) {
650650
var allCols = [];
651651
var hasAliases = false;
652652
if(columnNode.aggregator !== 'COUNT') {
653+
var tableName = txt.join('');
653654
for (var i = 0; i < table.columns.length; ++i) {
654655
var col = table.columns[i];
655656
var aliased = col.name !== (col.alias || col.property);
656657
hasAliases = hasAliases || aliased;
657-
allCols.push(this.quote(col.name) + (aliased ? ' AS ' + this.quote(col.alias || col.property) : ''));
658+
allCols.push(tableName + this.quote(col.name) + (aliased ? ' AS ' + this.quote(col.alias || col.property) : ''));
658659
}
659660
}
660-
txt.push(hasAliases ? allCols.join(', ') : '*');
661+
if(hasAliases) {
662+
txt = [allCols.join(', ')];
663+
}
664+
else {
665+
txt.push('*');
666+
}
661667
}
662668
else {
663669
txt.push(this.quote(columnNode.name));

test/dialects/select-tests.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
var Harness = require('./support');
44
var post = Harness.definePostTable();
5+
var customerAlias = Harness.defineCustomerAliasTable();
56

67
Harness.test({
78
query: post.select(post.id).select(post.content),
@@ -19,3 +20,20 @@ Harness.test({
1920
},
2021
params: []
2122
});
23+
24+
Harness.test({
25+
query: customerAlias.select(customerAlias.star()),
26+
pg: {
27+
text : 'SELECT "customer"."id" AS "id_alias", "customer"."name" AS "name_alias", "customer"."age" AS "age_alias", "customer"."income" AS "income_alias", "customer"."metadata" AS "metadata_alias" FROM "customer"',
28+
string: 'SELECT "customer"."id" AS "id_alias", "customer"."name" AS "name_alias", "customer"."age" AS "age_alias", "customer"."income" AS "income_alias", "customer"."metadata" AS "metadata_alias" FROM "customer"'
29+
},
30+
sqlite: {
31+
text : 'SELECT "customer"."id" AS "id_alias", "customer"."name" AS "name_alias", "customer"."age" AS "age_alias", "customer"."income" AS "income_alias", "customer"."metadata" AS "metadata_alias" FROM "customer"',
32+
string: 'SELECT "customer"."id" AS "id_alias", "customer"."name" AS "name_alias", "customer"."age" AS "age_alias", "customer"."income" AS "income_alias", "customer"."metadata" AS "metadata_alias" FROM "customer"'
33+
},
34+
mysql: {
35+
text : 'SELECT `customer`.`id` AS `id_alias`, `customer`.`name` AS `name_alias`, `customer`.`age` AS `age_alias`, `customer`.`income` AS `income_alias`, `customer`.`metadata` AS `metadata_alias` FROM `customer`',
36+
string: 'SELECT `customer`.`id` AS `id_alias`, `customer`.`name` AS `name_alias`, `customer`.`age` AS `age_alias`, `customer`.`income` AS `income_alias`, `customer`.`metadata` AS `metadata_alias` FROM `customer`'
37+
},
38+
params: []
39+
});

0 commit comments

Comments
 (0)