From f6885792b09fcca737b7bbc8ade4c09397443f17 Mon Sep 17 00:00:00 2001 From: Eric Perry Date: Tue, 12 Jan 2016 12:39:40 -0500 Subject: [PATCH] Correctly double quote strings within arrays for PG --- lib/dialect/postgres.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/lib/dialect/postgres.js b/lib/dialect/postgres.js index 7464ebf..764c98e 100644 --- a/lib/dialect/postgres.js +++ b/lib/dialect/postgres.js @@ -26,7 +26,7 @@ Postgres.prototype._getParameterText = function(index, value) { } }; -Postgres.prototype._getParameterValue = function(value) { +Postgres.prototype._getParameterValue = function(value, quoteChar) { // handle primitives if (null === value) { value = 'NULL'; @@ -36,12 +36,15 @@ Postgres.prototype._getParameterValue = function(value) { // number is just number value = value; } else if ('string' === typeof value) { - // string uses single quote - value = this.quote(value, "'"); + // string uses single quote by default + value = this.quote(value, quoteChar || "'"); } else if ('object' === typeof value) { if (_.isArray(value)) { // convert each element of the array - value = _.map(value, this._getParameterValue, this); + value = value.map(function (item) { + // In a Postgres array, strings must be double-quoted + return this._getParameterValue(item, '"'); + }); value = '\'{' + value.join(',') + '}\''; } else if (_.isFunction(value.toISOString)) { // Date object's default toString format does not get parsed well