Re: [PATCHES] Have psql display names and OUT/INOUT in \df output
On Sat, Jul 15, 2006 at 04:42:50PM -0700, David Fetter wrote: Folks, This patch makes psql's \df display functions with the names of parameters and OUT/INOUT if appropriate. Should there be a regression test for this? A doc patch? As this doesn't change any documented behavior, it doesn't look like there is space for a doc patch. Anyhow, please find enclosed the context-style diff. Sorry about the mix-up earlier :) Cheers, D -- David Fetter [EMAIL PROTECTED] http://fetter.org/ phone: +1 415 235 3778AIM: dfetter666 Skype: davidfetter Remember to vote! Index: src/bin/psql/describe.c === RCS file: /projects/cvsroot/pgsql/src/bin/psql/describe.c,v retrieving revision 1.140 diff -c -r1.140 describe.c *** src/bin/psql/describe.c 14 Jun 2006 16:49:02 - 1.140 --- src/bin/psql/describe.c 16 Jul 2006 06:10:10 - *** *** 170,177 SELECT n.nspname as \%s\,\n p.proname as \%s\,\n CASE WHEN p.proretset THEN 'setof ' ELSE '' END ||\n ! pg_catalog.format_type(p.prorettype, NULL) as \%s\,\n ! pg_catalog.oidvectortypes(p.proargtypes) as \%s\, _(Schema), _(Name), _(Result data type), _(Argument data types)); --- 170,198 SELECT n.nspname as \%s\,\n p.proname as \%s\,\n CASE WHEN p.proretset THEN 'setof ' ELSE '' END ||\n ! pg_catalog.format_type(p.prorettype, NULL) as \%s\,\n ! CASE WHEN proallargtypes IS NOT NULL THEN\n ! array_to_string(ARRAY(\n ! SELECT\n ! CASE\n ! WHEN p.proargmodes[s.i] = 'i' THEN ''\n ! WHEN p.proargmodes[s.i] = 'o' THEN ' OUT '\n ! WHEN p.proargmodes[s.i] = 'b' THEN ' INOUT '\n ! END ||\n ! COALESCE(p.proargnames[s.i] || ' ','') ||\n ! format_type(p.proallargtypes[s.i],-1)\n ! FROM\n ! generate_series(1,array_upper(p.proallargtypes,1)) AS s(i)\n ! ), ',')\n ! ELSE\n ! array_to_string(ARRAY(\n ! SELECT\n ! COALESCE(p.proargnames[s.i+1] || ' ', '') ||\n ! format_type(p.proargtypes[s.i],-1)\n ! FROM\n ! generate_series(0,array_upper(p.proargtypes,1)) AS s(i)\n ! ), ',')\n ! END AS \%s\, _(Schema), _(Name), _(Result data type), _(Argument data types)); ---(end of broadcast)--- TIP 1: if posting/reading through Usenet, please send an appropriate subscribe-nomail command to [EMAIL PROTECTED] so that your message can get through to the mailing list cleanly
Re: [PATCHES] Have psql display names and OUT/INOUT in \df output
On Sat, 2006-07-15 at 23:16 -0700, David Fetter wrote: Anyhow, please find enclosed the context-style diff. How carefully did you test this? postgres=# \df abc List of functions Schema | Name | Result data type | Argument data types +--+--+- public | abc | integer | a integer,b integer (1 row) (The argument list should be separated by both a comma and whitespace.) postgres=# create or replace function xyz(inout a int, inout int) returns record as 'select (1, 2);' language sql; CREATE FUNCTION postgres=# \df xyz List of functions Schema | Name | Result data type | Argument data types +--+--+-- public | xyz | record | INOUT a integer, INOUT integer (1 row) (Spurious whitespace for the unnamed INOUT parameter.) You need to schema-qualify references to builtin functions, to avoid accidentally using functions of the same name that appear earlier in the user's search path. (As a general rule, look at the surrounding code carefully before you modify it.) It would be nice to be consistent about SQL style, at least within a single query (e.g. don't separate function arguments with whitespace in some places but not others). -Neil ---(end of broadcast)--- TIP 5: don't forget to increase your free space map settings
Re: [PATCHES] Have psql display names and OUT/INOUT in \df output
On Sun, Jul 16, 2006 at 12:21:12AM -0700, Neil Conway wrote: On Sat, 2006-07-15 at 23:16 -0700, David Fetter wrote: Anyhow, please find enclosed the context-style diff. How carefully did you test this? Not enough. Here's the latest. postgres=# \df abc List of functions Schema | Name | Result data type | Argument data types +--+--+- public | abc | integer | a integer,b integer (1 row) (The argument list should be separated by both a comma and whitespace.) postgres=# create or replace function xyz(inout a int, inout int) returns record as 'select (1, 2);' language sql; CREATE FUNCTION postgres=# \df xyz List of functions Schema | Name | Result data type | Argument data types +--+--+-- public | xyz | record | INOUT a integer, INOUT integer (1 row) These are now fixed. (Spurious whitespace for the unnamed INOUT parameter.) You need to schema-qualify references to builtin functions, to avoid accidentally using functions of the same name that appear earlier in the user's search path. I don't understand what you mean here. The schema name comes with both versions of \df, just as it did before. Cheers, D -- David Fetter [EMAIL PROTECTED] http://fetter.org/ phone: +1 415 235 3778AIM: dfetter666 Skype: davidfetter Remember to vote! Index: src/bin/psql/describe.c === RCS file: /projects/cvsroot/pgsql/src/bin/psql/describe.c,v retrieving revision 1.140 diff -c -r1.140 describe.c *** src/bin/psql/describe.c 14 Jun 2006 16:49:02 - 1.140 --- src/bin/psql/describe.c 16 Jul 2006 07:59:48 - *** *** 170,177 SELECT n.nspname as \%s\,\n p.proname as \%s\,\n CASE WHEN p.proretset THEN 'setof ' ELSE '' END ||\n ! pg_catalog.format_type(p.prorettype, NULL) as \%s\,\n ! pg_catalog.oidvectortypes(p.proargtypes) as \%s\, _(Schema), _(Name), _(Result data type), _(Argument data types)); --- 170,204 SELECT n.nspname as \%s\,\n p.proname as \%s\,\n CASE WHEN p.proretset THEN 'setof ' ELSE '' END ||\n ! pg_catalog.format_type(p.prorettype, NULL) as \%s\,\n ! CASE WHEN proallargtypes IS NOT NULL THEN\n ! array_to_string(ARRAY(\n ! SELECT\n ! CASE\n ! WHEN p.proargmodes[s.i] = 'i' THEN ''\n ! WHEN p.proargmodes[s.i] = 'o' THEN 'OUT '\n ! WHEN p.proargmodes[s.i] = 'b' THEN 'INOUT '\n ! END ||\n ! CASE\n ! WHEN p.proargnames[s.i] = '' OR p.proargnames[s.i] IS NULL THEN ''\n ! ELSE p.proargnames[s.i] || ' ' \n ! END ||\n ! format_type(p.proallargtypes[s.i],-1)\n ! FROM\n ! generate_series(1,array_upper(p.proallargtypes,1)) AS s(i)\n ! ), ', ')\n ! ELSE\n ! array_to_string(ARRAY(\n ! SELECT\n ! CASE\n ! WHEN p.proargnames[s.i+1] = '' OR p.proargnames[s.i+1] IS NULL THEN ''\n ! ELSE p.proargnames[s.i+1] || ' '\n ! END ||\n ! format_type(p.proargtypes[s.i],-1)\n ! FROM\n ! generate_series(0,array_upper(p.proargtypes,1)) AS s(i)\n ! ), ', ')\n ! END AS \%s\,
Re: [PATCHES] Have psql display names and OUT/INOUT in \df output
On Sun, 2006-07-16 at 01:00 -0700, David Fetter wrote: On Sun, Jul 16, 2006 at 12:21:12AM -0700, Neil Conway wrote: You need to schema-qualify references to builtin functions, to avoid accidentally using functions of the same name that appear earlier in the user's search path. I don't understand what you mean here. For example, you shouldn't be using generate_series in the SQL query: if the user has a function of the same name earlier in their search path, psql will invoke the wrong function. Instead, you should call pg_catalog.generate_series, as psql was careful to do prior to the patch. -Neil ---(end of broadcast)--- TIP 1: if posting/reading through Usenet, please send an appropriate subscribe-nomail command to [EMAIL PROTECTED] so that your message can get through to the mailing list cleanly
Re: [PATCHES] Have psql display names and OUT/INOUT in \df output
On Sun, Jul 16, 2006 at 05:16:58AM -0700, Neil Conway wrote: On Sun, 2006-07-16 at 01:00 -0700, David Fetter wrote: On Sun, Jul 16, 2006 at 12:21:12AM -0700, Neil Conway wrote: You need to schema-qualify references to builtin functions, to avoid accidentally using functions of the same name that appear earlier in the user's search path. I don't understand what you mean here. For example, you shouldn't be using generate_series in the SQL query: if the user has a function of the same name earlier in their search path, psql will invoke the wrong function. Instead, you should call pg_catalog.generate_series, as psql was careful to do prior to the patch. Thanks for clarifying this. Patch attached. Cheers, D -- David Fetter [EMAIL PROTECTED] http://fetter.org/ phone: +1 415 235 3778AIM: dfetter666 Skype: davidfetter Remember to vote! Index: src/bin/psql/describe.c === RCS file: /projects/cvsroot/pgsql/src/bin/psql/describe.c,v retrieving revision 1.140 diff -c -r1.140 describe.c *** src/bin/psql/describe.c 14 Jun 2006 16:49:02 - 1.140 --- src/bin/psql/describe.c 16 Jul 2006 14:18:08 - *** *** 170,177 SELECT n.nspname as \%s\,\n p.proname as \%s\,\n CASE WHEN p.proretset THEN 'setof ' ELSE '' END ||\n ! pg_catalog.format_type(p.prorettype, NULL) as \%s\,\n ! pg_catalog.oidvectortypes(p.proargtypes) as \%s\, _(Schema), _(Name), _(Result data type), _(Argument data types)); --- 170,204 SELECT n.nspname as \%s\,\n p.proname as \%s\,\n CASE WHEN p.proretset THEN 'setof ' ELSE '' END ||\n ! pg_catalog.format_type(p.prorettype, NULL) as \%s\,\n ! CASE WHEN proallargtypes IS NOT NULL THEN\n ! pg_catalog.array_to_string(ARRAY(\n ! SELECT\n ! CASE\n ! WHEN p.proargmodes[s.i] = 'i' THEN ''\n ! WHEN p.proargmodes[s.i] = 'o' THEN 'OUT '\n ! WHEN p.proargmodes[s.i] = 'b' THEN 'INOUT '\n ! END ||\n ! CASE\n ! WHEN p.proargnames[s.i] = '' OR p.proargnames[s.i] IS NULL THEN ''\n ! ELSE p.proargnames[s.i] || ' ' \n ! END ||\n ! pg_catalog.format_type(p.proallargtypes[s.i],-1)\n ! FROM\n ! pg_catalog.generate_series(1,pg_catalog.array_upper(p.proallargtypes,1)) AS s(i)\n ! ), ', ')\n ! ELSE\n ! pg_catalog.array_to_string(ARRAY(\n ! SELECT\n ! CASE\n ! WHEN p.proargnames[s.i+1] = '' OR p.proargnames[s.i+1] IS NULL THEN ''\n ! ELSE p.proargnames[s.i+1] || ' '\n ! END ||\n ! pg_catalog.format_type(p.proargtypes[s.i],-1)\n ! FROM\n ! pg_catalog.generate_series(0,pg_catalog.array_upper(p.proargtypes,1)) AS s(i)\n ! ), ', ')\n ! END AS \%s\, _(Schema), _(Name), _(Result data type), _(Argument data types)); ---(end of broadcast)--- TIP 5: don't forget to increase your free space map settings
Re: [PATCHES] Have psql display names and OUT/INOUT in \df output
On Sun, 2006-07-16 at 07:18 -0700, David Fetter wrote: Thanks for clarifying this. Patch attached. Applied, with one more fix: format_type's second argument should be NULL if it is not otherwise known. Thanks for the patch. (Speaking of which, there is probably room for a one-parameter version of format_type() that just calls the normal version with a NULL for the second parameter...) -Neil ---(end of broadcast)--- TIP 9: In versions below 8.0, the planner will ignore your desire to choose an index scan if your joining column's datatypes do not match
Re: [PATCHES] Have psql display names and OUT/INOUT in \df output
David Fetter wrote: Folks, This patch makes psql's \df display functions with the names of parameters and OUT/INOUT if appropriate. Should there be a regression test for this? A doc patch? Regression tests are for server functionality, generally. Possibly docs should be patched. cheers andrew ---(end of broadcast)--- TIP 1: if posting/reading through Usenet, please send an appropriate subscribe-nomail command to [EMAIL PROTECTED] so that your message can get through to the mailing list cleanly