From: | Mike Toews <mwtoews(at)gmail(dot)com> |
---|---|
To: | pgsql-hackers(at)postgresql(dot)org |
Subject: | Function argument names in pg_catalog |
Date: | 2011-07-19 11:23:24 |
Message-ID: | CAM2FmMqWhwZOMpL5BoVROmGXWS6U=ngBUTFEgk_1AfgXpauguA@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
Hi hackers,
I'm curios why argument names (argname) are not used in the DDL for
functions in pg_catalog, while they are are used throughout the
documentation. For example, the documentation for pg_read_file in
Table 9-60[1] has an "SQL prototype":
pg_read_file(filename text, offset bigint, length bigint)
then why isn't the DDL for the function instead something like:
CREATE OR REPLACE FUNCTION
public.pg_read_file(filename text, "offset" bigint, length bigint)
RETURNS text AS 'pg_read_file'
LANGUAGE internal VOLATILE STRICT COST 1;
There are two advantages for using argument names for function
definitions: to add extra documentation for the parameters, and allow
named notation (where applicable).
For the "extra documentation"[2] point, the "SQL prototype" is visible
in PgAdmin or psql. For example, with the above example try "\df
public.pg_read_file", the fourth column shows 'filename text, "offset"
bigint, length bigint' in the fourth column. The existing "\df
pg_catalog.pg_read_file" returns "text, bigint, bigint", which sends
the user to look up the function in the documentation to determine
which bigint parameter is for "length" or "offset". Having built-in
extra documentation saves this trip.
For the named notation[3] rational, a user can rearrange the arguments:
select public.pg_read_file("offset" := 200, length := 10, filename := 'myfile')
or more practically, if parameters in the function were defined with
default_expr, then the named parameters can be used while omitting
default_expr parameters to accept defaults.
Are there any drawbacks? Performance/bloat? Technical limitations?
Apologies for my ignorance on how the DDL for functions in pg_catalog
are defined. I can only assume they are generated from their internal
C functions, as I can't find a pg_catalog.sql file in the source.
Thanks for your thoughts,
-Mike
[1] http://www.postgresql.org/docs/current/static/functions-admin.html
[2] http://www.postgresql.org/docs/current/static/sql-createfunction.html
[3] http://www.postgresql.org/docs/current/static/sql-syntax-calling-funcs.html
From | Date | Subject | |
---|---|---|---|
Next Message | Simon Riggs | 2011-07-19 12:09:23 | Re: Cascade replication |
Previous Message | Fujii Masao | 2011-07-19 11:19:40 | Re: Cascade replication |