psql \df choose functions by their arguments - Mailing list pgsql-hackers
From | Greg Sabino Mullane |
---|---|
Subject | psql \df choose functions by their arguments |
Date | |
Msg-id | CAKAnmmLF9Hhu02N+s7uAyLc5J1xZReg72HQUoiKhNiJV3_jACQ@mail.gmail.com Whole thread Raw |
Responses |
Re: psql \df choose functions by their arguments
Re: psql \df choose functions by their arguments |
List | pgsql-hackers |
-----BEGIN PGP SIGNED MESSAGE-----
Hash: RIPEMD160
Improve psql \df to choose functions by their arguments
== OVERVIEW
Having to scroll through same-named functions with different argument types
when you know exactly which one you want is annoying at best, error causing
at worst. This patch enables a quick narrowing of functions with the
same name but different arguments. For example, to see the full details
of a function names "myfunc" with a TEXT argument, but not showing
the version of "myfunc" with a BIGINT argument, one can now do:
psql=# \df myfunc text
For this, we are fairly liberal in what we accept, and try to be as
intuitive as possible.
Features:
* Type names are case insensitive. Whitespace is optional, but quoting is respected:
greg=# \df myfunc text "character varying" INTEGER
* Abbreviations of common types is permitted (because who really likes
to type out "character varying"?), so the above could also be written as:
greg=# \df myfunc text varchar int
* The matching is greedy, so you can see everything matching a subset:
greg=# \df myfunc timestamptz
List of functions
Schema | Name | Result data type | Argument data types | Type
- --------+--------+------------------+-------------------------------------------+------
public | myfunc | void | timestamp with time zone | func
public | myfunc | void | timestamp with time zone, bigint | func
public | myfunc | void | timestamp with time zone, bigint, boolean | func
public | myfunc | void | timestamp with time zone, integer | func
public | myfunc | void | timestamp with time zone, text, cidr | func
(5 rows)
* The appearance of a closing paren indicates we do not want the greediness:
greg=# \df myfunc (timestamptz, bigint)
List of functions
Schema | Name | Result data type | Argument data types | Type
- --------+--------+------------------+----------------------------------+------
public | myfunc | void | timestamp with time zone, bigint | func
(1 row)
== TAB COMPLETION:
I'm not entirely happy with this, but I figure piggybacking
onto COMPLETE_WITH_FUNCTION_ARG is better than nothing at all.
Ideally we'd walk prev*_wd to refine the returned list, but
that's an awful lot of complexity for very little gain, and I think
the current behavior of showing the complete list of args each time
should suffice.
== DOCUMENTATION:
The new feature is briefly mentioned: wordsmithing help in the
sgml section is appreciated. I'm not sure how many of the above features
need to be documented in detail.
Regarding psql/help.c, I don't think this really warrants a change there.
As it is, we've gone through great lengths to keep this overloaded backslash
command left justified with the rest!
== TESTS:
I put this into psql.c, seems the best place. Mostly testing out
basic functionality, quoting, and the various abbreviations. Not much
else to test, near as I can tell, as this is a pure convienence addition
and shouldn't affect anything else. Any extra words after a function name
for \df was previously treated as an error.
== IMPLEMENTATION:
Rather than messing with psqlscanslash, we simply slurp in the entire rest
of the line via psql_scan_slash_option (all of which was previously ignored).
This is passed to describeFunction, which then uses strtokx to break it
into tokens. We look for a match by comparing the current proargtypes entry,
casted to text, against the lowercase version of the token found by strtokx.
Along the way, we convert things like "timestamptz" to the official version
(i.e. "timestamp with time zone"). If any of the tokens start with a closing
paren, we immediately stop parsing and set pronargs to the current number
of valid tokens, thereby forcing a match to one (or zero) functions.
6ab7a45d541f2c31c5631b811f14081bf7b22271 v1-psql-df-pick-function-by-type.patch
- --
Greg Sabino Mullane
PGP Key: 0x14964AC8 202010151316
http://biglumber.com/x/web?pk=2529DF6AB8F79407E94445B4BC9B906714964AC8
-----BEGIN PGP SIGNATURE-----
iF0EAREDAB0WIQQlKd9quPeUB+lERbS8m5BnFJZKyAUCX4iENQAKCRC8m5BnFJZK
yIUKAKDiv1E9KgXuSO7lE9p+ttFdk02O2ACg44lu9VdKt3IggIrPiXBPKR8C85M=
=QPSd
-----END PGP SIGNATURE-----
Hash: RIPEMD160
Improve psql \df to choose functions by their arguments
== OVERVIEW
Having to scroll through same-named functions with different argument types
when you know exactly which one you want is annoying at best, error causing
at worst. This patch enables a quick narrowing of functions with the
same name but different arguments. For example, to see the full details
of a function names "myfunc" with a TEXT argument, but not showing
the version of "myfunc" with a BIGINT argument, one can now do:
psql=# \df myfunc text
For this, we are fairly liberal in what we accept, and try to be as
intuitive as possible.
Features:
* Type names are case insensitive. Whitespace is optional, but quoting is respected:
greg=# \df myfunc text "character varying" INTEGER
* Abbreviations of common types is permitted (because who really likes
to type out "character varying"?), so the above could also be written as:
greg=# \df myfunc text varchar int
* The matching is greedy, so you can see everything matching a subset:
greg=# \df myfunc timestamptz
List of functions
Schema | Name | Result data type | Argument data types | Type
- --------+--------+------------------+-------------------------------------------+------
public | myfunc | void | timestamp with time zone | func
public | myfunc | void | timestamp with time zone, bigint | func
public | myfunc | void | timestamp with time zone, bigint, boolean | func
public | myfunc | void | timestamp with time zone, integer | func
public | myfunc | void | timestamp with time zone, text, cidr | func
(5 rows)
* The appearance of a closing paren indicates we do not want the greediness:
greg=# \df myfunc (timestamptz, bigint)
List of functions
Schema | Name | Result data type | Argument data types | Type
- --------+--------+------------------+----------------------------------+------
public | myfunc | void | timestamp with time zone, bigint | func
(1 row)
== TAB COMPLETION:
I'm not entirely happy with this, but I figure piggybacking
onto COMPLETE_WITH_FUNCTION_ARG is better than nothing at all.
Ideally we'd walk prev*_wd to refine the returned list, but
that's an awful lot of complexity for very little gain, and I think
the current behavior of showing the complete list of args each time
should suffice.
== DOCUMENTATION:
The new feature is briefly mentioned: wordsmithing help in the
sgml section is appreciated. I'm not sure how many of the above features
need to be documented in detail.
Regarding psql/help.c, I don't think this really warrants a change there.
As it is, we've gone through great lengths to keep this overloaded backslash
command left justified with the rest!
== TESTS:
I put this into psql.c, seems the best place. Mostly testing out
basic functionality, quoting, and the various abbreviations. Not much
else to test, near as I can tell, as this is a pure convienence addition
and shouldn't affect anything else. Any extra words after a function name
for \df was previously treated as an error.
== IMPLEMENTATION:
Rather than messing with psqlscanslash, we simply slurp in the entire rest
of the line via psql_scan_slash_option (all of which was previously ignored).
This is passed to describeFunction, which then uses strtokx to break it
into tokens. We look for a match by comparing the current proargtypes entry,
casted to text, against the lowercase version of the token found by strtokx.
Along the way, we convert things like "timestamptz" to the official version
(i.e. "timestamp with time zone"). If any of the tokens start with a closing
paren, we immediately stop parsing and set pronargs to the current number
of valid tokens, thereby forcing a match to one (or zero) functions.
6ab7a45d541f2c31c5631b811f14081bf7b22271 v1-psql-df-pick-function-by-type.patch
- --
Greg Sabino Mullane
PGP Key: 0x14964AC8 202010151316
http://biglumber.com/x/web?pk=2529DF6AB8F79407E94445B4BC9B906714964AC8
-----BEGIN PGP SIGNATURE-----
iF0EAREDAB0WIQQlKd9quPeUB+lERbS8m5BnFJZKyAUCX4iENQAKCRC8m5BnFJZK
yIUKAKDiv1E9KgXuSO7lE9p+ttFdk02O2ACg44lu9VdKt3IggIrPiXBPKR8C85M=
=QPSd
-----END PGP SIGNATURE-----
Attachment
pgsql-hackers by date: