cube-js / cube-js/cube

Postgres filters use incorrect escape characters

Open
#9,989 3 comments 0 reactions 1 assignee Claimed by @igorlukanin View on GitHub
question
Dominant language
Rust
Stars
20.8k
Forks
2.1k
Avg merge
1d 2h
Merged PRs (30d)
181

Description

**Describe the bug**
In the postgres driver (newest - v1.3.72,, with Postgres 16.9) when using filters like contains or equals, the SQL is generated with `ESCAPE '\\'` . This results in an error:
```
"error": "Error: syntax error at or near \")\"\n
```
It seems that this is because there should be a single backslash.

**To Reproduce**
Steps to reproduce the behavior:
Create a postgres cube and execute a query using a contains filter.

**Expected behavior**
A clear and concise description of what you expected to happen.

We should be able to use contains/equals filters on a postgres connection.

**Screenshots**
If applicable, add screenshots to help explain your problem.

**Minimally reproducible Cube Schema**
In case your bug report is data modelling related please put your minimally reproducible Cube Schema here.
You can use selects without tables in order to achieve that as follows.

```javascript
cube(`Users`, {
sql: `
SELECT 1 as id, 'john.doe@example.com' as email
UNION ALL
SELECT 2 as id, 'jane.smith@example.com' as email
`,

dimensions: {
email: {
sql: `email`,
type: `string`
}
},

measures: {
count: {
type: `count`
}
}
});
```

And then query with:
```
{
"dimensions": ["Users.email"],
"filters": [{
"member": "Users.email",
"operator": "contains",
"values": ["example"]
}]
}
```

**Version:**
Using `1.3.72` for the server/core/postgres-driver with Postgres 16.9

**Additional context**
Add any other context about the problem here.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.