33 *
44 * Copyright (c) 2000-2010, PostgreSQL Global Development Group
55 *
6- * $PostgreSQL: pgsql/src/bin/psql/tab-complete.c,v 1.196 2010/02/26 02:01:20 momjian Exp $
6+ * $PostgreSQL: pgsql/src/bin/psql/tab-complete.c,v 1.197 2010/04/05 05:33:24 itagaki Exp $
77 */
88
99/*----------------------------------------------------------------------
@@ -507,6 +507,11 @@ static const SchemaQuery Query_for_list_of_views = {
507507" FROM pg_catalog.pg_am "\
508508" WHERE substring(pg_catalog.quote_ident(amname),1,%d)='%s'"
509509
510+ #define Query_for_list_of_arguments \
511+ " SELECT pg_catalog.oidvectortypes(proargtypes)||')' "\
512+ " FROM pg_catalog.pg_proc "\
513+ " WHERE proname='%s'"
514+
510515/*
511516 * This is a list of all "things" in Pgsql, which can show up after CREATE or
512517 * DROP; and there is also a query to get a list of them.
@@ -705,11 +710,27 @@ psql_completion(char *text, int start, int end)
705710else if (pg_strcasecmp (prev3_wd ,"ALTER" )== 0 &&
706711 (pg_strcasecmp (prev2_wd ,"AGGREGATE" )== 0 ||
707712pg_strcasecmp (prev2_wd ,"FUNCTION" )== 0 ))
713+ COMPLETE_WITH_CONST ("(" );
714+ /* ALTER AGGREGATE,FUNCTION <name> (...) */
715+ else if (pg_strcasecmp (prev4_wd ,"ALTER" )== 0 &&
716+ (pg_strcasecmp (prev3_wd ,"AGGREGATE" )== 0 ||
717+ pg_strcasecmp (prev3_wd ,"FUNCTION" )== 0 ))
708718{
709- static const char * const list_ALTERAGG []=
710- {"OWNER TO" ,"RENAME TO" ,"SET SCHEMA" ,NULL };
719+ if (prev_wd [strlen (prev_wd )- 1 ]== ')' )
720+ {
721+ static const char * const list_ALTERAGG []=
722+ {"OWNER TO" ,"RENAME TO" ,"SET SCHEMA" ,NULL };
711723
712- COMPLETE_WITH_LIST (list_ALTERAGG );
724+ COMPLETE_WITH_LIST (list_ALTERAGG );
725+ }
726+ else
727+ {
728+ char * tmp_buf = malloc (strlen (Query_for_list_of_arguments )+ strlen (prev2_wd ));
729+
730+ sprintf (tmp_buf ,Query_for_list_of_arguments ,prev2_wd );
731+ COMPLETE_WITH_QUERY (tmp_buf );
732+ free (tmp_buf );
733+ }
713734}
714735
715736/* ALTER CONVERSION,SCHEMA <name> */
@@ -860,7 +881,7 @@ psql_completion(char *text, int start, int end)
860881{
861882static const char * const list_ALTERSEQUENCE []=
862883{"INCREMENT" ,"MINVALUE" ,"MAXVALUE" ,"RESTART" ,"NO" ,"CACHE" ,"CYCLE" ,
863- "SET SCHEMA" ,"OWNED BY" ,"RENAME TO" ,NULL };
884+ "SET SCHEMA" ,"OWNED BY" ,"OWNER TO" , " RENAME TO" ,NULL };
864885
865886COMPLETE_WITH_LIST (list_ALTERSEQUENCE );
866887}
@@ -887,7 +908,8 @@ psql_completion(char *text, int start, int end)
887908else if (pg_strcasecmp (prev3_wd ,"ALTER" )== 0 &&
888909pg_strcasecmp (prev2_wd ,"VIEW" )== 0 )
889910{
890- static const char * const list_ALTERVIEW []= {"RENAME TO" ,NULL };
911+ static const char * const list_ALTERVIEW []=
912+ {"ALTER COLUMN" ,"OWNER TO" ,"RENAME TO" ,"SET SCHEMA" ,NULL };
891913
892914COMPLETE_WITH_LIST (list_ALTERVIEW );
893915}
@@ -1206,7 +1228,7 @@ psql_completion(char *text, int start, int end)
12061228pg_strcasecmp (prev2_wd ,"TYPE" )== 0 )
12071229{
12081230static const char * const list_ALTERTYPE []=
1209- {"OWNER TO" ,"SET SCHEMA" ,NULL };
1231+ {"OWNER TO" ,"RENAME TO" , " SET SCHEMA" ,NULL };
12101232
12111233COMPLETE_WITH_LIST (list_ALTERTYPE );
12121234}
@@ -1761,10 +1783,9 @@ psql_completion(char *text, int start, int end)
17611783pg_strcasecmp (prev3_wd ,"FUNCTION" )== 0 )&&
17621784pg_strcasecmp (prev_wd ,"(" )== 0 )
17631785{
1764- static const char func_args_query []= "select pg_catalog.oidvectortypes(proargtypes)||')' from pg_proc where proname='%s'" ;
1765- char * tmp_buf = malloc (strlen (func_args_query )+ strlen (prev2_wd ));
1786+ char * tmp_buf = malloc (strlen (Query_for_list_of_arguments )+ strlen (prev2_wd ));
17661787
1767- sprintf (tmp_buf ,func_args_query ,prev2_wd );
1788+ sprintf (tmp_buf ,Query_for_list_of_arguments ,prev2_wd );
17681789COMPLETE_WITH_QUERY (tmp_buf );
17691790free (tmp_buf );
17701791}
@@ -2230,6 +2251,7 @@ psql_completion(char *text, int start, int end)
22302251else if (pg_strcasecmp (prev2_wd ,"SET" )== 0 &&
22312252pg_strcasecmp (prev4_wd ,"UPDATE" )!= 0 &&
22322253pg_strcasecmp (prev_wd ,"TABLESPACE" )!= 0 &&
2254+ pg_strcasecmp (prev_wd ,"SCHEMA" )!= 0 &&
22332255prev_wd [strlen (prev_wd )- 1 ]!= ')' &&
22342256pg_strcasecmp (prev4_wd ,"DOMAIN" )!= 0 )
22352257COMPLETE_WITH_CONST ("TO" );