a few other things:
* Made all references to the pg_* tables absolute, by specifying
the pg_catalog schema.
* Added SCHEMA as a create/delete completion option.
* Added SCHEMA completion as: SELECT nspname FROM
pg_catalog.pg_namespace
WHERE substr(nspname,1,%d)='%s'
* Added completion of "INSERT INTO <table> (" with attribute names.
* Added completion of "INSERT INTO <table> (attribs)" with
VALUES or SELECT
* Added limited locking completion: only for one table:
"LOCK" and "LOCK TABLE" now both get a completion list of tables
Complete with "IN" for LOCK [TABLE] <table>
Complete LOCK [TABLE] <table> IN with a lock mode
* Added a very simple WHERE finisher that uses the previous word
as a table lookup for attributes.
* Added quote support when parsing "previous words". In other words,
hitting tab after INSERT INTO "foo bar baby"
now does the right thing and recognizes "foo bar baby" as one word.
Letting tab-complete quote things that should be quoted seems to be
temporarily ifdef'ed out due to readline compatibility problems.
Can anyone elaborate on this?
Greg Sabino Mullane
#define Query_for_list_of_attributes "SELECT a.attname FROM pg_attribute a, pg_class c WHERE c.oid = a.attrelid and a.attnum>0 and substr(a.attname,1,%d)='%s' and c.relname='%s'"
#define Query_for_list_of_attributes "SELECT a.attname FROM pg_catalog.pg_attribute a, pg_catalog.pg_class c WHERE c.oid = a.attrelid and a.attnum>0 and substr(a.attname,1,%d)='%s' and c.relname='%s'"
@ -376,7 +374,7 @@ psql_completion(char *text, int start, int end)
*queries.*/
if(snprintf(query_buffer,BUF_SIZE,
"SELECT c1.relname FROM pg_class c1, pg_class c2, pg_index i WHERE c1.oid=i.indrelid and i.indexrelid=c2.oid and c2.relname='%s'",
"SELECT c1.relname FROM pg_catalog.pg_class c1, pg_catalog.pg_class c2, pg_catalog.pg_index i WHERE c1.oid=i.indrelid and i.indexrelid=c2.oid and c2.relname='%s'",
prev2_wd)==-1)
ERROR_QUERY_TOO_LONG;
else
@ -389,7 +387,7 @@ psql_completion(char *text, int start, int end)
COMPLETE_WITH_QUERY("SELECT relname FROM pg_listener WHERE substr(relname,1,%d)='%s'");
COMPLETE_WITH_QUERY("SELECT relname FROM pg_catalog.pg_listener WHERE substr(relname,1,%d)='%s'");
/* REINDEX */
elseif(strcasecmp(prev_wd,"REINDEX")==0)
@ -715,7 +742,7 @@ psql_completion(char *text, int start, int end)
/* UNLISTEN */
elseif(strcasecmp(prev_wd,"UNLISTEN")==0)
COMPLETE_WITH_QUERY("SELECT relname FROM pg_listener WHERE substr(relname,1,%d)='%s' UNION SELECT '*'::text");
COMPLETE_WITH_QUERY("SELECT relname FROM pg_catalog.pg_listener WHERE substr(relname,1,%d)='%s' UNION SELECT '*'::text");
/* UPDATE */
/* If prev. word is UPDATE suggest a list of tables */
@ -735,10 +762,15 @@ psql_completion(char *text, int start, int end)
/* VACUUM */
elseif(strcasecmp(prev_wd,"VACUUM")==0)
COMPLETE_WITH_QUERY("SELECT relname FROM pg_class WHERE relkind='r' and substr(relname,1,%d)='%s' UNION SELECT 'FULL'::text UNION SELECT 'ANALYZE'::text");
COMPLETE_WITH_QUERY("SELECT relname FROM pg_catalog.pg_class WHERE relkind='r' and substr(relname,1,%d)='%s' UNION SELECT 'FULL'::text UNION SELECT 'ANALYZE'::text");