pg-mem icon indicating copy to clipboard operation
pg-mem copied to clipboard

Any-Type

Open Zomono opened this issue 5 months ago • 0 comments

Some of my postgresql-functions that I want to reimplement in pg-mem using registerFunction do not have a concrete type. They either accept any type and do some generic stuff or they accept multiple different types at the same argument position.

Here are some examples:

  • jsonb_build_object: accepts a variadic number of arguments of any type and returns json.
  • dateOrTimeToString: accepts string, date, timestamp, timestamptz and returns string
  • toTemplateString: accepts 4 arguments of any type and combines them into a string-template.

It is an old code base, so it is not an option to modify the production code with alternative sql-implementations.

What I like to do instead is something like this:

const db = newDb({});
db.public.registerFunction({
    name: 'jsonb_build_object',
    argsVariadic: DataType.any,
    returns: DataType.json,
    implementation: ...
})
db.public.registerFunction({
    name: 'toTemplateString',
    args: [DataType.any, DataType.any, DataType.any, DataType.any]
    returns: DataType.string,
    implementation: ...
})

Zomono avatar Sep 09 '25 06:09 Zomono