Skip to content
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

Closed
ArdentZeal opened this issue Jul 28, 2015 · 1 comment
Closed

postgres arrays are stringified wrong #920

ArdentZeal opened this issue Jul 28, 2015 · 1 comment

Comments

@ArdentZeal
Copy link

@ArdentZeal ArdentZeal commented Jul 28, 2015

Hello,

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])
...
.toString()

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

 _strucd.knex().debug()
                        .select(_strucd.knex.raw('date, ' + UserListDataController._buildGraphSelectStringFromElementsPostgresql(list, elementsWithEC, elementcategories, graphParameters)))
                        .from(_strucd.knex.raw(utils.__buildGenerateSeriesString(columnName, interval, generateIntervalMin, generateIntervalMax)))
                        .leftOuterJoin(
                            _strucd.knex.raw(
                                '(' +
                                _strucd.knex(tableName)
                                    .select(_strucd.knex.raw(utils.__buildGraphSubquerySelectDateString(columnName, interval) + ', ' + UserListDataController._buildGraphSubquerySelectStringFromElementsPostgresql(list, elementsWithEC, elementcategories, graphParameters)))
                                    .whereNull('deprecated_at')
                                    .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) {
                            console.log(results);
                            return callback(null, results);
                        })
                        .catch(function(err) {
                            return callback(err);
                        });
tgriesser added a commit that referenced this issue Oct 12, 2016
* 0.12.x:
  release 0.12.4
  Updating/pruning some deps
  Fix #1733, #920, incorrect postgres array bindings
rslabbert added a commit to rslabbert/knex that referenced this issue Nov 9, 2016
@wubzz
Copy link
Member

@wubzz wubzz commented Feb 16, 2018

Seems fixed according to commits and tests on knexjs.org

@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
Labels
None yet
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants