@@ -1031,9 +1031,13 @@ static const SchemaQuery Query_for_trigger_of_table = {
10311031" FROM pg_catalog.pg_roles "\
10321032" WHERE rolname LIKE '%s'"
10331033
1034+ /* add these to Query_for_list_of_roles in OWNER contexts */
1035+ #define Keywords_for_list_of_owner_roles \
1036+ "CURRENT_ROLE", "CURRENT_USER", "SESSION_USER"
1037+
10341038/* add these to Query_for_list_of_roles in GRANT contexts */
10351039#define Keywords_for_list_of_grant_roles \
1036- "PUBLIC" , "CURRENT_ROLE", "CURRENT_USER", "SESSION_USER "
1040+ Keywords_for_list_of_owner_roles , "PUBLIC "
10371041
10381042#define Query_for_all_table_constraints \
10391043"SELECT conname "\
@@ -1785,8 +1789,15 @@ psql_completion(const char *text, int start, int end)
17851789/* CREATE */
17861790/* complete with something you can create */
17871791else if (TailMatches ("CREATE" ))
1788- matches = rl_completion_matches (text ,create_command_generator );
1789-
1792+ {
1793+ /* only some object types can be created as part of CREATE SCHEMA */
1794+ if (HeadMatches ("CREATE" ,"SCHEMA" ))
1795+ COMPLETE_WITH ("TABLE" ,"VIEW" ,"INDEX" ,"SEQUENCE" ,"TRIGGER" ,
1796+ /* for INDEX and TABLE/SEQUENCE, respectively */
1797+ "UNIQUE" ,"UNLOGGED" );
1798+ else
1799+ matches = rl_completion_matches (text ,create_command_generator );
1800+ }
17901801/* complete with something you can create or replace */
17911802else if (TailMatches ("CREATE" ,"OR" ,"REPLACE" ))
17921803COMPLETE_WITH ("FUNCTION" ,"PROCEDURE" ,"LANGUAGE" ,"RULE" ,"VIEW" ,
@@ -3154,6 +3165,20 @@ psql_completion(const char *text, int start, int end)
31543165else if (TailMatches ("AS" ,"ON" ,"SELECT|UPDATE|INSERT|DELETE" ,"TO" ))
31553166COMPLETE_WITH_SCHEMA_QUERY (Query_for_list_of_tables );
31563167
3168+ /* CREATE SCHEMA [ <name> ] [ AUTHORIZATION ] */
3169+ else if (Matches ("CREATE" ,"SCHEMA" ))
3170+ COMPLETE_WITH_QUERY_PLUS (Query_for_list_of_schemas ,
3171+ "AUTHORIZATION" );
3172+ else if (Matches ("CREATE" ,"SCHEMA" ,"AUTHORIZATION" )||
3173+ Matches ("CREATE" ,"SCHEMA" ,MatchAny ,"AUTHORIZATION" ))
3174+ COMPLETE_WITH_QUERY_PLUS (Query_for_list_of_roles ,
3175+ Keywords_for_list_of_owner_roles );
3176+ else if (Matches ("CREATE" ,"SCHEMA" ,"AUTHORIZATION" ,MatchAny )||
3177+ Matches ("CREATE" ,"SCHEMA" ,MatchAny ,"AUTHORIZATION" ,MatchAny ))
3178+ COMPLETE_WITH ("CREATE" ,"GRANT" );
3179+ else if (Matches ("CREATE" ,"SCHEMA" ,MatchAny ))
3180+ COMPLETE_WITH ("AUTHORIZATION" ,"CREATE" ,"GRANT" );
3181+
31573182/* CREATE SEQUENCE --- is allowed inside CREATE SCHEMA, so use TailMatches */
31583183else if (TailMatches ("CREATE" ,"SEQUENCE" ,MatchAny )||
31593184TailMatches ("CREATE" ,"TEMP|TEMPORARY" ,"SEQUENCE" ,MatchAny ))
@@ -3185,9 +3210,15 @@ psql_completion(const char *text, int start, int end)
31853210/* Complete "CREATE TEMP/TEMPORARY" with the possible temp objects */
31863211else if (TailMatches ("CREATE" ,"TEMP|TEMPORARY" ))
31873212COMPLETE_WITH ("SEQUENCE" ,"TABLE" ,"VIEW" );
3188- /* Complete "CREATE UNLOGGED" with TABLE or MATVIEW */
3213+ /* Complete "CREATE UNLOGGED" with TABLE, SEQUENCE or MATVIEW */
31893214else if (TailMatches ("CREATE" ,"UNLOGGED" ))
3190- COMPLETE_WITH ("TABLE" ,"MATERIALIZED VIEW" );
3215+ {
3216+ /* but not MATVIEW in CREATE SCHEMA */
3217+ if (HeadMatches ("CREATE" ,"SCHEMA" ))
3218+ COMPLETE_WITH ("TABLE" ,"SEQUENCE" );
3219+ else
3220+ COMPLETE_WITH ("TABLE" ,"SEQUENCE" ,"MATERIALIZED VIEW" );
3221+ }
31913222/* Complete PARTITION BY with RANGE ( or LIST ( or ... */
31923223else if (TailMatches ("PARTITION" ,"BY" ))
31933224COMPLETE_WITH ("RANGE (" ,"LIST (" ,"HASH (" );
@@ -4263,9 +4294,7 @@ psql_completion(const char *text, int start, int end)
42634294/* OWNER TO - complete with available roles */
42644295else if (TailMatches ("OWNER" ,"TO" ))
42654296COMPLETE_WITH_QUERY_PLUS (Query_for_list_of_roles ,
4266- "CURRENT_ROLE" ,
4267- "CURRENT_USER" ,
4268- "SESSION_USER" );
4297+ Keywords_for_list_of_owner_roles );
42694298
42704299/* ORDER BY */
42714300else if (TailMatches ("FROM" ,MatchAny ,"ORDER" ))