-
BackendPostgreSQL Diesel version2.3.2 Diesel Features"image","openjp2","jpegxl","charls" Operating System VersionUbuntu 25.04 Third party librariesserde = { version = "1.0.228", features = ["derive"] } serde_json = "1.0.145" What do you want to do?I have a database table that has a JSONB columns. That column contains DICOM-tags in form of a DICOM-JSON (see https://dicom.nema.org/medical/dicom/current/output/chtml/part18/sect_f.2.html). See this entry for example: {
"00080005": {
"vr": "CS",
"Value": [
"ISO_IR 100"
]
},
"00080008": {
"vr": "CS",
"Value": [
"ORIGINAL",
"PRIMARY",
"AXIAL",
"CT_SOM5 SPI"
]
},
"00080016": {
"vr": "UI",
"Value": [
"1.2.840.10008.5.1.4.1.1.2"
]
},
"00080018": {
"vr": "UI",
"Value": [
"1.2.826.0.1.3680043.2.473.2.3472463830.1692.1087912327.528"
]
},
"00080021": {
"vr": "DA",
"Value": [
"20010327"
]
},
"00080022": {
"vr": "DA",
"Value": [
"20010327"
]
},
"00321060": {
"vr": "LO",
"Value": [
"CT Thorax"
]
}
}My goal is to query for rows that contain a specific tag. E.g. i filter for a date like this: "00080022": {
"vr": "DA",
"Value": [
"20010327"
]
},Compile time errorno compilation issue What code do you already have?pub async fn list_with_criteria(
conn: &mut DbConn,
offset: i64,
limit: i64,
criteria: &InMemDicomObject,
) -> Result<Vec<(Patient, Study)>, diesel::result::Error> {
use crate::db::schema::study::dsl::*;
let json = serde_json::to_value(DicomJson::from(criteria)).unwrap();
study
.filter(tags.contains(&json))
.inner_join(crate::db::schema::patient::table)
.order_by((study_date.desc(), study_time.desc()))
.offset(offset)
.limit(limit)
.select((Patient::as_select(), Study::as_select()))
.load(conn)
.await
}
`tags` is my JSONB column in this case. My idea was to use the `contains` method to check if the column contains the json that i am looking for. However this always yields an empty response. How do I filter against a JSONB column correctly?Additional detailsNo response Checklist
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
|
So I tried it locally on a psql command line with a test table and the provided data. The following query works for me: select * from study where tags @> '{"00080022": {
"vr": "DA",
"Value": [
"20010327"
]
}}'This is also what is constructed by your DSL (beside the join/limit/offset); I do not know which data are in your table or what other constraints exists so I can only guess why the query is returning no results for you. The most likely reason is that the You can and should check if the query looks correct via |
Beta Was this translation helpful? Give feedback.
So I tried it locally on a psql command line with a test table and the provided data.
The following query works for me:
This is also what is constructed by your DSL (beside the join/limit/offset);
I do not know which data are in your table or what other constraints exists so I can only guess why the query is returning no results for you. The most likely reason is that the
INNER JOINfilters out all results for whatever reason.You can and should check if the query looks correct via
diesel::debug_query(). That should also allow you to inspect which part of the q…