[PostgreSQL] Comparing jsonb columns to string values in WHERE statements
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Aptitud para principiantes
- 30/100
- Tipo de issue
- Error
- Claridad
- Necesita aclaración
- Estado de actividad
- Estancado
- Stack tecnológico
- fsharp, postgresql
- Área
- databases
Línea de trabajo
Comienza rastreando la función filterBuilder y cómo se manejan los tipos de PostgreSQL tratados como cadenas. Compara los dos enfoques de igualdad propuestos jsonb-to-text y text-to-jsonb, incluidos los casos de JSON no válido y semánticamente equivalentes. Se considera terminado cuando el comportamiento elegido evita el error reportado jsonb = text sin ocultar las comparaciones no válidas.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
... 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 = =
);
- Lenguaje dominante
- F#
- Estrellas
- 627
- Forks
- 147
- Merge medio
- 2 h 2 min
- PR fusionados (30 d)
- 1
Guía de contribución
No hay ninguna guía de contribución indexada para este repositorio
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de fsprojects/SQLProvider
-
enhancement
Dificultad 3/5 1-2 días Aptitud para principiantes 55/100
fsprojects/SQLProvider#872 · 2 comentarios ·
-
Repo Assist? Abiertoenhancement
Dificultad 5/5 Más de una semana Aptitud para principiantes 10/100
fsprojects/SQLProvider#870 · 1 comentario ·
-
postgresql
Dificultad 4/5 3-5 días Aptitud para principiantes 58/100
fsprojects/SQLProvider#869 · 2 comentarios ·
-
documentation
Dificultad 2/5 1-3 horas Aptitud para principiantes 42/100
fsprojects/SQLProvider#868 · 2 comentarios ·
-
sql server
Dificultad 4/5 3-5 días Aptitud para principiantes 45/100
fsprojects/SQLProvider#851 · 1 comentario ·
Todos los issues de fsprojects/SQLProvider
Issues similares
-
Dificultad 1/5 Menos de una hora Aptitud para principiantes 75/100
-
bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 88/100
AstrBotDevs/AstrBot#10205 ·
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 70/100
OHDSI/Data2Evidence#3394 ·
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 84/100