functions.create/retrieve fails for multi-word argument types

Open Beginner friendly
#1,146 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
78/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
postgresql, typescript
Domain
api, databases

Research direction

Start at the functions.retrieve argument-type resolution path, then check how functions.create retrieves the newly created function. Reproduce the issue with double precision and timestamp with time zone arguments, and verify that full type names resolve while an optional leading argument name is ignored.

Written by the indexing model from the issue text.

Description

Bug

functions.retrieve({ args }) (and therefore functions.create, which retrieves after create) resolves each arg to a type by taking only the last space-separated token and casting it to regtype:

STRING_TO_ARRAY(arg, ' ')[last]::regtype

That breaks SQL-standard multi-word types:

arg last token result
double precision precision invalid type name "precision"
timestamp with time zone zone error
x double precision precision error

Repro

await pgMeta.functions.create({
  name: 'test_multiword_arg',
  schema: 'public',
  args: ['x double precision', 'ts timestamp with time zone'],
  definition: 'select x',
  return_type: 'double precision',
  language: 'sql',
  behavior: 'STABLE',
  security_definer: false,
})
// CREATE succeeds; retrieve-by-args fails → create returns an error

Expected

Args should resolve using the full type name (and drop only an optional leading parameter name), so Studio/API can create and look up functions with common SQL types.

Dominant language
TypeScript
Stars
1.2k
Forks
223
PR merge metrics
No merged PRs in 30d

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from supabase/postgres-meta

All issues in supabase/postgres-meta

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.