-
-
Notifications
You must be signed in to change notification settings - Fork 107
New issue
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
PostgreSQL json fields, how to use them? #252
Comments
Because keys are always quoted, I think the best way is to use Nette\Database\SqlLiteral $db->query('SELECT * FROM log WHERE', [
new SqlLiteral("data->>'code' = ?", [2]),
]); |
Maybe you're right. I just don't like how the resulting code looks in case of complex queries. $i = 0;
foreach ($keyIds as $key) {
$literal = [
$this->db::literal("data->>'code' = ?", $event),
$this->db::literal("data->'data'->>'key' = ?", $key),
];
if ($result) {
$literal[] = $this->db::literal("data->'data'->>'result'", $result);
}
$params[$i++] = $this->db::literal('?and', $literal);
}
$this->query($sql, $this->db::literal('?and', $params)); instead of foreach ($keyIds as $key) {
$params = [
"data->>'ev_code'" => $event,
"data->'data'->>'key'" => $key,
];
if ($result) {
$params[] = ["data->data'->>'result'" => $result];
}
}
$this->query($sql, ...$params); |
Yes, problem is that |
I have similar problem. When filtering with |
Version: 3.0.5
Bug Description
I want to use json field in WHERE
Steps To Reproduce
Create simple table:
Try to run query:
Expected Behavior
Result SQL must be (query in postgres_query.log)
but I got
Possible Solution
Nette need to somehow avoid quotes in the name of such fields
The text was updated successfully, but these errors were encountered: