Moon_of_father
Moon_of_father

Reputation: 313

How to get the code of system functions in Postgres

How to get the definition of a system function? I mean the code of it.

Upvotes: 0

Views: 508

Answers (1)

Craig Ringer
Craig Ringer

Reputation: 324455

Get the oid of the system function with

SELECT 'funcname'::regproc::oid;

The result is a number like 2176.

Look in src/include/catalog/pg_proc.h for the oid. You'll see something like

DATA(insert OID = 2176 ....

The 4th-last entry is the C function name. It's not always the same as the SQL function name (2nd field) due to overloads etc.

Find the C procedure definition with git grep ^procname or using ctags/cscope eg vim -t procname.

Upvotes: 2

Related Questions