-
-
Notifications
You must be signed in to change notification settings - Fork 104
Open
Description
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: ...
})
Metadata
Metadata
Assignees
Labels
No labels