File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -91,6 +91,12 @@ Column.prototype.count = function(alias) {
9191 return new ColumnNode ( context ) ;
9292} ;
9393
94+ Column . prototype . distinct = function ( ) {
95+ var context = contextify ( this ) ;
96+ context . distinct = true ;
97+ return new ColumnNode ( context ) ;
98+ } ;
99+
94100binaryMethod ( 'equals' , '=' ) ;
95101binaryMethod ( 'equal' , '=' ) ;
96102binaryMethod ( 'notEqual' , '<>' ) ;
Original file line number Diff line number Diff line change @@ -287,11 +287,17 @@ Postgres.prototype.visitColumn = function(columnNode) {
287287 var table = columnNode . table ;
288288 var inSelectClause = ! this . _selectOrDeleteEndIndex ;
289289 var txt = "" ;
290+ var closeParen = false ;
290291 if ( inSelectClause ) {
291292 if ( columnNode . asArray ) {
293+ closeParen = true ;
292294 txt += this . _arrayAggFunctionName + '(' ;
293295 } else if ( columnNode . aggCount ) {
296+ closeParen = true ;
294297 txt += 'COUNT(' ;
298+ } else if ( columnNode . distinct === true ) {
299+ closeParen = true ;
300+ txt += 'DISTINCT('
295301 }
296302 }
297303 if ( ! this . _visitedInsert && ! this . _visitingUpdateTargetColumn && ! this . _visitingCreate && ! this . _visitingAlter ) {
@@ -311,7 +317,7 @@ Postgres.prototype.visitColumn = function(columnNode) {
311317 } else {
312318 txt += this . quote ( columnNode . name ) ;
313319 }
314- if ( inSelectClause && ( columnNode . asArray || columnNode . aggCount ) ) {
320+ if ( closeParen ) {
315321 txt += ')' ;
316322 }
317323 if ( inSelectClause && columnNode . alias ) {
Original file line number Diff line number Diff line change @@ -14,6 +14,7 @@ module.exports = Node.define({
1414 this . table = config . table ;
1515 this . value = config . getValue ( ) ;
1616 this . dataType = config . dataType ;
17+ this . distinct = config . distinct ;
1718 } ,
1819 as : function ( alias ) {
1920 this . alias = alias ;
Original file line number Diff line number Diff line change 1+ 'use strict' ;
2+
3+ var Harness = require ( './support' ) ;
4+ var user = Harness . defineUserTable ( ) ;
5+
6+ Harness . test ( {
7+ query : user . select ( user . id . distinct ( ) ) ,
8+ pg : 'SELECT DISTINCT("user"."id") FROM "user"'
9+ } ) ;
You can’t perform that action at this time.
0 commit comments