I expected this to be simple, but I've tried multiple combinations and I can't get PostgreSQL to accept them. It claims there are no matching functions, yet the types listed (as seen in the example below) clearly matches my defined function.
List of data types
Schema | Name | Internal name | Size | Elements | Access privileges | Description
--------+--------+---------------+------+----------+-------------------+-------------
public | levels | levels | 4 | debug +| |
| | | | info +| |
| | | | warn +| |
| | | | critical | |
CREATE FUNCTION public."logEvent"(IN in_type text,IN in_priority public.levels,IN in_message text)
RETURNS void
LANGUAGE 'sql'
NOT LEAKPROOF
AS $function$
INSERT INTO public.log (type,priority,message) VALUES (in_type, in_priority, in_message);
$function$;
The failing query:
SELECT 1 FROM public.logEvent('test'::text,'debug'::public.levels,'test from sql prompt'::text);
ERROR: function public.logevent(text, levels, text) does not exist
LINE 1: SELECT 1 FROM public.logEvent('test'::text,'debug'::public.l...
^
HINT: No function matches the given name and argument types. You might need to add explicit type casts.
An alternate function definition: I get the same error when trying to execute this create function call:
CREATE FUNCTION public."logEvent"(IN in_type text, IN in_priority text, IN in_message text)
RETURNS boolean
LANGUAGE 'sql'
NOT LEAKPROOF
AS $function$
SELECT public.logEvent( in_type, CAST(lower(in_priority) AS public.levels), in_message);
$function$;
Are you aware that double-quoted identifiers are case-sensitive?
CREATE FUNCTION public."logEvent"
But:
SELECT 1 FROM public.logEvent
This should work:
SELECT 1 FROM public."logEvent"('test', 'debug', 'test from sql prompt');
Explicit type casts are only necessary if there can be ambiguity with overloaded function.
Either keep double-quoting "logEvent"
for the rest of its existence, or (smarter) use unquoted (effectively lower-case), legal identifiers.