开发者

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

How would one go about determining the function used by postgresql to perform a type casting?

EG: If I have SELECT '{1,2,3}'::int4[], how do I determine which function is used by postgresql to perform the casting? Doing \dC within psql does not seem to list any casts that have the target data type being 开发者_运维百科int4[].


The totally elite way is to do SET debug_print_parse TO on; or SET debug_print_plan TO on; and then look at the parse or plan tree in the server log for which function ends up being called.

In this particular example, this will tell you that what you wrote isn't really a cast, it simply feeds the string '{1,2,3}' to the type input function of the type int4[]. There are other scenarios where a cast function as such won't be called, such as binary compatible types or coercion via I/O functions.


The casts are stored in a system table, pg_casts. You might be able to trace it through the online documentation. pg_proc looks promising.

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜