prisma / quaint

SQL Query AST and Visitor for Rust
Apache License 2.0
583 stars 62 forks source link

fix: json_extract ::jsonb casting with equality #295

Closed Weakky closed 3 years ago

Weakky commented 3 years ago

Overview

With postgres, when rendering an equals, if the right value is a Json value, the left value gets casted to a ::jsonb.

This was causing issues with json_extract because it's rendered as such: col#>ARRAY['a','b']::text.

Appending ::jsonb to col#>ARRAY['a','b']::text, was causing an error. This fix adds parenthesis around col#>ARRAY['a','b']::text so that the whole expression properly gets casted as (col#>ARRAY['a','b']::text)::jsonb.

A regression test was also added.