Issue with json object prop query

This will work but I cant make the 'slug' dynamic
// This works
sql`categories_subquery.categories::jsonb @> jsonb_build_array(jsonb_build_object('slug', ${filter.value}::text))`;

// dont work (where categories_subquery.categories::jsonb @> jsonb_build_array(jsonb_build_object($1, $2::text))',
// params: [ 'slug', 'cabello' ]
// error: could not determine data type of parameter $1)
sql`categories_subquery.categories::jsonb @> jsonb_build_array(jsonb_build_object(${filter.column}, ${filter.value}::text))`;
// doesnt work either it get replaced as "slug" so I get column reference "slug" is ambiguous

sql`categories_subquery.categories::jsonb @> jsonb_build_array(jsonb_build_object(${sql.identifier(filter.column)}, ${filter.value}::text))`
// This works
sql`categories_subquery.categories::jsonb @> jsonb_build_array(jsonb_build_object('slug', ${filter.value}::text))`;

// dont work (where categories_subquery.categories::jsonb @> jsonb_build_array(jsonb_build_object($1, $2::text))',
// params: [ 'slug', 'cabello' ]
// error: could not determine data type of parameter $1)
sql`categories_subquery.categories::jsonb @> jsonb_build_array(jsonb_build_object(${filter.column}, ${filter.value}::text))`;
// doesnt work either it get replaced as "slug" so I get column reference "slug" is ambiguous

sql`categories_subquery.categories::jsonb @> jsonb_build_array(jsonb_build_object(${sql.identifier(filter.column)}, ${filter.value}::text))`
1 Reply
DoggeSlapper
DoggeSlapperOP4mo ago
so far then only option I have seen is using sql.raw
Want results from more Discord servers?
Add your server