We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
Simple object with integer[] type of one field
var Table = sql.define({ schema: 'tests', name: 'objects', columns: [ 'id', 'some_field' // type - integer[] ] });
var query = Table.select().from(Table) .where( items.some_field.contains(sql.array(123, 456)) ) .toQuery();
Query generates:
{ text: 'SELECT "tests"."objects".* FROM "tests"."objects" WHERE ("tests"."objects"."some_field" @> ARRAY[$1, $2])', values: [ 123, 456 ] }
But when send query to postgres by
client.query(query.text, query.values)
Its generate type cast error:
error: operator does not exist: integer[] @> text[]
The text was updated successfully, but these errors were encountered:
Anybody?
Sorry, something went wrong.
I am experiencing this as well, however I think the root cause is within the pg module, specifically this issue: brianc/node-postgres#220.
The thread suggests monkey-patching https://github.com/brianc/node-postgres/blob/715e5009dde23c0fb5b127f9b536aa6ed5245fc2/lib/utils.js#L30, I'm not sure if that's still the only solution.
My solution is to try guess the type by first value:
Postgres.prototype.visitArrayCall = function(arrayCall) { var type = 'text'; if (arrayCall.nodes.length) { var test = arrayCall.nodes[0].value(); if ('number' === typeof test) type = !!(test % 1) ? 'double precision' : 'integer'; } var txt = 'ARRAY[' + arrayCall.nodes.map(this.visit.bind(this)).join(', ') + ']::' + type + '[]'; return [txt]; };
No branches or pull requests
Simple object with integer[] type of one field
Query generates:
But when send query to postgres by
Its generate type cast error:
The text was updated successfully, but these errors were encountered: