K
Kysely4d ago
Vjau

could not determine data type of parameter $1

I am trying to nest PG functions array_agg and json_build_object I tried like this
select(({ fn, eb, val }) => {
return fn
.agg<
{
foo_col: string;
bar_col:string;
}[]
>("array_agg", [
eb.fn("json_build_object", [
val("foo_col"),
"sometable.foo",
val("bar_col"),
"sometable.bar",
]),
])
.as("objs")
select(({ fn, eb, val }) => {
return fn
.agg<
{
foo_col: string;
bar_col:string;
}[]
>("array_agg", [
eb.fn("json_build_object", [
val("foo_col"),
"sometable.foo",
val("bar_col"),
"sometable.bar",
]),
])
.as("objs")
However, i receive an error from Postgres could not determine data type of parameter $1 Looking at the compiled query, val("foo_col") seems to be replaced by $1 then applied as first param. Why are val values parameterized since they are pretty much static ? Why is postgres complaining about the type thing ? Thank you.
Solution:
Ok, perplexity gave me the answer. You have to cast the key names à string with cast(val("foo_col"), "text")...
Jump to solution
1 Reply
Solution
Vjau
Vjau4d ago
Ok, perplexity gave me the answer. You have to cast the key names à string with cast(val("foo_col"), "text")

Did you find this page helpful?