WIP psql \df choose functions by their arguments - Mailing list pgsql-hackers
From | Greg Sabino Mullane |
---|---|
Subject | WIP psql \df choose functions by their arguments |
Date | |
Msg-id | cc6cb5a2ac9783ce2fca5797468739c4@biglumber.com Whole thread Raw |
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. dcd972f6b945070ef4454ea39d25378427a90e89 df.patch -----BEGIN PGP SIGNATURE----- iF0EAREDAB0WIQQlKd9quPeUB+lERbS8m5BnFJZKyAUCX4bsgwAKCRC8m5BnFJZK yGDvAJ9ix8jzwtTwKLDQUgu5yb/iBoC7EQCfQsf8LLZ0RWsiiMposi57u3S94nE= =rQj2 -----END PGP SIGNATURE-----
Attachment
pgsql-hackers by date: