Re: [HACKERS] Attach comments to functions' parameters and return value
On 9/15/15 12:35 AM, Charles Clavadetscher wrote: 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. I like RETURN VALUE better myself. 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. Right. You should be able to use the current COMMENT ON code. Note however that the last time I looked it does NOT support the full syntax that CREATE FUNCTION does. It'd be nice to fix that, but that's mostly a separate matter. Though, it would probably be nice if all of this stuff (along with the regprocedure input function) could be factored into a single piece of code... -- Jim Nasby, Data Architect, Blue Treble Consulting, Austin TX Experts in Analytics, Data Architecture and PostgreSQL Data in Trouble? Get it in Treble! http://BlueTreble.com -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers
Re: [HACKERS] Attach comments to functions' parameters and return value
Hello Jim > -Original Message- > From: pgsql-hackers-ow...@postgresql.org [mailto:pgsql-hackers- > ow...@postgresql.org] On Behalf Of Charles Clavadetscher > Sent: Dienstag, 15. September 2015 07:35 > To: Jim Nasby ; pgsql-hackers@postgresql.org > Subject: Re: [HACKERS] Attach comments to functions' parameters and return > value > > 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. As promised: http://www.schmiedewerkstatt.ch/wiki/index.php/Database_self-documenting_Wik i Feedback, as usual, is always welcome. Bye Charles -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers
Re: [HACKERS] Attach comments to functions' parameters and return value
Hello Àlvaro On 14/09/2015 20:02, Alvaro Herrera wrote: Jim Nasby wrote: On 9/14/15 8:59 AM, Charles Clavadetscher wrote: 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. This sequence of commits may be helpful. http://git.postgresql.org/gitweb/?p=postgresql.git;a=history;f=src/test/regress/sql/object_address.sql;hb=HEAD Thank you. From the first impression I think that I was not too far away from a correct procedure ;-) I will take a closer look as soon as I can, but I am confident that this will help. Bye Charles -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers
Re: [HACKERS] Attach comments to functions' parameters and return value
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 -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers
Re: [HACKERS] Attach comments to functions' parameters and return value
Jim Nasby wrote: > On 9/14/15 8:59 AM, Charles Clavadetscher wrote: > >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. This sequence of commits may be helpful. http://git.postgresql.org/gitweb/?p=postgresql.git;a=history;f=src/test/regress/sql/object_address.sql;hb=HEAD -- Álvaro Herrerahttp://www.2ndQuadrant.com/ PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers
Re: [HACKERS] Attach comments to functions' parameters and return value
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. :) In order to optimize the query, we wrote a small set of sql functions that generate wiki markup for the objects queried. The idea behind is that this is much quicker in PostgreSQL than on a web server hosting MediaWiki, besides a better control of the privileges for the user retrieving data. And that! :) So far we can document in such a way tables and views. I started to create something similar for functions until I noticed that there is no way to attach comments on functions' parameters and return value. My first idea was to add this information in the function description, but this is quite an ugly solution. 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. 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. BTW, I'm also interested in this but I'm not sure when I'd have time to work on it. -- Jim Nasby, Data Architect, Blue Treble Consulting, Austin TX Experts in Analytics, Data Architecture and PostgreSQL Data in Trouble? Get it in Treble! http://BlueTreble.com -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers