@@ -644,10 +644,10 @@ PostgreSQL.prototype._buildWhere = function(model, where) {
644644 if ( Array . isArray ( expression ) ) {
645645 // Column value is a list
646646 for ( let j = 0 , m = expression . length ; j < m ; j ++ ) {
647- columnValue . push ( this . toColumnValue ( p , expression [ j ] ) ) ;
647+ columnValue . push ( this . toColumnValue ( p , expression [ j ] , true ) ) ;
648648 }
649649 } else {
650- columnValue . push ( this . toColumnValue ( p , expression ) ) ;
650+ columnValue . push ( this . toColumnValue ( p , expression , true ) ) ;
651651 }
652652 if ( operator === 'between' ) {
653653 // BETWEEN v1 AND v2
@@ -669,7 +669,7 @@ PostgreSQL.prototype._buildWhere = function(model, where) {
669669 // do not coerce RegExp based on property definitions
670670 columnValue = expression ;
671671 } else {
672- columnValue = this . toColumnValue ( p , expression ) ;
672+ columnValue = this . toColumnValue ( p , expression , true ) ;
673673 }
674674 sqlExp = self . buildExpression ( columnName , operator , columnValue , p ) ;
675675 stmt . merge ( sqlExp ) ;
@@ -711,13 +711,15 @@ PostgreSQL.prototype._buildWhere = function(model, where) {
711711 * Convert property name/value to an escaped DB column value
712712 * @param {Object } prop Property descriptor
713713 * @param {* } val Property value
714+ * @param {boolean } isWhereClause
714715 * @returns {* } The escaped value of DB column
715716 */
716- PostgreSQL . prototype . toColumnValue = function ( prop , val ) {
717+ PostgreSQL . prototype . toColumnValue = function ( prop , val , isWhereClause ) {
717718 if ( val == null ) {
718719 // PostgreSQL complains with NULLs in not null columns
719720 // If we have an autoincrement value, return DEFAULT instead
720- if ( prop . autoIncrement || prop . id ) {
721+ // Do not return 'DEFAULT' for id field in where clause
722+ if ( prop . autoIncrement || ( prop . id && ! isWhereClause ) ) {
721723 return new ParameterizedSQL ( 'DEFAULT' ) ;
722724 } else {
723725 return null ;
0 commit comments