@@ -644,10 +644,10 @@ PostgreSQL.prototype._buildWhere = function(model, where) {
644
644
if ( Array . isArray ( expression ) ) {
645
645
// Column value is a list
646
646
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 ) ) ;
648
648
}
649
649
} else {
650
- columnValue . push ( this . toColumnValue ( p , expression ) ) ;
650
+ columnValue . push ( this . toColumnValue ( p , expression , true ) ) ;
651
651
}
652
652
if ( operator === 'between' ) {
653
653
// BETWEEN v1 AND v2
@@ -669,7 +669,7 @@ PostgreSQL.prototype._buildWhere = function(model, where) {
669
669
// do not coerce RegExp based on property definitions
670
670
columnValue = expression ;
671
671
} else {
672
- columnValue = this . toColumnValue ( p , expression ) ;
672
+ columnValue = this . toColumnValue ( p , expression , true ) ;
673
673
}
674
674
sqlExp = self . buildExpression ( columnName , operator , columnValue , p ) ;
675
675
stmt . merge ( sqlExp ) ;
@@ -711,13 +711,15 @@ PostgreSQL.prototype._buildWhere = function(model, where) {
711
711
* Convert property name/value to an escaped DB column value
712
712
* @param {Object } prop Property descriptor
713
713
* @param {* } val Property value
714
+ * @param {boolean } isWhereClause
714
715
* @returns {* } The escaped value of DB column
715
716
*/
716
- PostgreSQL . prototype . toColumnValue = function ( prop , val ) {
717
+ PostgreSQL . prototype . toColumnValue = function ( prop , val , isWhereClause ) {
717
718
if ( val == null ) {
718
719
// PostgreSQL complains with NULLs in not null columns
719
720
// 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 ) ) {
721
723
return new ParameterizedSQL ( 'DEFAULT' ) ;
722
724
} else {
723
725
return null ;
0 commit comments