@@ -202,6 +202,31 @@ do { \
202
202
matches = completion_matches(text, complete_from_query); \
203
203
} while (0)
204
204
205
+ #define COMPLETE_WITH_ENUM_VALUE (type ) \
206
+ do { \
207
+ char *_completion_schema; \
208
+ char *_completion_type; \
209
+ \
210
+ _completion_schema = strtokx(type, " \t\n\r", ".", "\"", 0, \
211
+ false, false, pset.encoding); \
212
+ (void) strtokx(NULL, " \t\n\r", ".", "\"", 0, \
213
+ false, false, pset.encoding); \
214
+ _completion_type = strtokx(NULL, " \t\n\r", ".", "\"", 0, \
215
+ false, false, pset.encoding); \
216
+ if (_completion_type == NULL)\
217
+ { \
218
+ completion_charp = Query_for_list_of_enum_values; \
219
+ completion_info_charp = type; \
220
+ } \
221
+ else \
222
+ { \
223
+ completion_charp = Query_for_list_of_enum_values_with_schema; \
224
+ completion_info_charp = _completion_type; \
225
+ completion_info_charp2 = _completion_schema; \
226
+ } \
227
+ matches = completion_matches(text, complete_from_query); \
228
+ } while (0)
229
+
205
230
#define COMPLETE_WITH_FUNCTION_ARG (function ) \
206
231
do { \
207
232
char *_completion_schema; \
@@ -598,6 +623,26 @@ static const SchemaQuery Query_for_list_of_matviews = {
598
623
" AND (pg_catalog.quote_ident(nspname)='%s' "\
599
624
" OR '\"' || nspname || '\"' ='%s') "
600
625
626
+ #define Query_for_list_of_enum_values \
627
+ "SELECT pg_catalog.quote_literal(enumlabel) "\
628
+ " FROM pg_catalog.pg_enum e, pg_catalog.pg_type t "\
629
+ " WHERE t.oid = e.enumtypid "\
630
+ " AND substring(pg_catalog.quote_literal(enumlabel),1,%d)='%s' "\
631
+ " AND (pg_catalog.quote_ident(typname)='%s' "\
632
+ " OR '\"' || typname || '\"'='%s') "\
633
+ " AND pg_catalog.pg_type_is_visible(t.oid)"
634
+
635
+ #define Query_for_list_of_enum_values_with_schema \
636
+ "SELECT pg_catalog.quote_literal(enumlabel) "\
637
+ " FROM pg_catalog.pg_enum e, pg_catalog.pg_type t, pg_catalog.pg_namespace n "\
638
+ " WHERE t.oid = e.enumtypid "\
639
+ " AND n.oid = t.typnamespace "\
640
+ " AND substring(pg_catalog.quote_literal(enumlabel),1,%d)='%s' "\
641
+ " AND (pg_catalog.quote_ident(typname)='%s' "\
642
+ " OR '\"' || typname || '\"'='%s') "\
643
+ " AND (pg_catalog.quote_ident(nspname)='%s' "\
644
+ " OR '\"' || nspname || '\"' ='%s') "
645
+
601
646
#define Query_for_list_of_template_databases \
602
647
"SELECT pg_catalog.quote_ident(d.datname) "\
603
648
" FROM pg_catalog.pg_database d "\
@@ -1872,11 +1917,10 @@ psql_completion(const char *text, int start, int end)
1872
1917
COMPLETE_WITH_LIST2 ("ATTRIBUTE" , "VALUE" );
1873
1918
/* ALTER TYPE <foo> RENAME */
1874
1919
else if (Matches4 ("ALTER" , "TYPE" , MatchAny , "RENAME" ))
1875
- COMPLETE_WITH_LIST2 ("ATTRIBUTE" , "TO" );
1876
- /* ALTER TYPE xxx RENAME ATTRIBUTE yyy */
1877
- else if (Matches6 ("ALTER" , "TYPE" , MatchAny , "RENAME" , "ATTRIBUTE" , MatchAny ))
1920
+ COMPLETE_WITH_LIST3 ("ATTRIBUTE" , "TO" , "VALUE " );
1921
+ /* ALTER TYPE xxx RENAME ( ATTRIBUTE|VALUE) yyy */
1922
+ else if (Matches6 ("ALTER" , "TYPE" , MatchAny , "RENAME" , "ATTRIBUTE|VALUE " , MatchAny ))
1878
1923
COMPLETE_WITH_CONST ("TO" );
1879
-
1880
1924
/*
1881
1925
* If we have ALTER TYPE <sth> ALTER/DROP/RENAME ATTRIBUTE, provide list
1882
1926
* of attributes
@@ -1896,6 +1940,12 @@ psql_completion(const char *text, int start, int end)
1896
1940
else if (Matches5 ("ALTER" , "GROUP" , MatchAny , "ADD|DROP" , "USER" ))
1897
1941
COMPLETE_WITH_QUERY (Query_for_list_of_roles );
1898
1942
1943
+ /*
1944
+ * If we have ALTER TYPE <sth> RENAME VALUE, provide list of enum values
1945
+ */
1946
+ else if (Matches5 ("ALTER" , "TYPE" , MatchAny , "RENAME" , "VALUE" ))
1947
+ COMPLETE_WITH_ENUM_VALUE (prev3_wd );
1948
+
1899
1949
/* BEGIN */
1900
1950
else if (Matches1 ("BEGIN" ))
1901
1951
COMPLETE_WITH_LIST6 ("WORK" , "TRANSACTION" , "ISOLATION LEVEL" , "READ" , "DEFERRABLE" , "NOT DEFERRABLE" );
0 commit comments