[PostgreSQL] Comparing jsonb columns to string values in WHERE statements
まだ誰も着手していません。
評価
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 初心者へのやさしさ
- 30/100
- issue の種類
- バグ
- 明瞭さ
- 説明が足りない
- 活発さ
- 停滞
- 技術スタック
- fsharp, postgresql
- 領域
- databases
調査の方向性
まず filterBuilder function と、文字列として扱われる PostgreSQL types の処理方法を追跡します。jsonb-to-text と text-to-jsonb の2つの equality approaches を、invalid な JSON と semantically equivalent な JSON のケースを含めて比較します。完了条件は、選択した動作によって報告された jsonb = text error が防止され、invalid な比較が隠蔽されないことです。
索引モデルが issue の本文から書いたものです。
説明
... results in an error "operator does not exist: jsonb = text".
This is because the filterBuilder function does not add a type cast for PostgreSQL types which are treated as strings .NET-side, such as jsonb.
Workaround: define a jsonb -> text -> bool equality function in your database schema, then associate it to the = operator (or invoke it explicitly).
However, there are two ways to define this equality:
-
Cast the jsonb column to text. This will never fail, however it may return
falseif the resulting text differs from the parameter in semantically-insignificant ways, such as whitespace, or the ordering of JSON properties -
Cast the text value to jsonb. This will perform a proper semantic comparison, but will throw an exception if the text isn't valid JSON - and I can imagine instances where you may want to check an unknown (user-provided?) text against a stored JSON value. Note that an empty string is not valid json.
If I implement this in a PR (which may be tricky, as filterBuilder doesn't seem to have access to the column type), which approach do you think should be taken? I strongly believe that the latter is the better one (because any failures will be immediately obvious rather than stealthy, and because both F# and PostgreSQL have a culture of correctness over permissiveness), but I'm throwing it out there in case people have different opinions.
Below an example of the workaround above, for anybody who may run into this issue:
create or replace function jsonb_compare(j jsonb, t text)
returns bool
as $$ select (j=t::jsonb)
$$ language sql;
create or replace function jsonb_compare_2(t text, j jsonb)
returns bool
as $$ select (j=t::jsonb)
$$ language sql;
create operator = (
leftarg = jsonb,
rightarg = text,
procedure = jsonb_compare,
commutator = =
);
create operator = (
leftarg = text,
rightarg = jsonb,
procedure = jsonb_compare_2,
commutator = =
);
- 主要言語
- F#
- スター
- 627
- フォーク
- 147
- 平均マージ
- 2時間 2分
- マージ済み PR(30日)
- 1
コントリビューションガイド
このリポジトリのコントリビューションガイドは索引されていません
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
fsprojects/SQLProvider のほかの issue
-
enhancement
難易度 3/5 1〜2日 初心者へのやさしさ 55/100
fsprojects/SQLProvider#872 · コメント 2 件 ·
-
Repo Assist? オープンenhancement
難易度 5/5 1週間以上 初心者へのやさしさ 10/100
fsprojects/SQLProvider#870 · コメント 1 件 ·
-
postgresql
難易度 4/5 3〜5日 初心者へのやさしさ 58/100
fsprojects/SQLProvider#869 · コメント 2 件 ·
-
documentation
難易度 2/5 1〜3時間 初心者へのやさしさ 42/100
fsprojects/SQLProvider#868 · コメント 2 件 ·
-
sql server
難易度 4/5 3〜5日 初心者へのやさしさ 45/100
fsprojects/SQLProvider#851 · コメント 1 件 ·
fsprojects/SQLProvider の issue をすべて見る
似ている issue
-
難易度 1/5 1時間未満 初心者へのやさしさ 75/100
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 88/100
AstrBotDevs/AstrBot#10205 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
OHDSI/Data2Evidence#3394 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 84/100