|
|
@ -9,6 +9,8 @@ var Postgres = function() { |
|
|
|
this.params = []; |
|
|
|
}; |
|
|
|
|
|
|
|
Postgres.prototype._arrayAggFunctionName = 'array_agg'; |
|
|
|
|
|
|
|
Postgres.prototype.getQuery = function(queryNode) { |
|
|
|
this.visitQuery(queryNode); |
|
|
|
return { text: this.output.join(' '), values: this.params }; |
|
|
@ -52,8 +54,10 @@ Postgres.prototype.visit = function(node) { |
|
|
|
} |
|
|
|
}; |
|
|
|
|
|
|
|
Postgres.prototype._quoteCharacter = '"'; |
|
|
|
Postgres.prototype.quote = function(word) { |
|
|
|
return '"' + word + '"'; |
|
|
|
var q = this._quoteCharacter; |
|
|
|
return q + word.replace(q,q+q) + q; |
|
|
|
}; |
|
|
|
|
|
|
|
Postgres.prototype.visitSelect = function(select) { |
|
|
@ -245,7 +249,7 @@ Postgres.prototype.visitTable = function(tableNode) { |
|
|
|
} |
|
|
|
txt += this.quote(table.getName()); |
|
|
|
if(table.alias) { |
|
|
|
txt += ' AS ' + table.alias; |
|
|
|
txt += ' AS ' + this.quote(table.alias); |
|
|
|
} |
|
|
|
return txt; |
|
|
|
}; |
|
|
@ -256,14 +260,14 @@ Postgres.prototype.visitColumn = function(columnNode) { |
|
|
|
var txt = ""; |
|
|
|
if(inSelectClause) { |
|
|
|
if (columnNode.asArray) { |
|
|
|
txt += 'array_agg('; |
|
|
|
txt += this._arrayAggFunctionName+'('; |
|
|
|
} else if (columnNode.aggCount) { |
|
|
|
txt += 'COUNT('; |
|
|
|
} |
|
|
|
} |
|
|
|
if(!this._visitedInsert && !this._visitingUpdateTargetColumn && !this._visitingCreate && !this._visitingAlter) { |
|
|
|
if(table.alias) { |
|
|
|
txt = table.alias; |
|
|
|
txt = this.quote(table.alias); |
|
|
|
} else { |
|
|
|
if(table.getSchema()) { |
|
|
|
txt = this.quote(table.getSchema()); |
|
|
@ -282,7 +286,7 @@ Postgres.prototype.visitColumn = function(columnNode) { |
|
|
|
txt += ')'; |
|
|
|
} |
|
|
|
if(inSelectClause && columnNode.alias) { |
|
|
|
txt += ' as ' + this.quote(columnNode.alias); |
|
|
|
txt += ' AS ' + this.quote(columnNode.alias); |
|
|
|
} |
|
|
|
if(this._visitingCreate || this._visitingAddColumn) { |
|
|
|
assert(columnNode.dataType, 'dataType missing for column ' + columnNode.name + |
|
|
|