@@ -1031,9 +1031,13 @@ static const SchemaQuery Query_for_trigger_of_table = {
1031
1031
" FROM pg_catalog.pg_roles "\
1032
1032
" WHERE rolname LIKE '%s'"
1033
1033
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
+
1034
1038
/* add these to Query_for_list_of_roles in GRANT contexts */
1035
1039
#define Keywords_for_list_of_grant_roles \
1036
- "PUBLIC" , "CURRENT_ROLE", "CURRENT_USER", "SESSION_USER "
1040
+ Keywords_for_list_of_owner_roles , "PUBLIC "
1037
1041
1038
1042
#define Query_for_all_table_constraints \
1039
1043
"SELECT conname "\
@@ -1785,8 +1789,15 @@ psql_completion(const char *text, int start, int end)
1785
1789
/* CREATE */
1786
1790
/* complete with something you can create */
1787
1791
else 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
+ }
1790
1801
/* complete with something you can create or replace */
1791
1802
else if (TailMatches ("CREATE" ,"OR" ,"REPLACE" ))
1792
1803
COMPLETE_WITH ("FUNCTION" ,"PROCEDURE" ,"LANGUAGE" ,"RULE" ,"VIEW" ,
@@ -3154,6 +3165,20 @@ psql_completion(const char *text, int start, int end)
3154
3165
else if (TailMatches ("AS" ,"ON" ,"SELECT|UPDATE|INSERT|DELETE" ,"TO" ))
3155
3166
COMPLETE_WITH_SCHEMA_QUERY (Query_for_list_of_tables );
3156
3167
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
+
3157
3182
/* CREATE SEQUENCE --- is allowed inside CREATE SCHEMA, so use TailMatches */
3158
3183
else if (TailMatches ("CREATE" ,"SEQUENCE" ,MatchAny )||
3159
3184
TailMatches ("CREATE" ,"TEMP|TEMPORARY" ,"SEQUENCE" ,MatchAny ))
@@ -3185,9 +3210,15 @@ psql_completion(const char *text, int start, int end)
3185
3210
/* Complete "CREATE TEMP/TEMPORARY" with the possible temp objects */
3186
3211
else if (TailMatches ("CREATE" ,"TEMP|TEMPORARY" ))
3187
3212
COMPLETE_WITH ("SEQUENCE" ,"TABLE" ,"VIEW" );
3188
- /* Complete "CREATE UNLOGGED" with TABLE or MATVIEW */
3213
+ /* Complete "CREATE UNLOGGED" with TABLE, SEQUENCE or MATVIEW */
3189
3214
else 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
+ }
3191
3222
/* Complete PARTITION BY with RANGE ( or LIST ( or ... */
3192
3223
else if (TailMatches ("PARTITION" ,"BY" ))
3193
3224
COMPLETE_WITH ("RANGE (" ,"LIST (" ,"HASH (" );
@@ -4263,9 +4294,7 @@ psql_completion(const char *text, int start, int end)
4263
4294
/* OWNER TO - complete with available roles */
4264
4295
else if (TailMatches ("OWNER" ,"TO" ))
4265
4296
COMPLETE_WITH_QUERY_PLUS (Query_for_list_of_roles ,
4266
- "CURRENT_ROLE" ,
4267
- "CURRENT_USER" ,
4268
- "SESSION_USER" );
4297
+ Keywords_for_list_of_owner_roles );
4269
4298
4270
4299
/* ORDER BY */
4271
4300
else if (TailMatches ("FROM" ,MatchAny ,"ORDER" ))