Proper string-escapes for Postgres #1548
Currently, knex tries to use backslashes to escape various characters in string literals for Postgres. The problem is, that Postgres doesn't interpret slashes in string literals by-default since version 9.1. It is possible to enable interpretation by setting
Strictly speaking, usage of regular string-literals is just not a predictable option anymore.
The proper solution is: use non-standard
The text was updated successfully, but these errors were encountered:
So I'll just open up your example a bit to understand it better... Input
But it is true that knex also has its own escaping function, which should work correctly. Which currently indeed replaces \ with \
> knex('dodo').where('name', 'hell\\"o there').toString() 'select * from "dodo" where "name" = \'hell\\\\"o there\''
Which really seem to result invalid string in database (too many backslashes...):
So... we seem to need own string escaping function for postgres or change some other part of string literal interpolation to use E'' literals.
ps. also how
* Modify test suite to test #1602 We shouldn’t be testing the “default” client class. Replace any usages with postgresql * Simplify knex.raw, deprecate global Knex.raw usage * Remove unused bluebird shim * Remove old / unused test comments * Don't capture Pool2 error event * Fix pg string escaping & parameterization #1602, #1548