Conflict with Postgresql jsonb operators
See original GitHub issueHi!
I have sql:
SELECT id, name, price, files->'photos'->0->>'name' as photo, annotation
FROM product
WHERE tags ?& array['17']
ORDER BY (tags->>'17')::int
LIMIT 10
If i run this sql direct in postgresql client it work fine
If i run this sql through node-postgres it work fine again:
var pg = require('pg');
var connPg = "postgres://user:password@localhost/mydbname";
var clientPg = new pg.Client(connPg);
var sqlProductsByTags = [
"SELECT id, name, price, files->'photos'->0->>'name' as photo, annotation ",
"FROM product ",
"WHERE tags ?& array['17'] ",
"ORDER BY (tags->>'17')::int ",
"LIMIT 10 "
];
clientPg.connect(function(err) {
if(err) {
return console.error('could not connect to postgres', err);
}
//console.log('SQL = ' + sqlProductsByTags.join(''));
clientPg.query(sqlProductsByTags.join(''), function(err, result) {
if(err) {
return console.error('error select products by tags', err);
}
for(var i = 0, max = result.rows.length; i < max; i++) {
console.log('name: ' + result.rows[i].name);
}
clientPg.end();
});
});
If i run raw sql by knex, it fail with error (below listed):
var connPg = "postgres://user:password@localhost/mydbname";
var pg = require('knex')({
client: 'pg',
connection: connPg
});
var sqlProductsByTags = [
"SELECT id, name, price, files->'photos'->0->>'name' as photo, annotation ",
"FROM product ",
"WHERE tags ?& array['17'] ",
"ORDER BY (tags->>'17')::int ",
"LIMIT 10 "
];
pg.raw(sqlProductsByTags.join(''))
This Error
{ [error: syntax error (at or near "$1")]
name: 'error',
length: 142,
severity: 'ERROR',
code: '42601',
detail: undefined,
hint: undefined,
position: '98',
internalPosition: undefined,
internalQuery: undefined,
where: undefined,
file: 'scan.l',
line: '1053',
routine: 'scanner_yyerror' }
I think that it fail because of i used jsonb operator ‘?&’, precise only one symbol ‘?’ Reference to PostgreSQL JSONB operators
Issue Analytics
- State:
- Created 9 years ago
- Comments:33 (19 by maintainers)
Top Results From Across the Web
PostgreSQL param binding conflicts with JSONB operators
PostgreSQL param binding conflicts with JSONB operators ... I'm updating a JSONB field in my postgreSQL database (using PHP Symfony DBAL) ...
Read more >9.5: JSON Functions and Operators - PostgreSQL
The field/element/path extraction operators return the same type as their left-hand input (either json or jsonb), except for those specified as returning text, ......
Read more >Combining Postgres jsonb query statements
The trick here is to use jsonb_set using {commentid} as the path you want to construct (second argument) and the third argument as...
Read more >PostgreSQL JSON Functions & Operators: Types, Syntax ...
What are PostgreSQL JSON Operators? To help you query JSON data, PostgreSQL includes two native operators: -> and ->>. The JSON object field...
Read more >PostgreSQL anti-patterns: Unnecessary json/hstore dynamic ...
PostgreSQL has json support – but you shouldn't use it for the great majority of what you're doing. This goes for hstore too,...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
+1 for
??
@SeanCannon, in my codebase I saw this working just fine over a year ago after it was fixed. Chances are very good that if you’re seeing a similar issue, it is a new problem, not a continuation of this problem.
I suggest you create a new Issue, complete with the version of knex you’re using, example code that demonstrates the problem, and output of the error and/or expected vs actual results.