@@ -202,6 +202,31 @@ do { \
202202 matches = completion_matches(text, complete_from_query); \
203203} while (0)
204204
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+
205230#define COMPLETE_WITH_FUNCTION_ARG (function ) \
206231do { \
207232 char *_completion_schema; \
@@ -598,6 +623,26 @@ static const SchemaQuery Query_for_list_of_matviews = {
598623" AND (pg_catalog.quote_ident(nspname)='%s' "\
599624" OR '\"' || nspname || '\"' ='%s') "
600625
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+
601646#define Query_for_list_of_template_databases \
602647"SELECT pg_catalog.quote_ident(d.datname) "\
603648" FROM pg_catalog.pg_database d "\
@@ -1872,11 +1917,10 @@ psql_completion(const char *text, int start, int end)
18721917 COMPLETE_WITH_LIST2 ("ATTRIBUTE" , "VALUE" );
18731918 /* ALTER TYPE <foo> RENAME */
18741919 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 ))
18781923 COMPLETE_WITH_CONST ("TO" );
1879-
18801924 /*
18811925 * If we have ALTER TYPE <sth> ALTER/DROP/RENAME ATTRIBUTE, provide list
18821926 * of attributes
@@ -1896,6 +1940,12 @@ psql_completion(const char *text, int start, int end)
18961940 else if (Matches5 ("ALTER" , "GROUP" , MatchAny , "ADD|DROP" , "USER" ))
18971941 COMPLETE_WITH_QUERY (Query_for_list_of_roles );
18981942
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+
18991949/* BEGIN */
19001950 else if (Matches1 ("BEGIN" ))
19011951 COMPLETE_WITH_LIST6 ("WORK" , "TRANSACTION" , "ISOLATION LEVEL" , "READ" , "DEFERRABLE" , "NOT DEFERRABLE" );
0 commit comments