Skip to content

Any-Type #466

@Zomono

Description

@Zomono

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

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions