Re: Attach comments to functions' parameters and return value - Mailing list pgsql-hackers
From | Charles Clavadetscher |
---|---|
Subject | Re: Attach comments to functions' parameters and return value |
Date | |
Msg-id | 55F7AE09.2050105@swisspug.org Whole thread Raw |
In response to | Re: Attach comments to functions' parameters and return value (Jim Nasby <Jim.Nasby@BlueTreble.com>) |
Responses |
Re: Attach comments to functions' parameters and return value
Re: Attach comments to functions' parameters and return value |
List | pgsql-hackers |
Hello Jim On 14/09/2015 19:23, Jim Nasby wrote: > On 9/14/15 8:59 AM, Charles Clavadetscher wrote: >> Hello >> >> In PostgreSQL it is possible to attach comments to almost everything. >> This >> made it possible for us to integrate the wiki that we use for our >> technical >> documentation directly with the database using the MediaWiki [1] >> extensions >> ExternalData [2] and MagicNoCache [3]. The result is a documentation on >> tables and related objects (indexes, triggers, etc.) and views that >> always >> shows the current state, i.e. any DDL change or any comment attached >> to an >> object is shown in the wiki immediately (or on refresh if the change was >> done after the reader landed on the page). > > Neat! I hope you'll open source that. :) Thank you for your answer. Sure I will put some information on it and the source on my website soon and let you know. There is not really much magic to it, but it can be quite helpful. >> My next workaround is to simulate the behaviour of a COMMENT ON FUNCTION >> PARAMETER/RETURNVALUE command inserting comments on these directly in >> pg_description. For that I used a convention similar to the one used for >> table attributes and defined following pg_description.objsubid: >> >> -1 = return value >> 0 = comment on the function itself (this already exists) >> 1..n = comment on parameter at position n > > At first glance, seems reasonable. > >> - Add function to get the position of the parameter, e.g. >> LookupFuncNamePos(function_name, param_name) or a function to create the >> whole ObjectAddress e.g. . > > Something similar might exist already. TBH, to start with, I would only > support position number. You'll have to support that case anyway, and it > should be simpler. I agree. Since parameter names are optional, supporting the position for comments definition is mandatory and is probably simpler. >> To long time PostgreSQL developers this may look straightforward. For the >> moment I am not even sure if that is correct and if there are other >> places >> that would need additions, apart from the obvious display in psql. > > I suspect that changes to support this should be pretty localized. I > suggest you look at other recent patches that have added COMMENT > functionality to see what they did. Good idea. As a matter of fact, Àlvaro sent a sequence of commits that relate in part to it. I will have a look to it as soon as I can. > BTW, I'm also interested in this but I'm not sure when I'd have time to > work on it. Good to know, thank you. As I mention in my original post I should be able to work on that in November this year. If I find some time I may start things earlier. Let's keep in touch over this list. Before any coding is done there should be an agreement on the syntax to be used in the statement and the way the information is stored. About the latter I think with the -1,0,1..n solution we are on a good track. For what's concerning the syntax I suggest the following. COMMENT ON FUNCTION function_name ( [ [ argmode ] [ argname ] argtype [, ...] ] ) PARAMETER param_position IS 'text'; COMMENT ON FUNCTION function_name ( [ [ argmode ] [ argname ] argtype [, ...] ] ) RETURN VALUE IS 'text'; An alternative to "RETURN VALUE" could be "RETURNS", which would make the statement shorter, but I think this may be confusing. The parameter list of the function is only required to identify the function also in cases it exists with the same name in different flavours. This sticks to the general syntax of the command and should be easy to understand. Your ideas? Thanks Charles
pgsql-hackers by date: