diff --git a/packages/server/src/integrations/base/sql.ts b/packages/server/src/integrations/base/sql.ts index bbb84b49cb..28d24645f7 100644 --- a/packages/server/src/integrations/base/sql.ts +++ b/packages/server/src/integrations/base/sql.ts @@ -176,7 +176,7 @@ class InternalBuilder { const columnName = fieldNames[1] // @ts-ignore query = query[rawFnc]( - `"${tableName}"."${columnName}"::jsonb @> ${stringifyArray(value)}` + `${not}"${tableName}"."${columnName}"::jsonb @> ${stringifyArray(value)}` ) }) } else if (this.client === SqlClients.MY_SQL) { diff --git a/packages/server/src/integrations/tests/sql.spec.js b/packages/server/src/integrations/tests/sql.spec.js index 865cf76e64..1dff477d9d 100644 --- a/packages/server/src/integrations/tests/sql.spec.js +++ b/packages/server/src/integrations/tests/sql.spec.js @@ -315,7 +315,7 @@ describe("SQL query builder", () => { }) }) - it("should use jsonb operator expression for PostgreSQL when filter is notContains", () => { + it("should use jsonb operator NOT expression for PostgreSQL when filter is notContains", () => { const query = new Sql(SqlClients.POSTGRES, 10)._query(generateReadJson({ filters: { notContains: { @@ -326,7 +326,7 @@ describe("SQL query builder", () => { })) expect(query).toEqual({ bindings: [10], - sql: `select * from (select * from \"${TABLE_NAME}\" where \"${TABLE_NAME}\".\"age\"::jsonb @> '[20]' and \"${TABLE_NAME}\".\"name\"::jsonb @> '["John"]' limit $1) as \"${TABLE_NAME}\"` + sql: `select * from (select * from \"${TABLE_NAME}\" where NOT \"${TABLE_NAME}\".\"age\"::jsonb @> '[20]' and NOT \"${TABLE_NAME}\".\"name\"::jsonb @> '["John"]' limit $1) as \"${TABLE_NAME}\"` }) }) })