How to find out the function used by postgresql to perform type casting?

How could one define the function used by postgresql to perform type casting?

EG: If I have SELECT '{1,2,3}' :: int4 [], how do I determine which function postgresql uses to perform casting? Running \ dC in psql doesn't seem to display a list in which the target data type is int4 [].

+4
source share
2 answers

A completely elite way is to do SET debug_print_parse TO on; or SET debug_print_plan TO on; and then view the parse or plan tree in the log of the server for which the function is being called.

In this specific example, this will tell you that what you wrote is not great, it just passes the string '{1,2,3}' to an input function like int4[] . There are other scenarios in which the translation function as such will not be called, such as binary compatible types or coercion using I / O functions.

+3
source

Jobs are stored in the system table, pg_casts . You may be able to trace it through the online documentation. pg_proc looks promising.

If you need to resort to reading the source code, try starting with pg_cast.h .

+1
source

Source: https://habr.com/ru/post/1368891/


All Articles