Home > Back-end >  How to wrap record_out() function?
How to wrap record_out() function?

Time:06-02

I'd like to create an IMMUTABLE wrapper function as discussed by https://stackoverflow.com/a/11007216/14731 but it's not clear how to proceed. The above Stackoverflow answer provides the following example:

For example, given:

CREATE OR REPLACE FUNCTION public.immutable_unaccent(regdictionary, text)
  RETURNS text LANGUAGE c IMMUTABLE PARALLEL SAFE STRICT AS
'$libdir/unaccent', 'unaccent_dict';

CREATE OR REPLACE FUNCTION public.f_unaccent(text)
  RETURNS text LANGUAGE sql IMMUTABLE PARALLEL SAFE STRICT AS
$func$
SELECT public.immutable_unaccent(regdictionary 'public.unaccent', $1)
$func$;

I scanned all the libraries in lib/ and as far as I can tell none of them export functions related to record_out(). Any ideas?

CodePudding user response:

The record_out() function is an internal built-in function. You can get its definition like this:

select pg_get_functiondef('record_out'::regproc);

                    pg_get_functiondef
----------------------------------------------------------
 CREATE OR REPLACE FUNCTION pg_catalog.record_out(record) 
  RETURNS cstring                                         
  LANGUAGE internal                                       
  STABLE PARALLEL SAFE STRICT                             
 AS $function$record_out$function$                        

I don't know for what purpose you want the wrapping function. It only remains to warn that such a change may bring unexpected results.

  • Related