From bb4f8b1c668c1ef60ab00282192e6a48fc99472e Mon Sep 17 00:00:00 2001 From: Henry Su Date: Sun, 23 Aug 2026 11:42:55 -0500 Subject: [PATCH] fix: retrieve the zero-argument function overload when args is empty functions.retrieve skipped the proargtypes filter for args: [], so overloaded names could return the wrong signature. --- src/lib/sql/functions.sql.ts | 12 +++++------- test/lib/functions.ts | 16 ++++++++++++++++ 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/src/lib/sql/functions.sql.ts b/src/lib/sql/functions.sql.ts index ea41d5e1..b51054ce 100644 --- a/src/lib/sql/functions.sql.ts +++ b/src/lib/sql/functions.sql.ts @@ -38,10 +38,9 @@ with functions as ( ${ props.args === undefined ? '' - : props.args.length > 0 - ? `p.proargtypes::text = ${ - props.args.length - ? `( + : `p.proargtypes::text = ${ + props.args.length > 0 + ? `( SELECT STRING_AGG(type_oid::text, ' ') FROM ( SELECT ( split_args.arr[ @@ -60,9 +59,8 @@ with functions as ( ) AS split_args ) args )` - : "''" - } AND` - : '' + : "''" + } AND` } p.prokind = 'f' ) diff --git a/test/lib/functions.ts b/test/lib/functions.ts index ce26e078..7d0d63a6 100644 --- a/test/lib/functions.ts +++ b/test/lib/functions.ts @@ -531,3 +531,19 @@ test('retrieve function by args filter - function with no arguments', async () = }) expect(res.error).toBeNull() }) + +test('retrieve function by args filter - zero-argument overload among polymorphic functions', async () => { + const res = await pgMeta.functions.retrieve({ + schema: 'public', + name: 'polymorphic_function_with_no_params_or_unnamed', + args: [], + }) + expect(res.error).toBeNull() + expect(res.data).toMatchObject({ + name: 'polymorphic_function_with_no_params_or_unnamed', + schema: 'public', + argument_types: '', + args: [], + return_type: 'integer', + }) +})