the attached patch makes teh following changes to the psql tab-complete
support
* adds a few missing words to some commands (like adding GIN as a valid
index type or OWNED BY for ALTER SEQUENCE,...)
* support for ALTER TABLE foo ENABLE/DISABLE REPLICA TRIGGER/RULE
* autocomplete CREATE DATABASE foo TEMPLATE (mostly done to prevent
conflicts with the TEMPLATE keyword for text search)
* support for ALTER/CREATE/DROP TEXT SEARCH as well as COMMENT ON TEXT
SEARCH and the corresponding psql backslash commands.
This proved a little more difficult than expected due to the fact that
words_after_create[] is used for two purposes - one is to provide a list
of words that follow immediatly after CREATE (or DROP) and the other
purpose is to use it for autocompleting anywhere in the statement if the
word in that struct is found with a query.
Since TEXT SEARCH CONFIGURATION|DICTIONARY|TEMPLATE|PARSER results in 3
words instead of one (as all the other words in that list are) I added a
flag to the struct to tell create_command_generator() to skip that entry
for autocompleting immediatly after CREATE which feels like a dirty
hack (but that holds true for a lot of code in tab-complete.c).
Stefan
Index: src/bin/psql/tab-complete.c
===
RCS file: /projects/cvsroot/pgsql/src/bin/psql/tab-complete.c,v
retrieving revision 1.166
diff -c -r1.166 tab-complete.c
*** src/bin/psql/tab-complete.c 3 Jul 2007 01:30:37 - 1.166
--- src/bin/psql/tab-complete.c 25 Aug 2007 11:17:23 -
***
*** 328,333
--- 328,337
AND pg_catalog.quote_ident(relname)='%s' \
AND pg_catalog.pg_table_is_visible(c.oid)
+ #define Query_for_list_of_template_databases \
+ SELECT pg_catalog.quote_ident(datname) FROM pg_catalog.pg_database \
+ WHERE substring(pg_catalog.quote_ident(datname),1,%d)='%s' and
datistemplate IS TRUE
+
#define Query_for_list_of_databases \
SELECT pg_catalog.quote_ident(datname) FROM pg_catalog.pg_database \
WHERE substring(pg_catalog.quote_ident(datname),1,%d)='%s'
***
*** 419,424
--- 423,444
(SELECT tgrelid FROM pg_catalog.pg_trigger \
WHERE pg_catalog.quote_ident(tgname)='%s')
+ #define Query_for_list_of_ts_configurations \
+ SELECT pg_catalog.quote_ident(cfgname) FROM pg_catalog.pg_ts_config \
+ WHERE substring(pg_catalog.quote_ident(cfgname),1,%d)='%s'
+
+ #define Query_for_list_of_ts_dictionaries \
+ SELECT pg_catalog.quote_ident(dictname) FROM pg_catalog.pg_ts_dict \
+ WHERE substring(pg_catalog.quote_ident(dictname),1,%d)='%s'
+
+ #define Query_for_list_of_ts_parsers \
+ SELECT pg_catalog.quote_ident(prsname) FROM pg_catalog.pg_ts_parser \
+ WHERE substring(pg_catalog.quote_ident(prsname),1,%d)='%s'
+
+ #define Query_for_list_of_ts_templates \
+ SELECT pg_catalog.quote_ident(tmplname) FROM pg_catalog.pg_ts_template \
+ WHERE substring(pg_catalog.quote_ident(tmplname),1,%d)='%s'
+
/*
* This is a list of all things in Pgsql, which can show up after CREATE or
* DROP; and there is also a query to get a list of them.
***
*** 429,434
--- 449,455
const char *name;
const char *query; /* simple query, or NULL */
const SchemaQuery *squery; /* schema query, or NULL */
+ const bool noshow; /* NULL or true if this word should not show up
after CREATE or DROP */
} pgsql_thing_t;
static const pgsql_thing_t words_after_create[] = {
***
*** 440,447
--- 461,470
* CREATE CONSTRAINT TRIGGER is not supported here because it is
designed
* to be used only by pg_dump.
*/
+ {CONFIGURATION, Query_for_list_of_ts_configurations, NULL, true},
{CONVERSION, SELECT pg_catalog.quote_ident(conname) FROM
pg_catalog.pg_conversion WHERE
substring(pg_catalog.quote_ident(conname),1,%d)='%s'},
{DATABASE, Query_for_list_of_databases},
+ {DICTIONARY, Query_for_list_of_ts_dictionaries, NULL, true},
{DOMAIN, NULL, Query_for_list_of_domains},
{FUNCTION, NULL, Query_for_list_of_functions},
{GROUP, Query_for_list_of_roles},
***
*** 449,454
--- 472,478
{INDEX, NULL, Query_for_list_of_indexes},
{OPERATOR, NULL, NULL}, /* Querying for this is probably not
such a
* good idea. */
+ {PARSER, Query_for_list_of_ts_parsers, NULL, true},
{ROLE, Query_for_list_of_roles},
{RULE, SELECT pg_catalog.quote_ident(rulename) FROM
pg_catalog.pg_rules WHERE
substring(pg_catalog.quote_ident(rulename),1,%d)='%s'},
{SCHEMA, Query_for_list_of_schemas},
***
*** 456,467
{TABLE, NULL, Query_for_list_of_tables},
{TABLESPACE, Query_for_list_of_tablespaces},
{TEMP, NULL, NULL}, /* for CREATE TEMP TABLE ... */
{TRIGGER, SELECT