[PostgreSQL] Comparing jsonb columns to string values in WHERE statements
Personne n'a encore pris cette issue.
Évaluation
- Difficulté
- 4/5
- Temps estimé
- 3-5 jours
- Accessibilité débutants
- 30/100
- Type d'issue
- Bug
- Clarté
- À clarifier
- Activité
- À l'abandon
- Stack technique
- fsharp, postgresql
- Domaine
- databases
Piste de recherche
Commencez par suivre la fonction filterBuilder et la manière dont sont traités les types PostgreSQL considérés comme des chaînes. Comparez les deux approches d’égalité proposées jsonb-to-text et text-to-jsonb, y compris les cas de JSON invalides et sémantiquement équivalents. Le travail est considéré comme terminé lorsque le comportement choisi empêche l’erreur signalée jsonb = text sans masquer les comparaisons invalides.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Description
... 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 = =
);
- Langage dominant
- F#
- Étoiles
- 627
- Forks
- 147
- Merge moyen
- 2 h 2 min
- PR mergées (30 j)
- 1
Guide de contribution
Aucun guide de contribution indexé pour ce dépôt
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Autres issues de fsprojects/SQLProvider
-
enhancement
Difficulté 3/5 1-2 jours Accessibilité débutants 55/100
fsprojects/SQLProvider#872 · 2 commentaires ·
-
Repo Assist? Ouverteenhancement
Difficulté 5/5 Plus d'une semaine Accessibilité débutants 10/100
fsprojects/SQLProvider#870 · 1 commentaire ·
-
postgresql
Difficulté 4/5 3-5 jours Accessibilité débutants 58/100
fsprojects/SQLProvider#869 · 2 commentaires ·
-
documentation
Difficulté 2/5 1-3 heures Accessibilité débutants 42/100
fsprojects/SQLProvider#868 · 2 commentaires ·
-
sql server
Difficulté 4/5 3-5 jours Accessibilité débutants 45/100
fsprojects/SQLProvider#851 · 1 commentaire ·
Toutes les issues de fsprojects/SQLProvider
Issues similaires
-
Difficulté 2/5 1-3 heures Accessibilité débutants 86/100
-
Code path without return value Ouverte
Difficulté 2/5 1-3 heures Accessibilité débutants 78/100
drogonframework/drogon#2605 ·
-
Add: Big boss telugu 10 24/7 Ouvertechannels:add check:failed
Difficulté 2/5 1-3 heures Accessibilité débutants 68/100
-
needs-triage Platform(Default)
Difficulté 2/5 1-3 heures Accessibilité débutants 78/100
-
Difficulté 2/5 1-3 heures Accessibilité débutants 72/100
ietf-tools/reef#42 ·