New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

postgres arrays are stringified wrong #920

ArdentZeal opened this Issue Jul 28, 2015 · 1 comment


None yet
2 participants

ArdentZeal commented Jul 28, 2015


I am using knex with a postgres database.

To build a subquery I am using knex to build the subquery. I am then using toString() method to put the query part into a strucd.knex.raw() which again is in a knex chain for the outer query. See full example below.

knex.where(columnName, '&&', [1,2,3])

knex turns the array into a valid postgresarray '{1,2,3}', but as soon as i call toString() it will be '{"1","2","3"}'.

So at the moment I have to put a .replace(/"/g, '') after each toString() just to circumvent that problem.

I would prefer knex handling that situation correctly instead of me hacking around it.

Kind Regards

Full example

                        .select(_strucd.knex.raw('date, ' + UserListDataController._buildGraphSelectStringFromElementsPostgresql(list, elementsWithEC, elementcategories, graphParameters)))
                        .from(_strucd.knex.raw(utils.__buildGenerateSeriesString(columnName, interval, generateIntervalMin, generateIntervalMax)))
                                '(' +
                                    .select(_strucd.knex.raw(utils.__buildGraphSubquerySelectDateString(columnName, interval) + ', ' + UserListDataController._buildGraphSubquerySelectStringFromElementsPostgresql(list, elementsWithEC, elementcategories, graphParameters)))
                                    .where(function() {
                                        UserListDataController.__buildFilterQuery(this, findParams.filter, list, elementsWithEC, elementcategories);
                                        UserListDataController.__buildInstantSearchQuery(this, findParams.instantSearch, list, elementsWithEC, elementcategories);
                                    .groupBy('interval').toString().replace(/\\"/g, '') +
                                    ') results'
                            'date', '=', 'results.interval'
                        .then(function(results) {
                            return callback(null, results);
                        .catch(function(err) {
                            return callback(err);

tgriesser added a commit that referenced this issue Oct 12, 2016

Merge branch '0.12.x'
* 0.12.x:
  release 0.12.4
  Updating/pruning some deps
  Fix #1733, #920, incorrect postgres array bindings

This comment has been minimized.


wubzz commented Feb 16, 2018

Seems fixed according to commits and tests on

@wubzz wubzz closed this Feb 16, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment