Andrew Hammond escribió:
> Ok, I've been hunting through src/backend to try and find the code for
> EXTRACT(epoch ...). I found EXTRACT in src/backend/parser/gram.y, which
> seems like a reasonable place to start.
>
> | EXTRACT '(' extract_list ')'
> {
> FuncCall *n = makeNode(FuncCall);
> n->funcname = SystemFuncName("date_part");
> n->args = $3;
> n->agg_star = FALSE;
> n->agg_distinct = FALSE;
> n->location = @1;
> $$ = (Node *)n;
> }
>
> Which got me looking for "date_part". But that only seems to be in the
> gram.y file, include/catalog/pg_proc.h and the test suite. The pg_proc.h
> stuff looks pretty interesting, but to decipher it, I figured I need to read
> up on SystemFuncName().
That's where you got lost -- if you had looked at the pg_proc.h entries
more carefully you would have seen that they point to other functions,
like timestamptz_part and friends. You can find them on timestamp.c,
etc. The key is knowing that the pg_proc.h entry maps from a SQL
function name into a C function name.
--
Alvaro Herrera http://www.amazon.com/gp/registry/DXLWNGRJD34J
"La naturaleza, tan frágil, tan expuesta a la muerte... y tan viva"