[PostgreSQL] Comparing jsonb columns to string values in WHERE statements
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 30/100
- Tipo di issue
- Bug
- Chiarezza
- Da chiarire
- Stato di attività
- Ferma
- Stack tecnologico
- fsharp, postgresql
- Ambito
- databases
Direzione di ricerca
Inizia tracciando la funzione filterBuilder e il modo in cui vengono gestiti i tipi PostgreSQL trattati come stringhe. Confronta i due approcci di uguaglianza proposti jsonb-to-text e text-to-jsonb, inclusi i casi di JSON non validi e semanticamente equivalenti. Il lavoro è completato quando il comportamento scelto previene l’errore segnalato jsonb = text senza nascondere i confronti non validi.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
... 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 = =
);
- Lingua principale
- F#
- Stelle
- 627
- Fork
- 147
- Merge medio
- 2h 2m
- PR unite (30g)
- 1
Guida per i contributori
Nessuna guida per i contributori indicizzata per questo repository
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di fsprojects/SQLProvider
-
enhancement
Difficoltà 3/5 1-2 giorni Idoneità per principianti 55/100
fsprojects/SQLProvider#872 · 2 commenti ·
-
Repo Assist? Apertaenhancement
Difficoltà 5/5 Più di una settimana Idoneità per principianti 10/100
fsprojects/SQLProvider#870 · 1 commento ·
-
postgresql
Difficoltà 4/5 3-5 giorni Idoneità per principianti 58/100
fsprojects/SQLProvider#869 · 2 commenti ·
-
documentation
Difficoltà 2/5 1-3 ore Idoneità per principianti 42/100
fsprojects/SQLProvider#868 · 2 commenti ·
-
sql server
Difficoltà 4/5 3-5 giorni Idoneità per principianti 45/100
fsprojects/SQLProvider#851 · 1 commento ·
Tutte le issue di fsprojects/SQLProvider
Issue simili
-
Add: New Channel Pop! Apertachannels:add check:passed
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 90/100
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
confluentinc/dbt-confluent#160 ·
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 75/100
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
AstrBotDevs/AstrBot#10205 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100