53 #include "catalog/pg_am_d.h"
54 #include "catalog/pg_class_d.h"
68 #ifndef HAVE_RL_FILENAME_COMPLETION_FUNCTION
69 #define rl_filename_completion_function filename_completion_function
72 #ifndef HAVE_RL_COMPLETION_MATCHES
73 #define rl_completion_matches completion_matches
81 #ifdef HAVE_RL_FILENAME_QUOTING_FUNCTION
82 #define USE_FILENAME_QUOTING_FUNCTIONS 1
86 #define WORD_BREAKS "\t\n@><=;|&() "
107 typedef struct VersionedQuery
109 int min_server_version;
129 typedef struct SchemaQuery
136 int min_server_version;
152 const char *selcondition;
159 const char *viscondition;
167 const char *
namespace;
185 const char *
const *keywords;
203 const char *refviscondition;
210 const char *refnamespace;
217 static int completion_max_records;
224 static char completion_last_char;
225 static const char *completion_charp;
226 static const char *
const *completion_charpp;
227 static const VersionedQuery *completion_vquery;
228 static const SchemaQuery *completion_squery;
229 static char *completion_ref_object;
230 static char *completion_ref_schema;
231 static bool completion_case_sensitive;
232 static bool completion_verbatim;
233 static bool completion_force_quote;
256 #define COMPLETE_WITH_QUERY(query) \
257 COMPLETE_WITH_QUERY_LIST(query, NULL)
259 #define COMPLETE_WITH_QUERY_LIST(query, list) \
261 completion_charp = query; \
262 completion_charpp = list; \
263 completion_verbatim = false; \
264 matches = rl_completion_matches(text, complete_from_query); \
267 #define COMPLETE_WITH_QUERY_PLUS(query, ...) \
269 static const char *const list[] = { __VA_ARGS__, NULL }; \
270 COMPLETE_WITH_QUERY_LIST(query, list); \
273 #define COMPLETE_WITH_QUERY_VERBATIM(query) \
274 COMPLETE_WITH_QUERY_VERBATIM_LIST(query, NULL)
276 #define COMPLETE_WITH_QUERY_VERBATIM_LIST(query, list) \
278 completion_charp = query; \
279 completion_charpp = list; \
280 completion_verbatim = true; \
281 matches = rl_completion_matches(text, complete_from_query); \
284 #define COMPLETE_WITH_QUERY_VERBATIM_PLUS(query, ...) \
286 static const char *const list[] = { __VA_ARGS__, NULL }; \
287 COMPLETE_WITH_QUERY_VERBATIM_LIST(query, list); \
290 #define COMPLETE_WITH_VERSIONED_QUERY(query) \
291 COMPLETE_WITH_VERSIONED_QUERY_LIST(query, NULL)
293 #define COMPLETE_WITH_VERSIONED_QUERY_LIST(query, list) \
295 completion_vquery = query; \
296 completion_charpp = list; \
297 completion_verbatim = false; \
298 matches = rl_completion_matches(text, complete_from_versioned_query); \
301 #define COMPLETE_WITH_VERSIONED_QUERY_PLUS(query, ...) \
303 static const char *const list[] = { __VA_ARGS__, NULL }; \
304 COMPLETE_WITH_VERSIONED_QUERY_LIST(query, list); \
307 #define COMPLETE_WITH_SCHEMA_QUERY(query) \
308 COMPLETE_WITH_SCHEMA_QUERY_LIST(query, NULL)
310 #define COMPLETE_WITH_SCHEMA_QUERY_LIST(query, list) \
312 completion_squery = &(query); \
313 completion_charpp = list; \
314 completion_verbatim = false; \
315 matches = rl_completion_matches(text, complete_from_schema_query); \
318 #define COMPLETE_WITH_SCHEMA_QUERY_PLUS(query, ...) \
320 static const char *const list[] = { __VA_ARGS__, NULL }; \
321 COMPLETE_WITH_SCHEMA_QUERY_LIST(query, list); \
324 #define COMPLETE_WITH_SCHEMA_QUERY_VERBATIM(query) \
326 completion_squery = &(query); \
327 completion_charpp = NULL; \
328 completion_verbatim = true; \
329 matches = rl_completion_matches(text, complete_from_schema_query); \
332 #define COMPLETE_WITH_VERSIONED_SCHEMA_QUERY(query) \
333 COMPLETE_WITH_VERSIONED_SCHEMA_QUERY_LIST(query, NULL)
335 #define COMPLETE_WITH_VERSIONED_SCHEMA_QUERY_LIST(query, list) \
337 completion_squery = query; \
338 completion_charpp = list; \
339 completion_verbatim = false; \
340 matches = rl_completion_matches(text, complete_from_versioned_schema_query); \
343 #define COMPLETE_WITH_VERSIONED_SCHEMA_QUERY_PLUS(query, ...) \
345 static const char *const list[] = { __VA_ARGS__, NULL }; \
346 COMPLETE_WITH_VERSIONED_SCHEMA_QUERY_LIST(query, list); \
353 #define COMPLETE_WITH_CONST(cs, con) \
355 completion_case_sensitive = (cs); \
356 completion_charp = (con); \
357 matches = rl_completion_matches(text, complete_from_const); \
360 #define COMPLETE_WITH_LIST_INT(cs, list) \
362 completion_case_sensitive = (cs); \
363 completion_charpp = (list); \
364 matches = rl_completion_matches(text, complete_from_list); \
367 #define COMPLETE_WITH_LIST(list) COMPLETE_WITH_LIST_INT(false, list)
368 #define COMPLETE_WITH_LIST_CS(list) COMPLETE_WITH_LIST_INT(true, list)
370 #define COMPLETE_WITH(...) \
372 static const char *const list[] = { __VA_ARGS__, NULL }; \
373 COMPLETE_WITH_LIST(list); \
376 #define COMPLETE_WITH_CS(...) \
378 static const char *const list[] = { __VA_ARGS__, NULL }; \
379 COMPLETE_WITH_LIST_CS(list); \
382 #define COMPLETE_WITH_ATTR(relation) \
383 COMPLETE_WITH_ATTR_LIST(relation, NULL)
385 #define COMPLETE_WITH_ATTR_LIST(relation, list) \
387 set_completion_reference(relation); \
388 completion_squery = &(Query_for_list_of_attributes); \
389 completion_charpp = list; \
390 completion_verbatim = false; \
391 matches = rl_completion_matches(text, complete_from_schema_query); \
394 #define COMPLETE_WITH_ATTR_PLUS(relation, ...) \
396 static const char *const list[] = { __VA_ARGS__, NULL }; \
397 COMPLETE_WITH_ATTR_LIST(relation, list); \
406 #define COMPLETE_WITH_ENUM_VALUE(type) \
408 set_completion_reference(type); \
409 if (text[0] == '\'' || \
410 start == 0 || rl_line_buffer[start - 1] != '\'') \
411 completion_squery = &(Query_for_list_of_enum_values_quoted); \
413 completion_squery = &(Query_for_list_of_enum_values_unquoted); \
414 completion_charpp = NULL; \
415 completion_verbatim = true; \
416 matches = rl_completion_matches(text, complete_from_schema_query); \
423 #define COMPLETE_WITH_TIMEZONE_NAME() \
425 static const char *const list[] = { "DEFAULT", NULL }; \
426 if (text[0] == '\'') \
427 completion_charp = Query_for_list_of_timezone_names_quoted_in; \
428 else if (start == 0 || rl_line_buffer[start - 1] != '\'') \
429 completion_charp = Query_for_list_of_timezone_names_quoted_out; \
431 completion_charp = Query_for_list_of_timezone_names_unquoted; \
432 completion_charpp = list; \
433 completion_verbatim = true; \
434 matches = rl_completion_matches(text, complete_from_query); \
437 #define COMPLETE_WITH_FUNCTION_ARG(function) \
439 set_completion_reference(function); \
440 completion_squery = &(Query_for_list_of_arguments); \
441 completion_charpp = NULL; \
442 completion_verbatim = true; \
443 matches = rl_completion_matches(text, complete_from_schema_query); \
453 static const SchemaQuery Query_for_constraint_of_table = {
454 .catname =
"pg_catalog.pg_constraint con, pg_catalog.pg_class c1",
455 .selcondition =
"con.conrelid=c1.oid",
456 .result =
"con.conname",
457 .refname =
"c1.relname",
458 .refviscondition =
"pg_catalog.pg_table_is_visible(c1.oid)",
459 .refnamespace =
"c1.relnamespace",
462 static const SchemaQuery Query_for_constraint_of_table_not_validated = {
463 .catname =
"pg_catalog.pg_constraint con, pg_catalog.pg_class c1",
464 .selcondition =
"con.conrelid=c1.oid and not con.convalidated",
465 .result =
"con.conname",
466 .refname =
"c1.relname",
467 .refviscondition =
"pg_catalog.pg_table_is_visible(c1.oid)",
468 .refnamespace =
"c1.relnamespace",
471 static const SchemaQuery Query_for_constraint_of_type = {
472 .catname =
"pg_catalog.pg_constraint con, pg_catalog.pg_type t",
473 .selcondition =
"con.contypid=t.oid",
474 .result =
"con.conname",
475 .refname =
"t.typname",
476 .refviscondition =
"pg_catalog.pg_type_is_visible(t.oid)",
477 .refnamespace =
"t.typnamespace",
480 static const SchemaQuery Query_for_index_of_table = {
481 .catname =
"pg_catalog.pg_class c1, pg_catalog.pg_class c2, pg_catalog.pg_index i",
482 .selcondition =
"c1.oid=i.indrelid and i.indexrelid=c2.oid",
483 .result =
"c2.relname",
484 .refname =
"c1.relname",
485 .refviscondition =
"pg_catalog.pg_table_is_visible(c1.oid)",
486 .refnamespace =
"c1.relnamespace",
489 static const SchemaQuery Query_for_unique_index_of_table = {
490 .catname =
"pg_catalog.pg_class c1, pg_catalog.pg_class c2, pg_catalog.pg_index i",
491 .selcondition =
"c1.oid=i.indrelid and i.indexrelid=c2.oid and i.indisunique",
492 .result =
"c2.relname",
493 .refname =
"c1.relname",
494 .refviscondition =
"pg_catalog.pg_table_is_visible(c1.oid)",
495 .refnamespace =
"c1.relnamespace",
498 static const SchemaQuery Query_for_list_of_aggregates[] = {
500 .min_server_version = 110000,
501 .catname =
"pg_catalog.pg_proc p",
502 .selcondition =
"p.prokind = 'a'",
503 .viscondition =
"pg_catalog.pg_function_is_visible(p.oid)",
504 .namespace =
"p.pronamespace",
505 .result =
"p.proname",
508 .catname =
"pg_catalog.pg_proc p",
509 .selcondition =
"p.proisagg",
510 .viscondition =
"pg_catalog.pg_function_is_visible(p.oid)",
511 .namespace =
"p.pronamespace",
512 .result =
"p.proname",
516 static const SchemaQuery Query_for_list_of_arguments = {
517 .catname =
"pg_catalog.pg_proc p",
518 .result =
"pg_catalog.oidvectortypes(p.proargtypes)||')'",
519 .refname =
"p.proname",
520 .refviscondition =
"pg_catalog.pg_function_is_visible(p.oid)",
521 .refnamespace =
"p.pronamespace",
524 static const SchemaQuery Query_for_list_of_attributes = {
525 .catname =
"pg_catalog.pg_attribute a, pg_catalog.pg_class c",
526 .selcondition =
"c.oid = a.attrelid and a.attnum > 0 and not a.attisdropped",
527 .result =
"a.attname",
528 .refname =
"c.relname",
529 .refviscondition =
"pg_catalog.pg_table_is_visible(c.oid)",
530 .refnamespace =
"c.relnamespace",
533 static const SchemaQuery Query_for_list_of_attribute_numbers = {
534 .catname =
"pg_catalog.pg_attribute a, pg_catalog.pg_class c",
535 .selcondition =
"c.oid = a.attrelid and a.attnum > 0 and not a.attisdropped",
536 .result =
"a.attnum::pg_catalog.text",
537 .refname =
"c.relname",
538 .refviscondition =
"pg_catalog.pg_table_is_visible(c.oid)",
539 .refnamespace =
"c.relnamespace",
542 static const char *
const Keywords_for_list_of_datatypes[] = {
562 "time with time zone",
563 "time without time zone",
564 "timestamp with time zone",
565 "timestamp without time zone",
570 static const SchemaQuery Query_for_list_of_datatypes = {
571 .catname =
"pg_catalog.pg_type t",
573 .selcondition =
"(t.typrelid = 0 "
574 " OR (SELECT c.relkind = " CppAsString2(RELKIND_COMPOSITE_TYPE)
575 " FROM pg_catalog.pg_class c WHERE c.oid = t.typrelid)) "
576 "AND t.typname !~ '^_'",
577 .viscondition =
"pg_catalog.pg_type_is_visible(t.oid)",
578 .namespace =
"t.typnamespace",
579 .result =
"t.typname",
580 .keywords = Keywords_for_list_of_datatypes,
583 static const SchemaQuery Query_for_list_of_composite_datatypes = {
584 .catname =
"pg_catalog.pg_type t",
586 .selcondition =
"(SELECT c.relkind = " CppAsString2(RELKIND_COMPOSITE_TYPE)
587 " FROM pg_catalog.pg_class c WHERE c.oid = t.typrelid) "
588 "AND t.typname !~ '^_'",
589 .viscondition =
"pg_catalog.pg_type_is_visible(t.oid)",
590 .namespace =
"t.typnamespace",
591 .result =
"t.typname",
594 static const SchemaQuery Query_for_list_of_domains = {
595 .catname =
"pg_catalog.pg_type t",
596 .selcondition =
"t.typtype = 'd'",
597 .viscondition =
"pg_catalog.pg_type_is_visible(t.oid)",
598 .namespace =
"t.typnamespace",
599 .result =
"t.typname",
602 static const SchemaQuery Query_for_list_of_enum_values_quoted = {
603 .catname =
"pg_catalog.pg_enum e, pg_catalog.pg_type t",
604 .selcondition =
"t.oid = e.enumtypid",
605 .result =
"pg_catalog.quote_literal(enumlabel)",
606 .refname =
"t.typname",
607 .refviscondition =
"pg_catalog.pg_type_is_visible(t.oid)",
608 .refnamespace =
"t.typnamespace",
611 static const SchemaQuery Query_for_list_of_enum_values_unquoted = {
612 .catname =
"pg_catalog.pg_enum e, pg_catalog.pg_type t",
613 .selcondition =
"t.oid = e.enumtypid",
614 .result =
"e.enumlabel",
615 .refname =
"t.typname",
616 .refviscondition =
"pg_catalog.pg_type_is_visible(t.oid)",
617 .refnamespace =
"t.typnamespace",
621 static const SchemaQuery Query_for_list_of_functions[] = {
623 .min_server_version = 110000,
624 .catname =
"pg_catalog.pg_proc p",
625 .selcondition =
"p.prokind != 'p'",
626 .viscondition =
"pg_catalog.pg_function_is_visible(p.oid)",
627 .namespace =
"p.pronamespace",
628 .result =
"p.proname",
631 .catname =
"pg_catalog.pg_proc p",
632 .viscondition =
"pg_catalog.pg_function_is_visible(p.oid)",
633 .namespace =
"p.pronamespace",
634 .result =
"p.proname",
638 static const SchemaQuery Query_for_list_of_procedures[] = {
640 .min_server_version = 110000,
641 .catname =
"pg_catalog.pg_proc p",
642 .selcondition =
"p.prokind = 'p'",
643 .viscondition =
"pg_catalog.pg_function_is_visible(p.oid)",
644 .namespace =
"p.pronamespace",
645 .result =
"p.proname",
653 static const SchemaQuery Query_for_list_of_routines = {
654 .catname =
"pg_catalog.pg_proc p",
655 .viscondition =
"pg_catalog.pg_function_is_visible(p.oid)",
656 .namespace =
"p.pronamespace",
657 .result =
"p.proname",
660 static const SchemaQuery Query_for_list_of_sequences = {
661 .catname =
"pg_catalog.pg_class c",
662 .selcondition =
"c.relkind IN (" CppAsString2(RELKIND_SEQUENCE)
")",
663 .viscondition =
"pg_catalog.pg_table_is_visible(c.oid)",
664 .namespace =
"c.relnamespace",
665 .result =
"c.relname",
668 static const SchemaQuery Query_for_list_of_foreign_tables = {
669 .catname =
"pg_catalog.pg_class c",
670 .selcondition =
"c.relkind IN (" CppAsString2(RELKIND_FOREIGN_TABLE)
")",
671 .viscondition =
"pg_catalog.pg_table_is_visible(c.oid)",
672 .namespace =
"c.relnamespace",
673 .result =
"c.relname",
676 static const SchemaQuery Query_for_list_of_tables = {
677 .catname =
"pg_catalog.pg_class c",
681 .viscondition =
"pg_catalog.pg_table_is_visible(c.oid)",
682 .namespace =
"c.relnamespace",
683 .result =
"c.relname",
686 static const SchemaQuery Query_for_list_of_partitioned_tables = {
687 .catname =
"pg_catalog.pg_class c",
688 .selcondition =
"c.relkind IN (" CppAsString2(RELKIND_PARTITIONED_TABLE)
")",
689 .viscondition =
"pg_catalog.pg_table_is_visible(c.oid)",
690 .namespace =
"c.relnamespace",
691 .result =
"c.relname",
694 static const SchemaQuery Query_for_list_of_tables_for_constraint = {
695 .catname =
"pg_catalog.pg_class c, pg_catalog.pg_constraint con",
696 .selcondition =
"c.oid=con.conrelid and c.relkind IN ("
699 .viscondition =
"pg_catalog.pg_table_is_visible(c.oid)",
700 .namespace =
"c.relnamespace",
701 .result =
"c.relname",
702 .use_distinct =
true,
703 .refname =
"con.conname",
706 static const SchemaQuery Query_for_list_of_tables_for_policy = {
707 .catname =
"pg_catalog.pg_class c, pg_catalog.pg_policy p",
708 .selcondition =
"c.oid=p.polrelid",
709 .viscondition =
"pg_catalog.pg_table_is_visible(c.oid)",
710 .namespace =
"c.relnamespace",
711 .result =
"c.relname",
712 .use_distinct =
true,
713 .refname =
"p.polname",
716 static const SchemaQuery Query_for_list_of_tables_for_rule = {
717 .catname =
"pg_catalog.pg_class c, pg_catalog.pg_rewrite r",
718 .selcondition =
"c.oid=r.ev_class",
719 .viscondition =
"pg_catalog.pg_table_is_visible(c.oid)",
720 .namespace =
"c.relnamespace",
721 .result =
"c.relname",
722 .use_distinct =
true,
723 .refname =
"r.rulename",
726 static const SchemaQuery Query_for_list_of_tables_for_trigger = {
727 .catname =
"pg_catalog.pg_class c, pg_catalog.pg_trigger t",
728 .selcondition =
"c.oid=t.tgrelid",
729 .viscondition =
"pg_catalog.pg_table_is_visible(c.oid)",
730 .namespace =
"c.relnamespace",
731 .result =
"c.relname",
732 .use_distinct =
true,
733 .refname =
"t.tgname",
736 static const SchemaQuery Query_for_list_of_ts_configurations = {
737 .catname =
"pg_catalog.pg_ts_config c",
738 .viscondition =
"pg_catalog.pg_ts_config_is_visible(c.oid)",
739 .namespace =
"c.cfgnamespace",
740 .result =
"c.cfgname",
743 static const SchemaQuery Query_for_list_of_ts_dictionaries = {
744 .catname =
"pg_catalog.pg_ts_dict d",
745 .viscondition =
"pg_catalog.pg_ts_dict_is_visible(d.oid)",
746 .namespace =
"d.dictnamespace",
747 .result =
"d.dictname",
750 static const SchemaQuery Query_for_list_of_ts_parsers = {
751 .catname =
"pg_catalog.pg_ts_parser p",
752 .viscondition =
"pg_catalog.pg_ts_parser_is_visible(p.oid)",
753 .namespace =
"p.prsnamespace",
754 .result =
"p.prsname",
757 static const SchemaQuery Query_for_list_of_ts_templates = {
758 .catname =
"pg_catalog.pg_ts_template t",
759 .viscondition =
"pg_catalog.pg_ts_template_is_visible(t.oid)",
760 .namespace =
"t.tmplnamespace",
761 .result =
"t.tmplname",
764 static const SchemaQuery Query_for_list_of_views = {
765 .catname =
"pg_catalog.pg_class c",
766 .selcondition =
"c.relkind IN (" CppAsString2(RELKIND_VIEW)
")",
767 .viscondition =
"pg_catalog.pg_table_is_visible(c.oid)",
768 .namespace =
"c.relnamespace",
769 .result =
"c.relname",
772 static const SchemaQuery Query_for_list_of_matviews = {
773 .catname =
"pg_catalog.pg_class c",
774 .selcondition =
"c.relkind IN (" CppAsString2(RELKIND_MATVIEW)
")",
775 .viscondition =
"pg_catalog.pg_table_is_visible(c.oid)",
776 .namespace =
"c.relnamespace",
777 .result =
"c.relname",
780 static const SchemaQuery Query_for_list_of_indexes = {
781 .catname =
"pg_catalog.pg_class c",
785 .viscondition =
"pg_catalog.pg_table_is_visible(c.oid)",
786 .namespace =
"c.relnamespace",
787 .result =
"c.relname",
790 static const SchemaQuery Query_for_list_of_partitioned_indexes = {
791 .catname =
"pg_catalog.pg_class c",
792 .selcondition =
"c.relkind = " CppAsString2(RELKIND_PARTITIONED_INDEX),
793 .viscondition =
"pg_catalog.pg_table_is_visible(c.oid)",
794 .namespace =
"c.relnamespace",
795 .result =
"c.relname",
800 static const SchemaQuery Query_for_list_of_relations = {
801 .catname =
"pg_catalog.pg_class c",
802 .viscondition =
"pg_catalog.pg_table_is_visible(c.oid)",
803 .namespace =
"c.relnamespace",
804 .result =
"c.relname",
808 static const SchemaQuery Query_for_list_of_partitioned_relations = {
809 .catname =
"pg_catalog.pg_class c",
810 .selcondition =
"c.relkind IN (" CppAsString2(RELKIND_PARTITIONED_TABLE)
812 .viscondition =
"pg_catalog.pg_table_is_visible(c.oid)",
813 .namespace =
"c.relnamespace",
814 .result =
"c.relname",
817 static const SchemaQuery Query_for_list_of_operator_families = {
818 .catname =
"pg_catalog.pg_opfamily c",
819 .viscondition =
"pg_catalog.pg_opfamily_is_visible(c.oid)",
820 .namespace =
"c.opfnamespace",
821 .result =
"c.opfname",
825 static const SchemaQuery Query_for_list_of_updatables = {
826 .catname =
"pg_catalog.pg_class c",
832 .viscondition =
"pg_catalog.pg_table_is_visible(c.oid)",
833 .namespace =
"c.relnamespace",
834 .result =
"c.relname",
838 static const SchemaQuery Query_for_list_of_mergetargets = {
839 .catname =
"pg_catalog.pg_class c",
844 .viscondition =
"pg_catalog.pg_table_is_visible(c.oid)",
845 .namespace =
"c.relnamespace",
846 .result =
"c.relname",
850 static const SchemaQuery Query_for_list_of_selectables = {
851 .catname =
"pg_catalog.pg_class c",
859 .viscondition =
"pg_catalog.pg_table_is_visible(c.oid)",
860 .namespace =
"c.relnamespace",
861 .result =
"c.relname",
865 static const SchemaQuery Query_for_list_of_truncatables = {
866 .catname =
"pg_catalog.pg_class c",
871 .viscondition =
"pg_catalog.pg_table_is_visible(c.oid)",
872 .namespace =
"c.relnamespace",
873 .result =
"c.relname",
877 #define Query_for_list_of_grantables Query_for_list_of_selectables
880 static const SchemaQuery Query_for_list_of_analyzables = {
881 .catname =
"pg_catalog.pg_class c",
887 .viscondition =
"pg_catalog.pg_table_is_visible(c.oid)",
888 .namespace =
"c.relnamespace",
889 .result =
"c.relname",
893 static const SchemaQuery Query_for_list_of_indexables = {
894 .catname =
"pg_catalog.pg_class c",
899 .viscondition =
"pg_catalog.pg_table_is_visible(c.oid)",
900 .namespace =
"c.relnamespace",
901 .result =
"c.relname",
908 #define Query_for_list_of_vacuumables Query_for_list_of_indexables
911 static const SchemaQuery Query_for_list_of_clusterables = {
912 .catname =
"pg_catalog.pg_class c",
917 .viscondition =
"pg_catalog.pg_table_is_visible(c.oid)",
918 .namespace =
"c.relnamespace",
919 .result =
"c.relname",
922 static const SchemaQuery Query_for_list_of_constraints_with_schema = {
923 .catname =
"pg_catalog.pg_constraint c",
924 .selcondition =
"c.conrelid <> 0",
925 .namespace =
"c.connamespace",
926 .result =
"c.conname",
929 static const SchemaQuery Query_for_list_of_statistics = {
930 .catname =
"pg_catalog.pg_statistic_ext s",
931 .viscondition =
"pg_catalog.pg_statistics_obj_is_visible(s.oid)",
932 .namespace =
"s.stxnamespace",
933 .result =
"s.stxname",
936 static const SchemaQuery Query_for_list_of_collations = {
937 .catname =
"pg_catalog.pg_collation c",
938 .selcondition =
"c.collencoding IN (-1, pg_catalog.pg_char_to_encoding(pg_catalog.getdatabaseencoding()))",
939 .viscondition =
"pg_catalog.pg_collation_is_visible(c.oid)",
940 .namespace =
"c.collnamespace",
941 .result =
"c.collname",
944 static const SchemaQuery Query_for_partition_of_table = {
945 .catname =
"pg_catalog.pg_class c1, pg_catalog.pg_class c2, pg_catalog.pg_inherits i",
946 .selcondition =
"c1.oid=i.inhparent and i.inhrelid=c2.oid and c2.relispartition",
947 .viscondition =
"pg_catalog.pg_table_is_visible(c2.oid)",
948 .namespace =
"c2.relnamespace",
949 .result =
"c2.relname",
950 .refname =
"c1.relname",
951 .refviscondition =
"pg_catalog.pg_table_is_visible(c1.oid)",
952 .refnamespace =
"c1.relnamespace",
955 static const SchemaQuery Query_for_rule_of_table = {
956 .catname =
"pg_catalog.pg_rewrite r, pg_catalog.pg_class c1",
957 .selcondition =
"r.ev_class=c1.oid",
958 .result =
"r.rulename",
959 .refname =
"c1.relname",
960 .refviscondition =
"pg_catalog.pg_table_is_visible(c1.oid)",
961 .refnamespace =
"c1.relnamespace",
964 static const SchemaQuery Query_for_trigger_of_table = {
965 .catname =
"pg_catalog.pg_trigger t, pg_catalog.pg_class c1",
966 .selcondition =
"t.tgrelid=c1.oid and not t.tgisinternal",
967 .result =
"t.tgname",
968 .refname =
"c1.relname",
969 .refviscondition =
"pg_catalog.pg_table_is_visible(c1.oid)",
970 .refnamespace =
"c1.relnamespace",
993 #define Query_for_list_of_template_databases \
995 " FROM pg_catalog.pg_database d "\
996 " WHERE d.datname LIKE '%s' "\
997 " AND (d.datistemplate OR pg_catalog.pg_has_role(d.datdba, 'USAGE'))"
999 #define Query_for_list_of_databases \
1000 "SELECT datname FROM pg_catalog.pg_database "\
1001 " WHERE datname LIKE '%s'"
1003 #define Query_for_list_of_tablespaces \
1004 "SELECT spcname FROM pg_catalog.pg_tablespace "\
1005 " WHERE spcname LIKE '%s'"
1007 #define Query_for_list_of_encodings \
1008 " SELECT DISTINCT pg_catalog.pg_encoding_to_char(conforencoding) "\
1009 " FROM pg_catalog.pg_conversion "\
1010 " WHERE pg_catalog.pg_encoding_to_char(conforencoding) LIKE pg_catalog.upper('%s')"
1012 #define Query_for_list_of_languages \
1014 " FROM pg_catalog.pg_language "\
1015 " WHERE lanname != 'internal' "\
1016 " AND lanname LIKE '%s'"
1018 #define Query_for_list_of_schemas \
1019 "SELECT nspname FROM pg_catalog.pg_namespace "\
1020 " WHERE nspname LIKE '%s'"
1023 #define Query_for_list_of_alter_system_set_vars \
1024 "SELECT pg_catalog.lower(name) FROM pg_catalog.pg_settings "\
1025 " WHERE context != 'internal' "\
1026 " AND pg_catalog.lower(name) LIKE pg_catalog.lower('%s')"
1028 #define Query_for_list_of_set_vars \
1029 "SELECT pg_catalog.lower(name) FROM pg_catalog.pg_settings "\
1030 " WHERE context IN ('user', 'superuser') "\
1031 " AND pg_catalog.lower(name) LIKE pg_catalog.lower('%s')"
1033 #define Query_for_list_of_show_vars \
1034 "SELECT pg_catalog.lower(name) FROM pg_catalog.pg_settings "\
1035 " WHERE pg_catalog.lower(name) LIKE pg_catalog.lower('%s')"
1037 #define Query_for_list_of_roles \
1039 " FROM pg_catalog.pg_roles "\
1040 " WHERE rolname LIKE '%s'"
1043 #define Keywords_for_list_of_owner_roles \
1044 "CURRENT_ROLE", "CURRENT_USER", "SESSION_USER"
1047 #define Keywords_for_list_of_grant_roles \
1048 Keywords_for_list_of_owner_roles, "PUBLIC"
1050 #define Query_for_all_table_constraints \
1052 " FROM pg_catalog.pg_constraint c "\
1053 " WHERE c.conrelid <> 0 "\
1054 " and conname LIKE '%s'"
1056 #define Query_for_list_of_fdws \
1058 " FROM pg_catalog.pg_foreign_data_wrapper "\
1059 " WHERE fdwname LIKE '%s'"
1061 #define Query_for_list_of_servers \
1063 " FROM pg_catalog.pg_foreign_server "\
1064 " WHERE srvname LIKE '%s'"
1066 #define Query_for_list_of_user_mappings \
1068 " FROM pg_catalog.pg_user_mappings "\
1069 " WHERE usename LIKE '%s'"
1071 #define Query_for_list_of_access_methods \
1073 " FROM pg_catalog.pg_am "\
1074 " WHERE amname LIKE '%s'"
1076 #define Query_for_list_of_index_access_methods \
1078 " FROM pg_catalog.pg_am "\
1079 " WHERE amname LIKE '%s' AND "\
1080 " amtype=" CppAsString2(AMTYPE_INDEX)
1082 #define Query_for_list_of_table_access_methods \
1084 " FROM pg_catalog.pg_am "\
1085 " WHERE amname LIKE '%s' AND "\
1086 " amtype=" CppAsString2(AMTYPE_TABLE)
1088 #define Query_for_list_of_extensions \
1090 " FROM pg_catalog.pg_extension "\
1091 " WHERE extname LIKE '%s'"
1093 #define Query_for_list_of_available_extensions \
1095 " FROM pg_catalog.pg_available_extensions "\
1096 " WHERE name LIKE '%s' AND installed_version IS NULL"
1098 #define Query_for_list_of_available_extension_versions \
1100 " FROM pg_catalog.pg_available_extension_versions "\
1101 " WHERE version LIKE '%s' AND name='%s'"
1103 #define Query_for_list_of_prepared_statements \
1105 " FROM pg_catalog.pg_prepared_statements "\
1106 " WHERE name LIKE '%s'"
1108 #define Query_for_list_of_event_triggers \
1110 " FROM pg_catalog.pg_event_trigger "\
1111 " WHERE evtname LIKE '%s'"
1113 #define Query_for_list_of_tablesample_methods \
1115 " FROM pg_catalog.pg_proc "\
1116 " WHERE prorettype = 'pg_catalog.tsm_handler'::pg_catalog.regtype AND "\
1117 " proargtypes[0] = 'pg_catalog.internal'::pg_catalog.regtype AND "\
1118 " proname LIKE '%s'"
1120 #define Query_for_list_of_policies \
1122 " FROM pg_catalog.pg_policy "\
1123 " WHERE polname LIKE '%s'"
1125 #define Query_for_values_of_enum_GUC \
1126 " SELECT val FROM ( "\
1127 " SELECT name, pg_catalog.unnest(enumvals) AS val "\
1128 " FROM pg_catalog.pg_settings "\
1130 " WHERE val LIKE '%s'"\
1131 " and pg_catalog.lower(name)=pg_catalog.lower('%s')"
1133 #define Query_for_list_of_channels \
1135 " FROM pg_catalog.pg_listening_channels() AS channel "\
1136 " WHERE channel LIKE '%s'"
1138 #define Query_for_list_of_cursors \
1140 " FROM pg_catalog.pg_cursors "\
1141 " WHERE name LIKE '%s'"
1143 #define Query_for_list_of_timezone_names_unquoted \
1145 " FROM pg_catalog.pg_timezone_names() "\
1146 " WHERE pg_catalog.lower(name) LIKE pg_catalog.lower('%s')"
1148 #define Query_for_list_of_timezone_names_quoted_out \
1149 "SELECT pg_catalog.quote_literal(name) AS name "\
1150 " FROM pg_catalog.pg_timezone_names() "\
1151 " WHERE pg_catalog.lower(name) LIKE pg_catalog.lower('%s')"
1153 #define Query_for_list_of_timezone_names_quoted_in \
1154 "SELECT pg_catalog.quote_literal(name) AS name "\
1155 " FROM pg_catalog.pg_timezone_names() "\
1156 " WHERE pg_catalog.quote_literal(pg_catalog.lower(name)) LIKE pg_catalog.lower('%s')"
1159 #define Privilege_options_of_grant_and_revoke \
1160 "SELECT", "INSERT", "UPDATE", "DELETE", "TRUNCATE", "REFERENCES", "TRIGGER", \
1161 "CREATE", "CONNECT", "TEMPORARY", "EXECUTE", "USAGE", "SET", "ALTER SYSTEM", \
1165 #define Alter_procedure_options \
1166 "DEPENDS ON EXTENSION", "EXTERNAL SECURITY", "NO DEPENDS ON EXTENSION", \
1167 "OWNER TO", "RENAME TO", "RESET", "SECURITY", "SET"
1170 #define Alter_routine_options \
1171 Alter_procedure_options, "COST", "IMMUTABLE", "LEAKPROOF", "NOT LEAKPROOF", \
1172 "PARALLEL", "ROWS", "STABLE", "VOLATILE"
1175 #define Alter_function_options \
1176 Alter_routine_options, "CALLED ON NULL INPUT", "RETURNS NULL ON NULL INPUT", \
1185 static const VersionedQuery Query_for_list_of_publications[] = {
1188 " FROM pg_catalog.pg_publication "
1189 " WHERE pubname LIKE '%s'"
1194 static const VersionedQuery Query_for_list_of_subscriptions[] = {
1196 " SELECT s.subname "
1197 " FROM pg_catalog.pg_subscription s, pg_catalog.pg_database d "
1198 " WHERE s.subname LIKE '%s' "
1199 " AND d.datname = pg_catalog.current_database() "
1200 " AND s.subdbid = d.oid"
1206 static const char *
const sql_commands[] = {
1207 "ABORT",
"ALTER",
"ANALYZE",
"BEGIN",
"CALL",
"CHECKPOINT",
"CLOSE",
"CLUSTER",
1208 "COMMENT",
"COMMIT",
"COPY",
"CREATE",
"DEALLOCATE",
"DECLARE",
1209 "DELETE FROM",
"DISCARD",
"DO",
"DROP",
"END",
"EXECUTE",
"EXPLAIN",
1210 "FETCH",
"GRANT",
"IMPORT FOREIGN SCHEMA",
"INSERT INTO",
"LISTEN",
"LOAD",
"LOCK",
1211 "MERGE INTO",
"MOVE",
"NOTIFY",
"PREPARE",
1212 "REASSIGN",
"REFRESH MATERIALIZED VIEW",
"REINDEX",
"RELEASE",
1213 "RESET",
"REVOKE",
"ROLLBACK",
1214 "SAVEPOINT",
"SECURITY LABEL",
"SELECT",
"SET",
"SHOW",
"START",
1215 "TABLE",
"TRUNCATE",
"UNLISTEN",
"UPDATE",
"VACUUM",
"VALUES",
"WITH",
1229 const VersionedQuery *vquery;
1230 const SchemaQuery *squery;
1231 const char *
const *keywords;
1235 #define THING_NO_CREATE (1 << 0)
1236 #define THING_NO_DROP (1 << 1)
1237 #define THING_NO_ALTER (1 << 2)
1238 #define THING_NO_SHOW (THING_NO_CREATE | THING_NO_DROP | THING_NO_ALTER)
1241 static const char *
const Keywords_for_user_thing[] = {
1246 static const pgsql_thing_t words_after_create[] = {
1247 {
"ACCESS METHOD", NULL, NULL, NULL, NULL, THING_NO_ALTER},
1248 {
"AGGREGATE", NULL, NULL, Query_for_list_of_aggregates},
1249 {
"CAST", NULL, NULL, NULL},
1251 {
"COLLATION", NULL, NULL, &Query_for_list_of_collations},
1257 {
"CONFIGURATION", NULL, NULL, &Query_for_list_of_ts_configurations, NULL, THING_NO_SHOW},
1258 {
"CONVERSION",
"SELECT conname FROM pg_catalog.pg_conversion WHERE conname LIKE '%s'"},
1259 {
"DATABASE", Query_for_list_of_databases},
1260 {
"DEFAULT PRIVILEGES", NULL, NULL, NULL, NULL, THING_NO_CREATE | THING_NO_DROP},
1261 {
"DICTIONARY", NULL, NULL, &Query_for_list_of_ts_dictionaries, NULL, THING_NO_SHOW},
1262 {
"DOMAIN", NULL, NULL, &Query_for_list_of_domains},
1263 {
"EVENT TRIGGER", NULL, NULL, NULL},
1264 {
"EXTENSION", Query_for_list_of_extensions},
1265 {
"FOREIGN DATA WRAPPER", NULL, NULL, NULL},
1266 {
"FOREIGN TABLE", NULL, NULL, NULL},
1267 {
"FUNCTION", NULL, NULL, Query_for_list_of_functions},
1268 {
"GROUP", Query_for_list_of_roles},
1269 {
"INDEX", NULL, NULL, &Query_for_list_of_indexes},
1270 {
"LANGUAGE", Query_for_list_of_languages},
1271 {
"LARGE OBJECT", NULL, NULL, NULL, NULL, THING_NO_CREATE | THING_NO_DROP},
1272 {
"MATERIALIZED VIEW", NULL, NULL, &Query_for_list_of_matviews},
1273 {
"OPERATOR", NULL, NULL, NULL},
1275 {
"OR REPLACE", NULL, NULL, NULL, NULL, THING_NO_DROP | THING_NO_ALTER},
1276 {
"OWNED", NULL, NULL, NULL, NULL, THING_NO_CREATE | THING_NO_ALTER},
1277 {
"PARSER", NULL, NULL, &Query_for_list_of_ts_parsers, NULL, THING_NO_SHOW},
1278 {
"POLICY", NULL, NULL, NULL},
1279 {
"PROCEDURE", NULL, NULL, Query_for_list_of_procedures},
1280 {
"PUBLICATION", NULL, Query_for_list_of_publications},
1281 {
"ROLE", Query_for_list_of_roles},
1282 {
"ROUTINE", NULL, NULL, &Query_for_list_of_routines, NULL, THING_NO_CREATE},
1283 {
"RULE",
"SELECT rulename FROM pg_catalog.pg_rules WHERE rulename LIKE '%s'"},
1284 {
"SCHEMA", Query_for_list_of_schemas},
1285 {
"SEQUENCE", NULL, NULL, &Query_for_list_of_sequences},
1286 {
"SERVER", Query_for_list_of_servers},
1287 {
"STATISTICS", NULL, NULL, &Query_for_list_of_statistics},
1288 {
"SUBSCRIPTION", NULL, Query_for_list_of_subscriptions},
1289 {
"SYSTEM", NULL, NULL, NULL, NULL, THING_NO_CREATE | THING_NO_DROP},
1290 {
"TABLE", NULL, NULL, &Query_for_list_of_tables},
1291 {
"TABLESPACE", Query_for_list_of_tablespaces},
1292 {
"TEMP", NULL, NULL, NULL, NULL, THING_NO_DROP | THING_NO_ALTER},
1294 {
"TEMPLATE", NULL, NULL, &Query_for_list_of_ts_templates, NULL, THING_NO_SHOW},
1295 {
"TEMPORARY", NULL, NULL, NULL, NULL, THING_NO_DROP | THING_NO_ALTER},
1297 {
"TEXT SEARCH", NULL, NULL, NULL},
1298 {
"TRANSFORM", NULL, NULL, NULL, NULL, THING_NO_ALTER},
1299 {
"TRIGGER",
"SELECT tgname FROM pg_catalog.pg_trigger WHERE tgname LIKE '%s' AND NOT tgisinternal"},
1300 {
"TYPE", NULL, NULL, &Query_for_list_of_datatypes},
1301 {
"UNIQUE", NULL, NULL, NULL, NULL, THING_NO_DROP | THING_NO_ALTER},
1303 {
"UNLOGGED", NULL, NULL, NULL, NULL, THING_NO_DROP | THING_NO_ALTER},
1305 {
"USER", Query_for_list_of_roles, NULL, NULL, Keywords_for_user_thing},
1306 {
"USER MAPPING FOR", NULL, NULL, NULL},
1307 {
"VIEW", NULL, NULL, &Query_for_list_of_views},
1329 #define MatchAny NULL
1330 #define MatchAnyExcept(pattern) ("!" pattern)
1331 #define MatchAnyN ""
1337 enum TCPatternKind kind;
1339 const char *
const *words;
1343 #define TCPAT(id, kind, ...) \
1344 { (id), (kind), VA_ARGS_NARGS(__VA_ARGS__), \
1345 (const char * const []) { __VA_ARGS__ } }
1347 #ifdef SWITCH_CONVERSION_APPLIED
1349 static const TCPattern tcpatterns[] =
1357 static const char *
const table_storage_parameters[] = {
1358 "autovacuum_analyze_scale_factor",
1359 "autovacuum_analyze_threshold",
1360 "autovacuum_enabled",
1361 "autovacuum_freeze_max_age",
1362 "autovacuum_freeze_min_age",
1363 "autovacuum_freeze_table_age",
1364 "autovacuum_multixact_freeze_max_age",
1365 "autovacuum_multixact_freeze_min_age",
1366 "autovacuum_multixact_freeze_table_age",
1367 "autovacuum_vacuum_cost_delay",
1368 "autovacuum_vacuum_cost_limit",
1369 "autovacuum_vacuum_insert_scale_factor",
1370 "autovacuum_vacuum_insert_threshold",
1371 "autovacuum_vacuum_scale_factor",
1372 "autovacuum_vacuum_threshold",
1374 "log_autovacuum_min_duration",
1376 "toast.autovacuum_enabled",
1377 "toast.autovacuum_freeze_max_age",
1378 "toast.autovacuum_freeze_min_age",
1379 "toast.autovacuum_freeze_table_age",
1380 "toast.autovacuum_multixact_freeze_max_age",
1381 "toast.autovacuum_multixact_freeze_min_age",
1382 "toast.autovacuum_multixact_freeze_table_age",
1383 "toast.autovacuum_vacuum_cost_delay",
1384 "toast.autovacuum_vacuum_cost_limit",
1385 "toast.autovacuum_vacuum_insert_scale_factor",
1386 "toast.autovacuum_vacuum_insert_threshold",
1387 "toast.autovacuum_vacuum_scale_factor",
1388 "toast.autovacuum_vacuum_threshold",
1389 "toast.log_autovacuum_min_duration",
1390 "toast.vacuum_index_cleanup",
1391 "toast.vacuum_truncate",
1392 "toast_tuple_target",
1393 "user_catalog_table",
1394 "vacuum_index_cleanup",
1400 static const char *
const view_optional_parameters[] = {
1408 static char **psql_completion(
const char *
text,
int start,
int end);
1409 static char **match_previous_words(
int pattern_id,
1411 char **previous_words,
1412 int previous_words_count);
1413 static char *create_command_generator(
const char *
text,
int state);
1414 static char *drop_command_generator(
const char *
text,
int state);
1415 static char *alter_command_generator(
const char *
text,
int state);
1416 static char *complete_from_query(
const char *
text,
int state);
1417 static char *complete_from_versioned_query(
const char *
text,
int state);
1418 static char *complete_from_schema_query(
const char *
text,
int state);
1419 static char *complete_from_versioned_schema_query(
const char *
text,
int state);
1420 static char *_complete_from_query(
const char *simple_query,
1421 const SchemaQuery *schema_query,
1422 const char *
const *keywords,
1425 static void set_completion_reference(
const char *
word);
1426 static void set_completion_reference_verbatim(
const char *
word);
1427 static char *complete_from_list(
const char *
text,
int state);
1428 static char *complete_from_const(
const char *
text,
int state);
1429 static void append_variable_names(
char ***varnames,
int *nvars,
1430 int *maxvars,
const char *varname,
1431 const char *prefix,
const char *suffix);
1432 static char **complete_from_variables(
const char *
text,
1433 const char *prefix,
const char *suffix,
bool need_value);
1434 static char *complete_from_files(
const char *
text,
int state);
1436 static char *pg_strdup_keyword_case(
const char *s,
const char *ref);
1437 static char *escape_string(
const char *
text);
1438 static char *make_like_pattern(
const char *
word);
1439 static void parse_identifier(
const char *
ident,
1440 char **schemaname,
char **objectname,
1441 bool *schemaquoted,
bool *objectquoted);
1442 static char *requote_identifier(
const char *schemaname,
const char *objectname,
1443 bool quote_schema,
bool quote_object);
1444 static bool identifier_needs_quotes(
const char *
ident);
1445 static PGresult *exec_query(
const char *query);
1447 static char **get_previous_words(
int point,
char **buffer,
int *nwords);
1449 static char *get_guctype(
const char *varname);
1451 #ifdef USE_FILENAME_QUOTING_FUNCTIONS
1452 static char *quote_file_name(
char *fname,
int match_type,
char *quote_pointer);
1453 static char *dequote_file_name(
char *fname,
int quote_char);
1464 rl_attempted_completion_function = psql_completion;
1466 #ifdef USE_FILENAME_QUOTING_FUNCTIONS
1467 rl_filename_quoting_function = quote_file_name;
1468 rl_filename_dequoting_function = dequote_file_name;
1471 rl_basic_word_break_characters = WORD_BREAKS;
1480 rl_completer_quote_characters =
"'";
1488 #ifdef HAVE_RL_FILENAME_QUOTE_CHARACTERS
1490 unsigned char *fqc = (
unsigned char *)
pg_malloc(256);
1492 for (
int i = 0;
i < 255;
i++)
1493 fqc[
i] = (
unsigned char) (
i + 1);
1495 rl_filename_quote_characters = (
const char *) fqc;
1499 completion_max_records = 1000;
1523 word_matches(
const char *pattern,
1525 bool case_sensitive)
1529 #define cimatch(s1, s2, n) \
1530 (case_sensitive ? strncmp(s1, s2, n) == 0 : pg_strncasecmp(s1, s2, n) == 0)
1533 if (pattern == NULL)
1537 if (*pattern ==
'!')
1538 return !word_matches(pattern + 1,
word, case_sensitive);
1541 wordlen = strlen(
word);
1544 const char *star = NULL;
1549 while (*
c !=
'\0' && *
c !=
'|')
1559 size_t beforelen = star - pattern,
1560 afterlen =
c - star - 1;
1562 if (wordlen >= (beforelen + afterlen) &&
1563 cimatch(
word, pattern, beforelen) &&
1564 cimatch(
word + wordlen - afterlen, star + 1, afterlen))
1570 if (wordlen == (
c - pattern) &&
1571 cimatch(
word, pattern, wordlen))
1592 TailMatchesArray(
bool case_sensitive,
1593 int previous_words_count,
char **previous_words,
1594 int narg,
const char *
const *
args)
1596 if (previous_words_count < narg)
1599 for (
int argno = 0; argno < narg; argno++)
1601 const char *
arg =
args[argno];
1603 if (!word_matches(
arg, previous_words[narg - argno - 1],
1615 TailMatchesImpl(
bool case_sensitive,
1616 int previous_words_count,
char **previous_words,
1619 const char *argarray[64];
1624 if (previous_words_count < narg)
1628 for (
int argno = 0; argno < narg; argno++)
1629 argarray[argno] = va_arg(
args,
const char *);
1632 return TailMatchesArray(case_sensitive,
1633 previous_words_count, previous_words,
1642 HeadMatchesArray(
bool case_sensitive,
1643 int previous_words_count,
char **previous_words,
1644 int narg,
const char *
const *
args)
1646 if (previous_words_count < narg)
1649 for (
int argno = 0; argno < narg; argno++)
1651 const char *
arg =
args[argno];
1653 if (!word_matches(
arg, previous_words[previous_words_count - argno - 1],
1665 HeadMatchesImpl(
bool case_sensitive,
1666 int previous_words_count,
char **previous_words,
1669 const char *argarray[64];
1674 if (previous_words_count < narg)
1678 for (
int argno = 0; argno < narg; argno++)
1679 argarray[argno] = va_arg(
args,
const char *);
1682 return HeadMatchesArray(case_sensitive,
1683 previous_words_count, previous_words,
1695 MatchesArray(
bool case_sensitive,
1696 int previous_words_count,
char **previous_words,
1697 int narg,
const char *
const *
args)
1699 int match_any_pos = -1;
1702 if (previous_words_count < narg - 1)
1706 for (
int argno = 0; argno < narg; argno++)
1708 const char *
arg =
args[argno];
1710 if (
arg != NULL &&
arg[0] ==
'\0')
1712 match_any_pos = argno;
1717 if (match_any_pos < 0)
1720 if (previous_words_count != narg)
1724 if (!HeadMatchesArray(case_sensitive,
1725 previous_words_count, previous_words,
1732 if (!HeadMatchesArray(case_sensitive,
1733 previous_words_count, previous_words,
1734 match_any_pos,
args))
1738 if (!TailMatchesArray(case_sensitive,
1739 previous_words_count, previous_words,
1740 narg - match_any_pos - 1,
1741 args + match_any_pos + 1))
1752 MatchesImpl(
bool case_sensitive,
1753 int previous_words_count,
char **previous_words,
1756 const char *argarray[64];
1762 if (previous_words_count < narg - 1)
1766 for (
int argno = 0; argno < narg; argno++)
1767 argarray[argno] = va_arg(
args,
const char *);
1770 return MatchesArray(case_sensitive,
1771 previous_words_count, previous_words,
1779 ends_with(
const char *s,
char c)
1781 size_t length = strlen(s);
1783 return (length > 0 && s[length - 1] ==
c);
1795 psql_completion(
const char *
text,
int start,
int end)
1798 char **matches = NULL;
1804 char **previous_words;
1807 int previous_words_count;
1816 #define prev_wd (previous_words[0])
1817 #define prev2_wd (previous_words[1])
1818 #define prev3_wd (previous_words[2])
1819 #define prev4_wd (previous_words[3])
1820 #define prev5_wd (previous_words[4])
1821 #define prev6_wd (previous_words[5])
1822 #define prev7_wd (previous_words[6])
1823 #define prev8_wd (previous_words[7])
1824 #define prev9_wd (previous_words[8])
1827 #define TailMatches(...) \
1828 TailMatchesImpl(false, previous_words_count, previous_words, \
1829 VA_ARGS_NARGS(__VA_ARGS__), __VA_ARGS__)
1832 #define TailMatchesCS(...) \
1833 TailMatchesImpl(true, previous_words_count, previous_words, \
1834 VA_ARGS_NARGS(__VA_ARGS__), __VA_ARGS__)
1837 #define Matches(...) \
1838 MatchesImpl(false, previous_words_count, previous_words, \
1839 VA_ARGS_NARGS(__VA_ARGS__), __VA_ARGS__)
1842 #define MatchesCS(...) \
1843 MatchesImpl(true, previous_words_count, previous_words, \
1844 VA_ARGS_NARGS(__VA_ARGS__), __VA_ARGS__)
1847 #define HeadMatches(...) \
1848 HeadMatchesImpl(false, previous_words_count, previous_words, \
1849 VA_ARGS_NARGS(__VA_ARGS__), __VA_ARGS__)
1852 #define HeadMatchesCS(...) \
1853 HeadMatchesImpl(true, previous_words_count, previous_words, \
1854 VA_ARGS_NARGS(__VA_ARGS__), __VA_ARGS__)
1857 static const char *
const backslash_commands[] = {
1859 "\\bind",
"\\bind_named",
1860 "\\connect",
"\\conninfo",
"\\C",
"\\cd",
"\\close",
"\\copy",
1861 "\\copyright",
"\\crosstabview",
1862 "\\d",
"\\da",
"\\dA",
"\\dAc",
"\\dAf",
"\\dAo",
"\\dAp",
1863 "\\db",
"\\dc",
"\\dconfig",
"\\dC",
"\\dd",
"\\ddp",
"\\dD",
1864 "\\des",
"\\det",
"\\deu",
"\\dew",
"\\dE",
"\\df",
1865 "\\dF",
"\\dFd",
"\\dFp",
"\\dFt",
"\\dg",
"\\di",
"\\dl",
"\\dL",
1866 "\\dm",
"\\dn",
"\\do",
"\\dO",
"\\dp",
"\\dP",
"\\dPi",
"\\dPt",
1867 "\\drds",
"\\drg",
"\\dRs",
"\\dRp",
"\\ds",
1868 "\\dt",
"\\dT",
"\\dv",
"\\du",
"\\dx",
"\\dX",
"\\dy",
1869 "\\echo",
"\\edit",
"\\ef",
"\\elif",
"\\else",
"\\encoding",
1870 "\\endif",
"\\errverbose",
"\\ev",
1872 "\\g",
"\\gdesc",
"\\getenv",
"\\gexec",
"\\gset",
"\\gx",
1874 "\\if",
"\\include",
"\\include_relative",
"\\ir",
1875 "\\list",
"\\lo_import",
"\\lo_export",
"\\lo_list",
"\\lo_unlink",
1877 "\\parse",
"\\password",
"\\print",
"\\prompt",
"\\pset",
1878 "\\qecho",
"\\quit",
1880 "\\s",
"\\set",
"\\setenv",
"\\sf",
"\\sv",
1881 "\\t",
"\\T",
"\\timing",
1884 "\\warn",
"\\watch",
"\\write",
1899 completion_last_char = (end >
start) ?
text[end -
start - 1] :
'\0';
1902 rl_completion_append_character =
' ';
1905 completion_charp = NULL;
1906 completion_charpp = NULL;
1907 completion_vquery = NULL;
1908 completion_squery = NULL;
1909 completion_ref_object = NULL;
1910 completion_ref_schema = NULL;
1917 previous_words = get_previous_words(
start,
1919 &previous_words_count);
1922 if (
text[0] ==
'\\')
1923 COMPLETE_WITH_LIST_CS(backslash_commands);
1926 else if (
text[0] ==
':' &&
text[1] !=
':')
1928 if (
text[1] ==
'\'')
1929 matches = complete_from_variables(
text,
":'",
"'",
true);
1930 else if (
text[1] ==
'"')
1931 matches = complete_from_variables(
text,
":\"",
"\"",
true);
1932 else if (
text[1] ==
'{' &&
text[2] ==
'?')
1933 matches = complete_from_variables(
text,
":{?",
"}",
true);
1935 matches = complete_from_variables(
text,
":",
"",
true);
1939 else if (previous_words_count == 0)
1940 COMPLETE_WITH_LIST(sql_commands);
1945 #ifdef SWITCH_CONVERSION_APPLIED
1958 for (
int tindx = 0; tindx <
lengthof(tcpatterns); tindx++)
1960 const TCPattern *tcpat = tcpatterns + tindx;
1963 switch (tcpat->kind)
1966 match = MatchesArray(
false,
1967 previous_words_count,
1969 tcpat->nwords, tcpat->words);
1972 match = MatchesArray(
true,
1973 previous_words_count,
1975 tcpat->nwords, tcpat->words);
1978 match = HeadMatchesArray(
false,
1979 previous_words_count,
1981 tcpat->nwords, tcpat->words);
1984 match = HeadMatchesArray(
true,
1985 previous_words_count,
1987 tcpat->nwords, tcpat->words);
1990 match = TailMatchesArray(
false,
1991 previous_words_count,
1993 tcpat->nwords, tcpat->words);
1996 match = TailMatchesArray(
true,
1997 previous_words_count,
1999 tcpat->nwords, tcpat->words);
2004 matches = match_previous_words(tcpat->id,
text,
start, end,
2006 previous_words_count);
2007 if (matches != NULL)
2016 matches = match_previous_words(0,
text,
start, end,
2018 previous_words_count);
2027 if (matches == NULL && previous_words_count > 0)
2029 const pgsql_thing_t *wac;
2031 for (wac = words_after_create; wac->name != NULL; wac++)
2036 COMPLETE_WITH_QUERY_LIST(wac->query,
2038 else if (wac->vquery)
2039 COMPLETE_WITH_VERSIONED_QUERY_LIST(wac->vquery,
2041 else if (wac->squery)
2042 COMPLETE_WITH_VERSIONED_SCHEMA_QUERY_LIST(wac->squery,
2054 if (matches == NULL)
2056 COMPLETE_WITH_CONST(
true,
"");
2058 rl_completion_append_character =
'\0';
2059 #ifdef HAVE_RL_COMPLETION_SUPPRESS_QUOTE
2060 rl_completion_suppress_quote = 1;
2065 free(previous_words);
2068 free(completion_ref_object);
2069 completion_ref_object = NULL;
2070 free(completion_ref_schema);
2071 completion_ref_schema = NULL;
2116 match_previous_words(
int pattern_id,
2118 char **previous_words,
int previous_words_count)
2121 char **matches = NULL;
2134 else if (TailMatches(
"CREATE"))
2137 if (HeadMatches(
"CREATE",
"SCHEMA"))
2138 COMPLETE_WITH(
"TABLE",
"VIEW",
"INDEX",
"SEQUENCE",
"TRIGGER",
2140 "UNIQUE",
"UNLOGGED");
2142 matches = rl_completion_matches(
text, create_command_generator);
2145 else if (TailMatches(
"CREATE",
"OR",
"REPLACE"))
2146 COMPLETE_WITH(
"FUNCTION",
"PROCEDURE",
"LANGUAGE",
"RULE",
"VIEW",
2147 "AGGREGATE",
"TRANSFORM",
"TRIGGER");
2151 else if (Matches(
"DROP"))
2152 matches = rl_completion_matches(
text, drop_command_generator);
2157 else if (Matches(
"ALTER",
"TABLE"))
2158 COMPLETE_WITH_SCHEMA_QUERY_PLUS(Query_for_list_of_tables,
2159 "ALL IN TABLESPACE");
2162 else if (Matches(
"ALTER"))
2163 matches = rl_completion_matches(
text, alter_command_generator);
2165 else if (TailMatches(
"ALL",
"IN",
"TABLESPACE", MatchAny))
2166 COMPLETE_WITH(
"SET TABLESPACE",
"OWNED BY");
2168 else if (TailMatches(
"ALL",
"IN",
"TABLESPACE", MatchAny,
"OWNED",
"BY"))
2169 COMPLETE_WITH_QUERY(Query_for_list_of_roles);
2171 else if (TailMatches(
"ALL",
"IN",
"TABLESPACE", MatchAny,
"OWNED",
"BY", MatchAny))
2172 COMPLETE_WITH(
"SET TABLESPACE");
2174 else if (Matches(
"ALTER",
"AGGREGATE|FUNCTION|PROCEDURE|ROUTINE", MatchAny))
2177 else if (Matches(
"ALTER",
"AGGREGATE", MatchAny, MatchAny))
2179 if (ends_with(prev_wd,
')'))
2180 COMPLETE_WITH(
"OWNER TO",
"RENAME TO",
"SET SCHEMA");
2182 COMPLETE_WITH_FUNCTION_ARG(prev2_wd);
2185 else if (Matches(
"ALTER",
"FUNCTION", MatchAny, MatchAny))
2187 if (ends_with(prev_wd,
')'))
2188 COMPLETE_WITH(Alter_function_options);
2190 COMPLETE_WITH_FUNCTION_ARG(prev2_wd);
2193 else if (Matches(
"ALTER",
"PROCEDURE", MatchAny, MatchAny))
2195 if (ends_with(prev_wd,
')'))
2196 COMPLETE_WITH(Alter_procedure_options);
2198 COMPLETE_WITH_FUNCTION_ARG(prev2_wd);
2201 else if (Matches(
"ALTER",
"ROUTINE", MatchAny, MatchAny))
2203 if (ends_with(prev_wd,
')'))
2204 COMPLETE_WITH(Alter_routine_options);
2206 COMPLETE_WITH_FUNCTION_ARG(prev2_wd);
2209 else if (Matches(
"ALTER",
"FUNCTION|ROUTINE", MatchAny, MatchAny,
"PARALLEL"))
2210 COMPLETE_WITH(
"RESTRICTED",
"SAFE",
"UNSAFE");
2212 else if (Matches(
"ALTER",
"FUNCTION|PROCEDURE|ROUTINE", MatchAny, MatchAny,
"SECURITY") ||
2213 Matches(
"ALTER",
"FUNCTION|PROCEDURE|ROUTINE", MatchAny, MatchAny,
"EXTERNAL",
"SECURITY"))
2214 COMPLETE_WITH(
"DEFINER",
"INVOKER");
2216 else if (Matches(
"ALTER",
"FUNCTION|PROCEDURE|ROUTINE", MatchAny, MatchAny,
"RESET"))
2217 COMPLETE_WITH_QUERY_VERBATIM_PLUS(Query_for_list_of_set_vars,
2220 else if (Matches(
"ALTER",
"FUNCTION|PROCEDURE|ROUTINE", MatchAny, MatchAny,
"SET"))
2221 COMPLETE_WITH_QUERY_VERBATIM_PLUS(Query_for_list_of_set_vars,
2225 else if (Matches(
"ALTER",
"PUBLICATION", MatchAny))
2226 COMPLETE_WITH(
"ADD",
"DROP",
"OWNER TO",
"RENAME TO",
"SET");
2228 else if (Matches(
"ALTER",
"PUBLICATION", MatchAny,
"ADD"))
2229 COMPLETE_WITH(
"TABLES IN SCHEMA",
"TABLE");
2230 else if (Matches(
"ALTER",
"PUBLICATION", MatchAny,
"ADD|SET",
"TABLE"))
2231 COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_tables);
2232 else if (HeadMatches(
"ALTER",
"PUBLICATION", MatchAny,
"ADD|SET",
"TABLE") &&
2233 ends_with(prev_wd,
','))
2234 COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_tables);
2243 else if (Matches(
"ALTER",
"PUBLICATION", MatchAny, MatchAnyN,
"WHERE"))
2245 else if (Matches(
"ALTER",
"PUBLICATION", MatchAny, MatchAnyN,
"WHERE",
"("))
2246 COMPLETE_WITH_ATTR(prev3_wd);
2247 else if (HeadMatches(
"ALTER",
"PUBLICATION", MatchAny,
"ADD|SET",
"TABLE") &&
2248 !TailMatches(
"WHERE",
"(*)"))
2249 COMPLETE_WITH(
",",
"WHERE (");
2250 else if (HeadMatches(
"ALTER",
"PUBLICATION", MatchAny,
"ADD|SET",
"TABLE"))
2253 else if (Matches(
"ALTER",
"PUBLICATION", MatchAny,
"DROP"))
2254 COMPLETE_WITH(
"TABLES IN SCHEMA",
"TABLE");
2256 else if (Matches(
"ALTER",
"PUBLICATION", MatchAny,
"SET"))
2257 COMPLETE_WITH(
"(",
"TABLES IN SCHEMA",
"TABLE");
2258 else if (Matches(
"ALTER",
"PUBLICATION", MatchAny,
"ADD|DROP|SET",
"TABLES",
"IN",
"SCHEMA"))
2259 COMPLETE_WITH_QUERY_PLUS(Query_for_list_of_schemas
2260 " AND nspname NOT LIKE E'pg\\\\_%%'",
2263 else if (Matches(
"ALTER",
"PUBLICATION", MatchAny, MatchAnyN,
"SET",
"("))
2264 COMPLETE_WITH(
"publish",
"publish_generated_columns",
"publish_via_partition_root");
2266 else if (Matches(
"ALTER",
"SUBSCRIPTION", MatchAny))
2267 COMPLETE_WITH(
"CONNECTION",
"ENABLE",
"DISABLE",
"OWNER TO",
2268 "RENAME TO",
"REFRESH PUBLICATION",
"SET",
"SKIP (",
2269 "ADD PUBLICATION",
"DROP PUBLICATION");
2271 else if (Matches(
"ALTER",
"SUBSCRIPTION", MatchAny, MatchAnyN,
"REFRESH",
"PUBLICATION"))
2272 COMPLETE_WITH(
"WITH (");
2274 else if (Matches(
"ALTER",
"SUBSCRIPTION", MatchAny, MatchAnyN,
"REFRESH",
"PUBLICATION",
"WITH",
"("))
2275 COMPLETE_WITH(
"copy_data");
2277 else if (Matches(
"ALTER",
"SUBSCRIPTION", MatchAny,
"SET"))
2278 COMPLETE_WITH(
"(",
"PUBLICATION");
2280 else if (Matches(
"ALTER",
"SUBSCRIPTION", MatchAny, MatchAnyN,
"SET",
"("))
2281 COMPLETE_WITH(
"binary",
"disable_on_error",
"failover",
"origin",
2282 "password_required",
"run_as_owner",
"slot_name",
2283 "streaming",
"synchronous_commit",
"two_phase");
2285 else if (Matches(
"ALTER",
"SUBSCRIPTION", MatchAny, MatchAnyN,
"SKIP",
"("))
2286 COMPLETE_WITH(
"lsn");
2288 else if (Matches(
"ALTER",
"SUBSCRIPTION", MatchAny, MatchAnyN,
"SET",
"PUBLICATION"))
2293 else if (Matches(
"ALTER",
"SUBSCRIPTION", MatchAny, MatchAnyN,
2294 "ADD|DROP|SET",
"PUBLICATION", MatchAny))
2295 COMPLETE_WITH(
"WITH (");
2297 else if (Matches(
"ALTER",
"SUBSCRIPTION", MatchAny, MatchAnyN,
2298 "ADD|DROP|SET",
"PUBLICATION", MatchAny,
"WITH",
"("))
2299 COMPLETE_WITH(
"copy_data",
"refresh");
2302 else if (Matches(
"ALTER",
"SCHEMA", MatchAny))
2303 COMPLETE_WITH(
"OWNER TO",
"RENAME TO");
2306 else if (Matches(
"ALTER",
"COLLATION", MatchAny))
2307 COMPLETE_WITH(
"OWNER TO",
"REFRESH VERSION",
"RENAME TO",
"SET SCHEMA");
2310 else if (Matches(
"ALTER",
"CONVERSION", MatchAny))
2311 COMPLETE_WITH(
"OWNER TO",
"RENAME TO",
"SET SCHEMA");
2314 else if (Matches(
"ALTER",
"DATABASE", MatchAny))
2315 COMPLETE_WITH(
"RESET",
"SET",
"OWNER TO",
"REFRESH COLLATION VERSION",
"RENAME TO",
2316 "IS_TEMPLATE",
"ALLOW_CONNECTIONS",
2317 "CONNECTION LIMIT");
2320 else if (Matches(
"ALTER",
"DATABASE", MatchAny,
"SET",
"TABLESPACE"))
2321 COMPLETE_WITH_QUERY(Query_for_list_of_tablespaces);
2324 else if (Matches(
"ALTER",
"EVENT",
"TRIGGER"))
2325 COMPLETE_WITH_QUERY(Query_for_list_of_event_triggers);
2328 else if (Matches(
"ALTER",
"EVENT",
"TRIGGER", MatchAny))
2329 COMPLETE_WITH(
"DISABLE",
"ENABLE",
"OWNER TO",
"RENAME TO");
2332 else if (Matches(
"ALTER",
"EVENT",
"TRIGGER", MatchAny,
"ENABLE"))
2333 COMPLETE_WITH(
"REPLICA",
"ALWAYS");
2336 else if (Matches(
"ALTER",
"EXTENSION", MatchAny))
2337 COMPLETE_WITH(
"ADD",
"DROP",
"UPDATE",
"SET SCHEMA");
2340 else if (Matches(
"ALTER",
"EXTENSION", MatchAny,
"ADD|DROP"))
2341 COMPLETE_WITH(
"ACCESS METHOD",
"AGGREGATE",
"CAST",
"COLLATION",
2342 "CONVERSION",
"DOMAIN",
"EVENT TRIGGER",
"FOREIGN",
2343 "FUNCTION",
"MATERIALIZED VIEW",
"OPERATOR",
2344 "LANGUAGE",
"PROCEDURE",
"ROUTINE",
"SCHEMA",
2345 "SEQUENCE",
"SERVER",
"TABLE",
"TEXT SEARCH",
2346 "TRANSFORM FOR",
"TYPE",
"VIEW");
2349 else if (Matches(
"ALTER",
"EXTENSION", MatchAny,
"ADD|DROP",
"FOREIGN"))
2350 COMPLETE_WITH(
"DATA WRAPPER",
"TABLE");
2353 else if (Matches(
"ALTER",
"EXTENSION", MatchAny,
"ADD|DROP",
"OPERATOR"))
2354 COMPLETE_WITH(
"CLASS",
"FAMILY");
2357 else if (Matches(
"ALTER",
"EXTENSION", MatchAny,
"ADD|DROP",
"TEXT",
"SEARCH"))
2358 COMPLETE_WITH(
"CONFIGURATION",
"DICTIONARY",
"PARSER",
"TEMPLATE");
2361 else if (Matches(
"ALTER",
"EXTENSION", MatchAny,
"UPDATE"))
2362 COMPLETE_WITH(
"TO");
2365 else if (Matches(
"ALTER",
"EXTENSION", MatchAny,
"UPDATE",
"TO"))
2367 set_completion_reference(prev3_wd);
2368 COMPLETE_WITH_QUERY(Query_for_list_of_available_extension_versions);
2372 else if (Matches(
"ALTER",
"FOREIGN"))
2373 COMPLETE_WITH(
"DATA WRAPPER",
"TABLE");
2376 else if (Matches(
"ALTER",
"FOREIGN",
"DATA",
"WRAPPER", MatchAny))
2377 COMPLETE_WITH(
"HANDLER",
"VALIDATOR",
"NO",
2378 "OPTIONS",
"OWNER TO",
"RENAME TO");
2379 else if (Matches(
"ALTER",
"FOREIGN",
"DATA",
"WRAPPER", MatchAny,
"NO"))
2380 COMPLETE_WITH(
"HANDLER",
"VALIDATOR");
2383 else if (Matches(
"ALTER",
"FOREIGN",
"TABLE", MatchAny))
2384 COMPLETE_WITH(
"ADD",
"ALTER",
"DISABLE TRIGGER",
"DROP",
"ENABLE",
2385 "INHERIT",
"NO INHERIT",
"OPTIONS",
"OWNER TO",
2386 "RENAME",
"SET",
"VALIDATE CONSTRAINT");
2389 else if (Matches(
"ALTER",
"INDEX"))
2390 COMPLETE_WITH_SCHEMA_QUERY_PLUS(Query_for_list_of_indexes,
2391 "ALL IN TABLESPACE");
2393 else if (Matches(
"ALTER",
"INDEX", MatchAny))
2394 COMPLETE_WITH(
"ALTER COLUMN",
"OWNER TO",
"RENAME TO",
"SET",
2395 "RESET",
"ATTACH PARTITION",
2396 "DEPENDS ON EXTENSION",
"NO DEPENDS ON EXTENSION");
2397 else if (Matches(
"ALTER",
"INDEX", MatchAny,
"ATTACH"))
2398 COMPLETE_WITH(
"PARTITION");
2399 else if (Matches(
"ALTER",
"INDEX", MatchAny,
"ATTACH",
"PARTITION"))
2400 COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_indexes);
2402 else if (Matches(
"ALTER",
"INDEX", MatchAny,
"ALTER"))
2403 COMPLETE_WITH(
"COLUMN");
2405 else if (Matches(
"ALTER",
"INDEX", MatchAny,
"ALTER",
"COLUMN"))
2407 set_completion_reference(prev3_wd);
2408 COMPLETE_WITH_SCHEMA_QUERY_VERBATIM(Query_for_list_of_attribute_numbers);
2411 else if (Matches(
"ALTER",
"INDEX", MatchAny,
"ALTER",
"COLUMN", MatchAny))
2412 COMPLETE_WITH(
"SET STATISTICS");
2414 else if (Matches(
"ALTER",
"INDEX", MatchAny,
"ALTER",
"COLUMN", MatchAny,
"SET"))
2415 COMPLETE_WITH(
"STATISTICS");
2417 else if (Matches(
"ALTER",
"INDEX", MatchAny,
"ALTER",
"COLUMN", MatchAny,
"SET",
"STATISTICS"))
2422 else if (Matches(
"ALTER",
"INDEX", MatchAny,
"SET"))
2423 COMPLETE_WITH(
"(",
"TABLESPACE");
2425 else if (Matches(
"ALTER",
"INDEX", MatchAny,
"RESET"))
2428 else if (Matches(
"ALTER",
"INDEX", MatchAny,
"RESET",
"("))
2429 COMPLETE_WITH(
"fillfactor",
2430 "deduplicate_items",
2431 "fastupdate",
"gin_pending_list_limit",
2433 "pages_per_range",
"autosummarize"
2435 else if (Matches(
"ALTER",
"INDEX", MatchAny,
"SET",
"("))
2436 COMPLETE_WITH(
"fillfactor =",
2437 "deduplicate_items =",
2438 "fastupdate =",
"gin_pending_list_limit =",
2440 "pages_per_range =",
"autosummarize ="
2442 else if (Matches(
"ALTER",
"INDEX", MatchAny,
"NO",
"DEPENDS"))
2443 COMPLETE_WITH(
"ON EXTENSION");
2444 else if (Matches(
"ALTER",
"INDEX", MatchAny,
"DEPENDS"))
2445 COMPLETE_WITH(
"ON EXTENSION");
2448 else if (Matches(
"ALTER",
"LANGUAGE", MatchAny))
2449 COMPLETE_WITH(
"OWNER TO",
"RENAME TO");
2452 else if (Matches(
"ALTER",
"LARGE",
"OBJECT", MatchAny))
2453 COMPLETE_WITH(
"OWNER TO");
2456 else if (Matches(
"ALTER",
"MATERIALIZED",
"VIEW"))
2457 COMPLETE_WITH_SCHEMA_QUERY_PLUS(Query_for_list_of_matviews,
2458 "ALL IN TABLESPACE");
2461 else if (Matches(
"ALTER",
"USER|ROLE", MatchAny) &&
2462 !TailMatches(
"USER",
"MAPPING"))
2463 COMPLETE_WITH(
"BYPASSRLS",
"CONNECTION LIMIT",
"CREATEDB",
"CREATEROLE",
2464 "ENCRYPTED PASSWORD",
"INHERIT",
"LOGIN",
"NOBYPASSRLS",
2465 "NOCREATEDB",
"NOCREATEROLE",
"NOINHERIT",
2466 "NOLOGIN",
"NOREPLICATION",
"NOSUPERUSER",
"PASSWORD",
2467 "RENAME TO",
"REPLICATION",
"RESET",
"SET",
"SUPERUSER",
2468 "VALID UNTIL",
"WITH");
2471 else if (Matches(
"ALTER",
"USER|ROLE", MatchAny,
"WITH"))
2473 COMPLETE_WITH(
"BYPASSRLS",
"CONNECTION LIMIT",
"CREATEDB",
"CREATEROLE",
2474 "ENCRYPTED PASSWORD",
"INHERIT",
"LOGIN",
"NOBYPASSRLS",
2475 "NOCREATEDB",
"NOCREATEROLE",
"NOINHERIT",
2476 "NOLOGIN",
"NOREPLICATION",
"NOSUPERUSER",
"PASSWORD",
2477 "RENAME TO",
"REPLICATION",
"RESET",
"SET",
"SUPERUSER",
2481 else if (Matches(
"ALTER",
"DEFAULT",
"PRIVILEGES"))
2482 COMPLETE_WITH(
"FOR",
"GRANT",
"IN SCHEMA",
"REVOKE");
2484 else if (Matches(
"ALTER",
"DEFAULT",
"PRIVILEGES",
"FOR"))
2485 COMPLETE_WITH(
"ROLE");
2487 else if (Matches(
"ALTER",
"DEFAULT",
"PRIVILEGES",
"IN"))
2488 COMPLETE_WITH(
"SCHEMA");
2490 else if (Matches(
"ALTER",
"DEFAULT",
"PRIVILEGES",
"FOR",
"ROLE|USER",
2492 COMPLETE_WITH(
"GRANT",
"REVOKE",
"IN SCHEMA");
2494 else if (Matches(
"ALTER",
"DEFAULT",
"PRIVILEGES",
"IN",
"SCHEMA",
2496 COMPLETE_WITH(
"GRANT",
"REVOKE",
"FOR ROLE");
2498 else if (Matches(
"ALTER",
"DEFAULT",
"PRIVILEGES",
"IN",
"SCHEMA",
2500 COMPLETE_WITH(
"ROLE");
2503 else if (Matches(
"ALTER",
"DEFAULT",
"PRIVILEGES",
"FOR",
"ROLE|USER",
2504 MatchAny,
"IN",
"SCHEMA", MatchAny) ||
2505 Matches(
"ALTER",
"DEFAULT",
"PRIVILEGES",
"IN",
"SCHEMA",
2506 MatchAny,
"FOR",
"ROLE|USER", MatchAny))
2507 COMPLETE_WITH(
"GRANT",
"REVOKE");
2509 else if (Matches(
"ALTER",
"DOMAIN", MatchAny))
2510 COMPLETE_WITH(
"ADD",
"DROP",
"OWNER TO",
"RENAME",
"SET",
2511 "VALIDATE CONSTRAINT");
2513 else if (Matches(
"ALTER",
"DOMAIN", MatchAny,
"DROP"))
2514 COMPLETE_WITH(
"CONSTRAINT",
"DEFAULT",
"NOT NULL");
2516 else if (Matches(
"ALTER",
"DOMAIN", MatchAny,
"DROP|RENAME|VALIDATE",
"CONSTRAINT"))
2518 set_completion_reference(prev3_wd);
2519 COMPLETE_WITH_SCHEMA_QUERY(Query_for_constraint_of_type);
2522 else if (Matches(
"ALTER",
"DOMAIN", MatchAny,
"RENAME"))
2523 COMPLETE_WITH(
"CONSTRAINT",
"TO");
2525 else if (Matches(
"ALTER",
"DOMAIN", MatchAny,
"RENAME",
"CONSTRAINT", MatchAny))
2526 COMPLETE_WITH(
"TO");
2529 else if (Matches(
"ALTER",
"DOMAIN", MatchAny,
"SET"))
2530 COMPLETE_WITH(
"DEFAULT",
"NOT NULL",
"SCHEMA");
2532 else if (Matches(
"ALTER",
"SEQUENCE", MatchAny))
2533 COMPLETE_WITH(
"AS",
"INCREMENT",
"MINVALUE",
"MAXVALUE",
"RESTART",
2534 "START",
"NO",
"CACHE",
"CYCLE",
"SET",
"OWNED BY",
2535 "OWNER TO",
"RENAME TO");
2537 else if (TailMatches(
"ALTER",
"SEQUENCE", MatchAny,
"AS"))
2538 COMPLETE_WITH_CS(
"smallint",
"integer",
"bigint");
2540 else if (Matches(
"ALTER",
"SEQUENCE", MatchAny,
"NO"))
2541 COMPLETE_WITH(
"MINVALUE",
"MAXVALUE",
"CYCLE");
2543 else if (Matches(
"ALTER",
"SEQUENCE", MatchAny,
"SET"))
2544 COMPLETE_WITH(
"SCHEMA",
"LOGGED",
"UNLOGGED");
2546 else if (Matches(
"ALTER",
"SERVER", MatchAny))
2547 COMPLETE_WITH(
"VERSION",
"OPTIONS",
"OWNER TO",
"RENAME TO");
2549 else if (Matches(
"ALTER",
"SERVER", MatchAny,
"VERSION", MatchAny))
2550 COMPLETE_WITH(
"OPTIONS");
2552 else if (Matches(
"ALTER",
"SYSTEM"))
2553 COMPLETE_WITH(
"SET",
"RESET");
2554 else if (Matches(
"ALTER",
"SYSTEM",
"SET|RESET"))
2555 COMPLETE_WITH_QUERY_VERBATIM_PLUS(Query_for_list_of_alter_system_set_vars,
2557 else if (Matches(
"ALTER",
"SYSTEM",
"SET", MatchAny))
2558 COMPLETE_WITH(
"TO");
2560 else if (Matches(
"ALTER",
"VIEW", MatchAny))
2561 COMPLETE_WITH(
"ALTER COLUMN",
"OWNER TO",
"RENAME",
"RESET",
"SET");
2563 else if (Matches(
"ALTER",
"VIEW", MatchAny,
"RENAME"))
2564 COMPLETE_WITH_ATTR_PLUS(prev2_wd,
"COLUMN",
"TO");
2565 else if (Matches(
"ALTER",
"VIEW", MatchAny,
"ALTER|RENAME",
"COLUMN"))
2566 COMPLETE_WITH_ATTR(prev3_wd);
2568 else if (Matches(
"ALTER",
"VIEW", MatchAny,
"ALTER", MatchAny) ||
2569 Matches(
"ALTER",
"VIEW", MatchAny,
"ALTER",
"COLUMN", MatchAny))
2570 COMPLETE_WITH(
"SET DEFAULT",
"DROP DEFAULT");
2572 else if (Matches(
"ALTER",
"VIEW", MatchAny,
"RENAME", MatchAnyExcept(
"TO")))
2573 COMPLETE_WITH(
"TO");
2575 else if (Matches(
"ALTER",
"VIEW", MatchAny,
"RENAME",
"COLUMN", MatchAnyExcept(
"TO")))
2576 COMPLETE_WITH(
"TO");
2578 else if (Matches(
"ALTER",
"VIEW", MatchAny,
"RESET"))
2581 else if (Matches(
"ALTER",
"VIEW", MatchAny,
"SET"))
2582 COMPLETE_WITH(
"(",
"SCHEMA");
2584 else if (Matches(
"ALTER",
"VIEW", MatchAny,
"SET|RESET",
"("))
2585 COMPLETE_WITH_LIST(view_optional_parameters);
2586 else if (Matches(
"ALTER",
"VIEW", MatchAny,
"SET",
"(", MatchAny))
2588 else if (Matches(
"ALTER",
"VIEW", MatchAny,
"SET",
"(",
"check_option",
"="))
2589 COMPLETE_WITH(
"local",
"cascaded");
2590 else if (Matches(
"ALTER",
"VIEW", MatchAny,
"SET",
"(",
"security_barrier|security_invoker",
"="))
2591 COMPLETE_WITH(
"true",
"false");
2594 else if (Matches(
"ALTER",
"MATERIALIZED",
"VIEW", MatchAny))
2595 COMPLETE_WITH(
"ALTER COLUMN",
"CLUSTER ON",
"DEPENDS ON EXTENSION",
2596 "NO DEPENDS ON EXTENSION",
"OWNER TO",
"RENAME",
2599 else if (Matches(
"ALTER",
"MATERIALIZED",
"VIEW", MatchAny,
"RENAME"))
2600 COMPLETE_WITH_ATTR_PLUS(prev2_wd,
"COLUMN",
"TO");
2601 else if (Matches(
"ALTER",
"MATERIALIZED",
"VIEW", MatchAny,
"ALTER|RENAME",
"COLUMN"))
2602 COMPLETE_WITH_ATTR(prev3_wd);
2604 else if (Matches(
"ALTER",
"MATERIALIZED",
"VIEW", MatchAny,
"RENAME", MatchAnyExcept(
"TO")))
2605 COMPLETE_WITH(
"TO");
2607 else if (Matches(
"ALTER",
"MATERIALIZED",
"VIEW", MatchAny,
"RENAME",
"COLUMN", MatchAnyExcept(
"TO")))
2608 COMPLETE_WITH(
"TO");
2610 else if (Matches(
"ALTER",
"MATERIALIZED",
"VIEW", MatchAny,
"SET"))
2611 COMPLETE_WITH(
"(",
"ACCESS METHOD",
"SCHEMA",
"TABLESPACE",
"WITHOUT CLUSTER");
2613 else if (Matches(
"ALTER",
"MATERIALIZED",
"VIEW", MatchAny,
"SET",
"ACCESS",
"METHOD"))
2614 COMPLETE_WITH_QUERY(Query_for_list_of_table_access_methods);
2617 else if (Matches(
"ALTER",
"POLICY"))
2618 COMPLETE_WITH_QUERY(Query_for_list_of_policies);
2620 else if (Matches(
"ALTER",
"POLICY", MatchAny))
2621 COMPLETE_WITH(
"ON");
2623 else if (Matches(
"ALTER",
"POLICY", MatchAny,
"ON"))
2625 set_completion_reference(prev2_wd);
2626 COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_tables_for_policy);
2629 else if (Matches(
"ALTER",
"POLICY", MatchAny,
"ON", MatchAny))
2630 COMPLETE_WITH(
"RENAME TO",
"TO",
"USING (",
"WITH CHECK (");
2632 else if (Matches(
"ALTER",
"POLICY", MatchAny,
"ON", MatchAny,
"TO"))
2633 COMPLETE_WITH_QUERY_PLUS(Query_for_list_of_roles,
2634 Keywords_for_list_of_grant_roles);
2636 else if (Matches(
"ALTER",
"POLICY", MatchAny,
"ON", MatchAny,
"USING"))
2639 else if (Matches(
"ALTER",
"POLICY", MatchAny,
"ON", MatchAny,
"WITH",
"CHECK"))
2643 else if (Matches(
"ALTER",
"RULE", MatchAny))
2644 COMPLETE_WITH(
"ON");
2647 else if (Matches(
"ALTER",
"RULE", MatchAny,
"ON"))
2649 set_completion_reference(prev2_wd);
2650 COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_tables_for_rule);
2654 else if (Matches(
"ALTER",
"RULE", MatchAny,
"ON", MatchAny))
2655 COMPLETE_WITH(
"RENAME TO");
2658 else if (Matches(
"ALTER",
"STATISTICS", MatchAny))
2659 COMPLETE_WITH(
"OWNER TO",
"RENAME TO",
"SET SCHEMA",
"SET STATISTICS");
2661 else if (Matches(
"ALTER",
"STATISTICS", MatchAny,
"SET"))
2662 COMPLETE_WITH(
"SCHEMA",
"STATISTICS");
2665 else if (Matches(
"ALTER",
"TRIGGER", MatchAny))
2666 COMPLETE_WITH(
"ON");
2668 else if (Matches(
"ALTER",
"TRIGGER", MatchAny,
"ON"))
2670 set_completion_reference(prev2_wd);
2671 COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_tables_for_trigger);
2675 else if (Matches(
"ALTER",
"TRIGGER", MatchAny,
"ON", MatchAny))
2676 COMPLETE_WITH(
"RENAME TO",
"DEPENDS ON EXTENSION",
2677 "NO DEPENDS ON EXTENSION");
2682 else if (Matches(
"ALTER",
"TABLE", MatchAny))
2683 COMPLETE_WITH(
"ADD",
"ALTER",
"CLUSTER ON",
"DISABLE",
"DROP",
2684 "ENABLE",
"INHERIT",
"NO",
"RENAME",
"RESET",
2685 "OWNER TO",
"SET",
"VALIDATE CONSTRAINT",
2686 "REPLICA IDENTITY",
"ATTACH PARTITION",
2687 "DETACH PARTITION",
"FORCE ROW LEVEL SECURITY",
2690 else if (Matches(
"ALTER",
"TABLE", MatchAny,
"ADD"))
2693 COMPLETE_WITH(
"COLUMN",
"CONSTRAINT",
"CHECK",
"UNIQUE",
"PRIMARY KEY",
2694 "EXCLUDE",
"FOREIGN KEY");
2697 else if (Matches(
"ALTER",
"TABLE", MatchAny,
"ADD",
"COLUMN", MatchAny) ||
2698 Matches(
"ALTER",
"TABLE", MatchAny,
"ADD", MatchAnyExcept(
"COLUMN|CONSTRAINT|CHECK|UNIQUE|PRIMARY|EXCLUDE|FOREIGN")))
2699 COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_datatypes);
2701 else if (Matches(
"ALTER",
"TABLE", MatchAny,
"ADD",
"CONSTRAINT", MatchAny))
2702 COMPLETE_WITH(
"CHECK",
"UNIQUE",
"PRIMARY KEY",
"EXCLUDE",
"FOREIGN KEY");
2704 else if (Matches(
"ALTER",
"TABLE", MatchAny,
"ADD",
"PRIMARY",
"KEY") ||
2705 Matches(
"ALTER",
"TABLE", MatchAny,
"ADD",
"UNIQUE") ||
2706 Matches(
"ALTER",
"TABLE", MatchAny,
"ADD",
"CONSTRAINT", MatchAny,
"PRIMARY",
"KEY") ||
2707 Matches(
"ALTER",
"TABLE", MatchAny,
"ADD",
"CONSTRAINT", MatchAny,
"UNIQUE"))
2708 COMPLETE_WITH(
"(",
"USING INDEX");
2710 else if (Matches(
"ALTER",
"TABLE", MatchAny,
"ADD",
"PRIMARY",
"KEY",
"USING",
"INDEX"))
2712 set_completion_reference(prev6_wd);
2713 COMPLETE_WITH_SCHEMA_QUERY(Query_for_unique_index_of_table);
2716 else if (Matches(
"ALTER",
"TABLE", MatchAny,
"ADD",
"UNIQUE",
"USING",
"INDEX"))
2718 set_completion_reference(prev5_wd);
2719 COMPLETE_WITH_SCHEMA_QUERY(Query_for_unique_index_of_table);
2722 else if (Matches(
"ALTER",
"TABLE", MatchAny,
"ADD",
"CONSTRAINT", MatchAny,
2723 "PRIMARY",
"KEY",
"USING",
"INDEX"))
2725 set_completion_reference(prev8_wd);
2726 COMPLETE_WITH_SCHEMA_QUERY(Query_for_unique_index_of_table);
2729 else if (Matches(
"ALTER",
"TABLE", MatchAny,
"ADD",
"CONSTRAINT", MatchAny,
2730 "UNIQUE",
"USING",
"INDEX"))
2732 set_completion_reference(prev7_wd);
2733 COMPLETE_WITH_SCHEMA_QUERY(Query_for_unique_index_of_table);
2736 else if (Matches(
"ALTER",
"TABLE", MatchAny,
"ENABLE"))
2737 COMPLETE_WITH(
"ALWAYS",
"REPLICA",
"ROW LEVEL SECURITY",
"RULE",
2739 else if (Matches(
"ALTER",
"TABLE", MatchAny,
"ENABLE",
"REPLICA|ALWAYS"))
2740 COMPLETE_WITH(
"RULE",
"TRIGGER");
2741 else if (Matches(
"ALTER",
"TABLE", MatchAny,
"ENABLE",
"RULE"))
2743 set_completion_reference(prev3_wd);
2744 COMPLETE_WITH_SCHEMA_QUERY(Query_for_rule_of_table);
2746 else if (Matches(
"ALTER",
"TABLE", MatchAny,
"ENABLE", MatchAny,
"RULE"))
2748 set_completion_reference(prev4_wd);
2749 COMPLETE_WITH_SCHEMA_QUERY(Query_for_rule_of_table);
2751 else if (Matches(
"ALTER",
"TABLE", MatchAny,
"ENABLE",
"TRIGGER"))
2753 set_completion_reference(prev3_wd);
2754 COMPLETE_WITH_SCHEMA_QUERY(Query_for_trigger_of_table);
2756 else if (Matches(
"ALTER",
"TABLE", MatchAny,
"ENABLE", MatchAny,
"TRIGGER"))
2758 set_completion_reference(prev4_wd);
2759 COMPLETE_WITH_SCHEMA_QUERY(Query_for_trigger_of_table);
2762 else if (Matches(
"ALTER",
"TABLE", MatchAny,
"INHERIT"))
2763 COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_tables);
2765 else if (Matches(
"ALTER",
"TABLE", MatchAny,
"NO"))
2766 COMPLETE_WITH(
"FORCE ROW LEVEL SECURITY",
"INHERIT");
2768 else if (Matches(
"ALTER",
"TABLE", MatchAny,
"NO",
"INHERIT"))
2769 COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_tables);
2771 else if (Matches(
"ALTER",
"TABLE", MatchAny,
"DISABLE"))
2772 COMPLETE_WITH(
"ROW LEVEL SECURITY",
"RULE",
"TRIGGER");
2773 else if (Matches(
"ALTER",
"TABLE", MatchAny,
"DISABLE",
"RULE"))
2775 set_completion_reference(prev3_wd);
2776 COMPLETE_WITH_SCHEMA_QUERY(Query_for_rule_of_table);
2778 else if (Matches(
"ALTER",
"TABLE", MatchAny,
"DISABLE",
"TRIGGER"))
2780 set_completion_reference(prev3_wd);
2781 COMPLETE_WITH_SCHEMA_QUERY(Query_for_trigger_of_table);
2785 else if (Matches(
"ALTER",
"TABLE", MatchAny,
"ALTER"))
2786 COMPLETE_WITH_ATTR_PLUS(prev2_wd,
"COLUMN",
"CONSTRAINT");
2789 else if (Matches(
"ALTER",
"TABLE", MatchAny,
"RENAME"))
2790 COMPLETE_WITH_ATTR_PLUS(prev2_wd,
"COLUMN",
"CONSTRAINT",
"TO");
2791 else if (Matches(
"ALTER",
"TABLE", MatchAny,
"ALTER|RENAME",
"COLUMN"))
2792 COMPLETE_WITH_ATTR(prev3_wd);
2795 else if (Matches(
"ALTER",
"TABLE", MatchAny,
"RENAME", MatchAnyExcept(
"CONSTRAINT|TO")))
2796 COMPLETE_WITH(
"TO");
2799 else if (Matches(
"ALTER",
"TABLE", MatchAny,
"RENAME",
"COLUMN|CONSTRAINT", MatchAnyExcept(
"TO")))
2800 COMPLETE_WITH(
"TO");
2803 else if (Matches(
"ALTER",
"TABLE", MatchAny,
"DROP"))
2804 COMPLETE_WITH(
"COLUMN",
"CONSTRAINT");
2806 else if (Matches(
"ALTER",
"TABLE", MatchAny,
"DROP",
"COLUMN"))
2807 COMPLETE_WITH_ATTR(prev3_wd);
2809 else if (Matches(
"ALTER",
"TABLE", MatchAny,
"ALTER|DROP|RENAME",
"CONSTRAINT"))
2811 set_completion_reference(prev3_wd);
2812 COMPLETE_WITH_SCHEMA_QUERY(Query_for_constraint_of_table);
2815 else if (Matches(
"ALTER",
"TABLE", MatchAny,
"VALIDATE",
"CONSTRAINT"))
2817 set_completion_reference(prev3_wd);
2818 COMPLETE_WITH_SCHEMA_QUERY(Query_for_constraint_of_table_not_validated);
2821 else if (Matches(
"ALTER",
"TABLE", MatchAny,
"ALTER",
"COLUMN", MatchAny) ||
2822 Matches(
"ALTER",
"TABLE", MatchAny,
"ALTER", MatchAny))
2823 COMPLETE_WITH(
"TYPE",
"SET",
"RESET",
"RESTART",
"ADD",
"DROP");
2825 else if (Matches(
"ALTER",
"TABLE", MatchAny,
"ALTER",
"COLUMN", MatchAny,
"ADD") ||
2826 Matches(
"ALTER",
"TABLE", MatchAny,
"ALTER", MatchAny,
"ADD"))
2827 COMPLETE_WITH(
"GENERATED");
2829 else if (Matches(
"ALTER",
"TABLE", MatchAny,
"ALTER",
"COLUMN", MatchAny,
"ADD",
"GENERATED") ||
2830 Matches(
"ALTER",
"TABLE", MatchAny,
"ALTER", MatchAny,
"ADD",
"GENERATED"))
2831 COMPLETE_WITH(
"ALWAYS",
"BY DEFAULT");
2833 else if (Matches(
"ALTER",
"TABLE", MatchAny,
"ALTER",
"COLUMN", MatchAny,
"ADD",
"GENERATED",
"ALWAYS") ||
2834 Matches(
"ALTER",
"TABLE", MatchAny,
"ALTER", MatchAny,
"ADD",
"GENERATED",
"ALWAYS") ||
2835 Matches(
"ALTER",
"TABLE", MatchAny,
"ALTER",
"COLUMN", MatchAny,
"ADD",
"GENERATED",
"BY",
"DEFAULT") ||
2836 Matches(
"ALTER",
"TABLE", MatchAny,
"ALTER", MatchAny,
"ADD",
"GENERATED",
"BY",
"DEFAULT"))
2837 COMPLETE_WITH(
"AS IDENTITY");
2839 else if (Matches(
"ALTER",
"TABLE", MatchAny,
"ALTER",
"COLUMN", MatchAny,
"SET") ||
2840 Matches(
"ALTER",
"TABLE", MatchAny,
"ALTER", MatchAny,
"SET"))
2841 COMPLETE_WITH(
"(",
"COMPRESSION",
"DATA TYPE",
"DEFAULT",
"EXPRESSION",
"GENERATED",
"NOT NULL",
2842 "STATISTICS",
"STORAGE",
2844 "INCREMENT",
"MINVALUE",
"MAXVALUE",
"START",
"NO",
"CACHE",
"CYCLE");
2846 else if (Matches(
"ALTER",
"TABLE", MatchAny,
"ALTER",
"COLUMN", MatchAny,
"SET",
"(") ||
2847 Matches(
"ALTER",
"TABLE", MatchAny,
"ALTER", MatchAny,
"SET",
"("))
2848 COMPLETE_WITH(
"n_distinct",
"n_distinct_inherited");
2850 else if (Matches(
"ALTER",
"TABLE", MatchAny,
"ALTER",
"COLUMN", MatchAny,
"SET",
"COMPRESSION") ||
2851 Matches(
"ALTER",
"TABLE", MatchAny,
"ALTER", MatchAny,
"SET",
"COMPRESSION"))
2852 COMPLETE_WITH(
"DEFAULT",
"PGLZ",
"LZ4");
2854 else if (Matches(
"ALTER",
"TABLE", MatchAny,
"ALTER",
"COLUMN", MatchAny,
"SET",
"EXPRESSION") ||
2855 Matches(
"ALTER",
"TABLE", MatchAny,
"ALTER", MatchAny,
"SET",
"EXPRESSION"))
2856 COMPLETE_WITH(
"AS");
2858 else if (Matches(
"ALTER",
"TABLE", MatchAny,
"ALTER",
"COLUMN", MatchAny,
"SET",
"EXPRESSION",
"AS") ||
2859 Matches(
"ALTER",
"TABLE", MatchAny,
"ALTER", MatchAny,
"SET",
"EXPRESSION",
"AS"))
2862 else if (Matches(
"ALTER",
"TABLE", MatchAny,
"ALTER",
"COLUMN", MatchAny,
"SET",
"GENERATED") ||
2863 Matches(
"ALTER",
"TABLE", MatchAny,
"ALTER", MatchAny,
"SET",
"GENERATED"))
2864 COMPLETE_WITH(
"ALWAYS",
"BY DEFAULT");
2866 else if (Matches(
"ALTER",
"TABLE", MatchAny,
"ALTER",
"COLUMN", MatchAny,
"SET",
"NO") ||
2867 Matches(
"ALTER",
"TABLE", MatchAny,
"ALTER", MatchAny,
"SET",
"NO"))
2868 COMPLETE_WITH(
"MINVALUE",
"MAXVALUE",
"CYCLE");
2870 else if (Matches(
"ALTER",
"TABLE", MatchAny,
"ALTER",
"COLUMN", MatchAny,
"SET",
"STORAGE") ||
2871 Matches(
"ALTER",
"TABLE", MatchAny,
"ALTER", MatchAny,
"SET",
"STORAGE"))
2872 COMPLETE_WITH(
"DEFAULT",
"PLAIN",
"EXTERNAL",
"EXTENDED",
"MAIN");
2874 else if (Matches(
"ALTER",
"TABLE", MatchAny,
"ALTER",
"COLUMN", MatchAny,
"SET",
"STATISTICS") ||
2875 Matches(
"ALTER",
"TABLE", MatchAny,
"ALTER", MatchAny,
"SET",
"STATISTICS"))
2880 else if (Matches(
"ALTER",
"TABLE", MatchAny,
"ALTER",
"COLUMN", MatchAny,
"DROP") ||
2881 Matches(
"ALTER",
"TABLE", MatchAny,
"ALTER", MatchAny,
"DROP"))
2882 COMPLETE_WITH(
"DEFAULT",
"EXPRESSION",
"IDENTITY",
"NOT NULL");
2883 else if (Matches(
"ALTER",
"TABLE", MatchAny,
"CLUSTER"))
2884 COMPLETE_WITH(
"ON");
2885 else if (Matches(
"ALTER",
"TABLE", MatchAny,
"CLUSTER",
"ON"))
2887 set_completion_reference(prev3_wd);
2888 COMPLETE_WITH_SCHEMA_QUERY(Query_for_index_of_table);
2891 else if (Matches(
"ALTER",
"TABLE", MatchAny,
"SET"))
2892 COMPLETE_WITH(
"(",
"ACCESS METHOD",
"LOGGED",
"SCHEMA",
2893 "TABLESPACE",
"UNLOGGED",
"WITH",
"WITHOUT");
2899 else if (Matches(
"ALTER",
"TABLE", MatchAny,
"SET",
"ACCESS",
"METHOD"))
2900 COMPLETE_WITH_QUERY_PLUS(Query_for_list_of_table_access_methods,
2907 else if (Matches(
"ALTER",
"TABLE", MatchAny,
"SET",
"TABLESPACE"))
2908 COMPLETE_WITH_QUERY(Query_for_list_of_tablespaces);
2910 else if (Matches(
"ALTER",
"TABLE", MatchAny,
"SET",
"WITHOUT"))
2911 COMPLETE_WITH(
"CLUSTER",
"OIDS");
2913 else if (Matches(
"ALTER",
"TABLE", MatchAny,
"RESET"))
2916 else if (Matches(
"ALTER",
"TABLE", MatchAny,
"SET|RESET",
"("))
2917 COMPLETE_WITH_LIST(table_storage_parameters);
2918 else if (Matches(
"ALTER",
"TABLE", MatchAny,
"REPLICA",
"IDENTITY",
"USING",
"INDEX"))
2920 set_completion_reference(prev5_wd);
2921 COMPLETE_WITH_SCHEMA_QUERY(Query_for_index_of_table);
2923 else if (Matches(
"ALTER",
"TABLE", MatchAny,
"REPLICA",
"IDENTITY",
"USING"))
2924 COMPLETE_WITH(
"INDEX");
2925 else if (Matches(
"ALTER",
"TABLE", MatchAny,
"REPLICA",
"IDENTITY"))
2926 COMPLETE_WITH(
"FULL",
"NOTHING",
"DEFAULT",
"USING");
2927 else if (Matches(
"ALTER",
"TABLE", MatchAny,
"REPLICA"))
2928 COMPLETE_WITH(
"IDENTITY");
2934 else if (Matches(
"ALTER",
"TABLE", MatchAny,
"ATTACH",
"PARTITION"))
2935 COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_tables);
2937 else if (TailMatches(
"ATTACH",
"PARTITION", MatchAny))
2938 COMPLETE_WITH(
"FOR VALUES",
"DEFAULT");
2939 else if (TailMatches(
"FOR",
"VALUES"))
2940 COMPLETE_WITH(
"FROM (",
"IN (",
"WITH (");
2946 else if (Matches(
"ALTER",
"TABLE", MatchAny,
"DETACH",
"PARTITION"))
2948 set_completion_reference(prev3_wd);
2949 COMPLETE_WITH_SCHEMA_QUERY(Query_for_partition_of_table);
2951 else if (Matches(
"ALTER",
"TABLE", MatchAny,
"DETACH",
"PARTITION", MatchAny))
2952 COMPLETE_WITH(
"CONCURRENTLY",
"FINALIZE");
2955 else if (Matches(
"ALTER",
"TABLE", MatchAny,
"OF"))
2956 COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_composite_datatypes);
2959 else if (Matches(
"ALTER",
"TABLESPACE", MatchAny))
2960 COMPLETE_WITH(
"RENAME TO",
"OWNER TO",
"SET",
"RESET");
2962 else if (Matches(
"ALTER",
"TABLESPACE", MatchAny,
"SET|RESET"))
2965 else if (Matches(
"ALTER",
"TABLESPACE", MatchAny,
"SET|RESET",
"("))
2966 COMPLETE_WITH(
"seq_page_cost",
"random_page_cost",
2967 "effective_io_concurrency",
"maintenance_io_concurrency");
2970 else if (Matches(
"ALTER",
"TEXT",
"SEARCH"))
2971 COMPLETE_WITH(
"CONFIGURATION",
"DICTIONARY",
"PARSER",
"TEMPLATE");
2972 else if (Matches(
"ALTER",
"TEXT",
"SEARCH",
"TEMPLATE|PARSER", MatchAny))
2973 COMPLETE_WITH(
"RENAME TO",
"SET SCHEMA");
2974 else if (Matches(
"ALTER",
"TEXT",
"SEARCH",
"DICTIONARY", MatchAny))
2975 COMPLETE_WITH(
"(",
"OWNER TO",
"RENAME TO",
"SET SCHEMA");
2976 else if (Matches(
"ALTER",
"TEXT",
"SEARCH",
"CONFIGURATION", MatchAny))
2977 COMPLETE_WITH(
"ADD MAPPING FOR",
"ALTER MAPPING",
2979 "OWNER TO",
"RENAME TO",
"SET SCHEMA");
2982 else if (Matches(
"ALTER",
"TYPE", MatchAny))
2983 COMPLETE_WITH(
"ADD ATTRIBUTE",
"ADD VALUE",
"ALTER ATTRIBUTE",
2985 "OWNER TO",
"RENAME",
"SET SCHEMA",
"SET (");
2987 else if (Matches(
"ALTER",
"TYPE", MatchAny,
"ADD"))
2988 COMPLETE_WITH(
"ATTRIBUTE",
"VALUE");
2990 else if (Matches(
"ALTER",
"TYPE", MatchAny,
"RENAME"))
2991 COMPLETE_WITH(
"ATTRIBUTE",
"TO",
"VALUE");
2993 else if (Matches(
"ALTER",
"TYPE", MatchAny,
"RENAME",
"ATTRIBUTE|VALUE", MatchAny))
2994 COMPLETE_WITH(
"TO");
3000 else if (Matches(
"ALTER",
"TYPE", MatchAny,
"ALTER|DROP|RENAME",
"ATTRIBUTE"))
3001 COMPLETE_WITH_ATTR(prev3_wd);
3003 else if (Matches(
"ALTER",
"TYPE", MatchAny,
"ALTER",
"ATTRIBUTE", MatchAny))
3004 COMPLETE_WITH(
"TYPE");
3006 else if (Matches(
"ALTER",
"TYPE", MatchAny,
"RENAME",
"VALUE"))
3007 COMPLETE_WITH_ENUM_VALUE(prev3_wd);
3009 else if (Matches(
"ALTER",
"TYPE", MatchAny,
"SET"))
3010 COMPLETE_WITH(
"(",
"SCHEMA");
3012 else if (Matches(
"ALTER",
"TYPE", MatchAny,
"SET",
"("))
3013 COMPLETE_WITH(
"ANALYZE",
"RECEIVE",
"SEND",
"STORAGE",
"SUBSCRIPT",
3014 "TYPMOD_IN",
"TYPMOD_OUT");
3017 else if (Matches(
"ALTER",
"GROUP", MatchAny))
3018 COMPLETE_WITH(
"ADD USER",
"DROP USER",
"RENAME TO");
3020 else if (Matches(
"ALTER",
"GROUP", MatchAny,
"ADD|DROP"))
3021 COMPLETE_WITH(
"USER");
3023 else if (Matches(
"ALTER",
"GROUP", MatchAny,
"ADD|DROP",
"USER"))
3024 COMPLETE_WITH_QUERY(Query_for_list_of_roles);
3030 else if (Matches(
"ANALYZE"))
3031 COMPLETE_WITH_SCHEMA_QUERY_PLUS(Query_for_list_of_analyzables,
3033 else if (HeadMatches(
"ANALYZE",
"(*") &&
3034 !HeadMatches(
"ANALYZE",
"(*)"))
3041 if (ends_with(prev_wd,
'(') || ends_with(prev_wd,
','))
3042 COMPLETE_WITH(
"VERBOSE",
"SKIP_LOCKED",
"BUFFER_USAGE_LIMIT");
3043 else if (TailMatches(
"VERBOSE|SKIP_LOCKED"))
3044 COMPLETE_WITH(
"ON",
"OFF");
3046 else if (Matches(
"ANALYZE", MatchAnyN,
"("))
3048 COMPLETE_WITH_ATTR(prev2_wd);
3049 else if (HeadMatches(
"ANALYZE"))
3050 COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_analyzables);
3053 else if (Matches(
"BEGIN"))
3054 COMPLETE_WITH(
"WORK",
"TRANSACTION",
"ISOLATION LEVEL",
"READ",
"DEFERRABLE",
"NOT DEFERRABLE");
3056 else if (Matches(
"END|ABORT"))
3057 COMPLETE_WITH(
"AND",
"WORK",
"TRANSACTION");
3059 else if (Matches(
"COMMIT"))
3060 COMPLETE_WITH(
"AND",
"WORK",
"TRANSACTION",
"PREPARED");
3062 else if (Matches(
"RELEASE"))
3063 COMPLETE_WITH(
"SAVEPOINT");
3065 else if (Matches(
"ROLLBACK"))
3066 COMPLETE_WITH(
"AND",
"WORK",
"TRANSACTION",
"TO SAVEPOINT",
"PREPARED");
3067 else if (Matches(
"ABORT|END|COMMIT|ROLLBACK",
"AND"))
3068 COMPLETE_WITH(
"CHAIN");
3070 else if (Matches(
"CALL"))
3071 COMPLETE_WITH_VERSIONED_SCHEMA_QUERY(Query_for_list_of_procedures);
3072 else if (Matches(
"CALL", MatchAny))
3075 else if (Matches(
"CLOSE"))
3076 COMPLETE_WITH_QUERY_PLUS(Query_for_list_of_cursors,
3079 else if (Matches(
"CLUSTER"))
3080 COMPLETE_WITH_SCHEMA_QUERY_PLUS(Query_for_list_of_clusterables,
3082 else if (Matches(
"CLUSTER",
"VERBOSE") ||
3083 Matches(
"CLUSTER",
"(*)"))
3084 COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_clusterables);
3086 else if (Matches(
"CLUSTER", MatchAnyExcept(
"VERBOSE|ON|(|(*)")))
3087 COMPLETE_WITH(
"USING");
3089 else if (Matches(
"CLUSTER",
"VERBOSE|(*)", MatchAny))
3090 COMPLETE_WITH(
"USING");
3092 else if (Matches(
"CLUSTER", MatchAny,
"USING") ||
3093 Matches(
"CLUSTER",
"VERBOSE|(*)", MatchAny,
"USING"))
3095 set_completion_reference(prev2_wd);
3096 COMPLETE_WITH_SCHEMA_QUERY(Query_for_index_of_table);
3098 else if (HeadMatches(
"CLUSTER",
"(*") &&
3099 !HeadMatches(
"CLUSTER",
"(*)"))
3106 if (ends_with(prev_wd,
'(') || ends_with(prev_wd,
','))
3107 COMPLETE_WITH(
"VERBOSE");
3111 else if (Matches(
"COMMENT"))
3112 COMPLETE_WITH(
"ON");
3113 else if (Matches(
"COMMENT",
"ON"))
3114 COMPLETE_WITH(
"ACCESS METHOD",
"AGGREGATE",
"CAST",
"COLLATION",
3115 "COLUMN",
"CONSTRAINT",
"CONVERSION",
"DATABASE",
3116 "DOMAIN",
"EXTENSION",
"EVENT TRIGGER",
3117 "FOREIGN DATA WRAPPER",
"FOREIGN TABLE",
3118 "FUNCTION",
"INDEX",
"LANGUAGE",
"LARGE OBJECT",
3119 "MATERIALIZED VIEW",
"OPERATOR",
"POLICY",
3120 "PROCEDURE",
"PROCEDURAL LANGUAGE",
"PUBLICATION",
"ROLE",
3121 "ROUTINE",
"RULE",
"SCHEMA",
"SEQUENCE",
"SERVER",
3122 "STATISTICS",
"SUBSCRIPTION",
"TABLE",
3123 "TABLESPACE",
"TEXT SEARCH",
"TRANSFORM FOR",
3124 "TRIGGER",
"TYPE",
"VIEW");
3125 else if (Matches(
"COMMENT",
"ON",
"ACCESS",
"METHOD"))
3126 COMPLETE_WITH_QUERY(Query_for_list_of_access_methods);
3127 else if (Matches(
"COMMENT",
"ON",
"CONSTRAINT"))
3128 COMPLETE_WITH_QUERY(Query_for_all_table_constraints);
3129 else if (Matches(
"COMMENT",
"ON",
"CONSTRAINT", MatchAny))
3130 COMPLETE_WITH(
"ON");
3131 else if (Matches(
"COMMENT",
"ON",
"CONSTRAINT", MatchAny,
"ON"))
3133 set_completion_reference(prev2_wd);
3134 COMPLETE_WITH_SCHEMA_QUERY_PLUS(Query_for_list_of_tables_for_constraint,
3137 else if (Matches(
"COMMENT",
"ON",
"CONSTRAINT", MatchAny,
"ON",
"DOMAIN"))
3138 COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_domains);
3139 else if (Matches(
"COMMENT",
"ON",
"EVENT",
"TRIGGER"))
3140 COMPLETE_WITH_QUERY(Query_for_list_of_event_triggers);
3141 else if (Matches(
"COMMENT",
"ON",
"FOREIGN"))
3142 COMPLETE_WITH(
"DATA WRAPPER",
"TABLE");
3143 else if (Matches(
"COMMENT",
"ON",
"FOREIGN",
"TABLE"))
3144 COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_foreign_tables);
3145 else if (Matches(
"COMMENT",
"ON",
"MATERIALIZED",
"VIEW"))
3146 COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_matviews);
3147 else if (Matches(
"COMMENT",
"ON",
"POLICY"))
3148 COMPLETE_WITH_QUERY(Query_for_list_of_policies);
3149 else if (Matches(
"COMMENT",
"ON",
"POLICY", MatchAny))
3150 COMPLETE_WITH(
"ON");
3151 else if (Matches(
"COMMENT",
"ON",
"POLICY", MatchAny,
"ON"))
3153 set_completion_reference(prev2_wd);
3154 COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_tables_for_policy);
3156 else if (Matches(
"COMMENT",
"ON",
"PROCEDURAL",
"LANGUAGE"))
3157 COMPLETE_WITH_QUERY(Query_for_list_of_languages);
3158 else if (Matches(
"COMMENT",
"ON",
"RULE", MatchAny))
3159 COMPLETE_WITH(
"ON");
3160 else if (Matches(
"COMMENT",
"ON",
"RULE", MatchAny,
"ON"))
3162 set_completion_reference(prev2_wd);
3163 COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_tables_for_rule);
3165 else if (Matches(
"COMMENT",
"ON",
"TEXT",
"SEARCH"))
3166 COMPLETE_WITH(
"CONFIGURATION",
"DICTIONARY",
"PARSER",
"TEMPLATE");
3167 else if (Matches(
"COMMENT",
"ON",
"TEXT",
"SEARCH",
"CONFIGURATION"))
3168 COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_ts_configurations);
3169 else if (Matches(
"COMMENT",
"ON",
"TEXT",
"SEARCH",
"DICTIONARY"))
3170 COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_ts_dictionaries);
3171 else if (Matches(
"COMMENT",
"ON",
"TEXT",
"SEARCH",
"PARSER"))
3172 COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_ts_parsers);
3173 else if (Matches(
"COMMENT",
"ON",
"TEXT",
"SEARCH",
"TEMPLATE"))
3174 COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_ts_templates);
3175 else if (Matches(
"COMMENT",
"ON",
"TRANSFORM",
"FOR"))
3176 COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_datatypes);
3177 else if (Matches(
"COMMENT",
"ON",
"TRANSFORM",
"FOR", MatchAny))
3178 COMPLETE_WITH(
"LANGUAGE");
3179 else if (Matches(
"COMMENT",
"ON",
"TRANSFORM",
"FOR", MatchAny,
"LANGUAGE"))
3181 set_completion_reference(prev2_wd);
3182 COMPLETE_WITH_QUERY(Query_for_list_of_languages);
3184 else if (Matches(
"COMMENT",
"ON",
"TRIGGER", MatchAny))
3185 COMPLETE_WITH(
"ON");
3186 else if (Matches(
"COMMENT",
"ON",
"TRIGGER", MatchAny,
"ON"))
3188 set_completion_reference(prev2_wd);
3189 COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_tables_for_trigger);
3191 else if (Matches(
"COMMENT",
"ON", MatchAny, MatchAnyExcept(
"IS")) ||
3192 Matches(
"COMMENT",
"ON", MatchAny, MatchAny, MatchAnyExcept(
"IS")) ||
3193 Matches(
"COMMENT",
"ON", MatchAny, MatchAny, MatchAny, MatchAnyExcept(
"IS")) ||
3194 Matches(
"COMMENT",
"ON", MatchAny, MatchAny, MatchAny, MatchAny, MatchAnyExcept(
"IS")))
3195 COMPLETE_WITH(
"IS");
3203 else if (Matches(
"COPY|\\copy"))
3204 COMPLETE_WITH_SCHEMA_QUERY_PLUS(Query_for_list_of_tables,
"(");
3206 else if (Matches(
"COPY|\\copy",
"("))
3207 COMPLETE_WITH(
"SELECT",
"TABLE",
"VALUES",
"INSERT INTO",
"UPDATE",
"DELETE FROM",
"WITH");
3209 else if (Matches(
"COPY|\\copy", MatchAny))
3210 COMPLETE_WITH(
"FROM",
"TO");
3212 else if (Matches(
"COPY", MatchAny,
"FROM|TO"))
3214 completion_charp =
"";
3215 completion_force_quote =
true;
3216 matches = rl_completion_matches(
text, complete_from_files);
3218 else if (Matches(
"\\copy", MatchAny,
"FROM|TO"))
3220 completion_charp =
"";
3221 completion_force_quote =
false;
3222 matches = rl_completion_matches(
text, complete_from_files);
3226 else if (Matches(
"COPY|\\copy", MatchAny,
"TO", MatchAny))
3227 COMPLETE_WITH(
"WITH (");
3230 else if (Matches(
"COPY|\\copy", MatchAny,
"FROM", MatchAny))
3231 COMPLETE_WITH(
"WITH (",
"WHERE");
3234 else if (Matches(
"COPY|\\copy", MatchAny,
"FROM|TO", MatchAny,
"WITH",
"("))
3235 COMPLETE_WITH(
"FORMAT",
"FREEZE",
"DELIMITER",
"NULL",
3236 "HEADER",
"QUOTE",
"ESCAPE",
"FORCE_QUOTE",
3237 "FORCE_NOT_NULL",
"FORCE_NULL",
"ENCODING",
"DEFAULT",
3238 "ON_ERROR",
"LOG_VERBOSITY");
3241 else if (Matches(
"COPY|\\copy", MatchAny,
"FROM|TO", MatchAny,
"WITH",
"(",
"FORMAT"))
3242 COMPLETE_WITH(
"binary",
"csv",
"text");
3245 else if (Matches(
"COPY|\\copy", MatchAny,
"FROM|TO", MatchAny,
"WITH",
"(",
"ON_ERROR"))
3246 COMPLETE_WITH(
"stop",
"ignore");
3249 else if (Matches(
"COPY|\\copy", MatchAny,
"FROM|TO", MatchAny,
"WITH",
"(",
"LOG_VERBOSITY"))
3250 COMPLETE_WITH(
"silent",
"default",
"verbose");
3253 else if (Matches(
"COPY|\\copy", MatchAny,
"FROM", MatchAny,
"WITH", MatchAny))
3254 COMPLETE_WITH(
"WHERE");
3258 else if (Matches(
"CREATE",
"ACCESS",
"METHOD", MatchAny))
3259 COMPLETE_WITH(
"TYPE");
3261 else if (Matches(
"CREATE",
"ACCESS",
"METHOD", MatchAny,
"TYPE"))
3262 COMPLETE_WITH(
"INDEX",
"TABLE");
3264 else if (Matches(
"CREATE",
"ACCESS",
"METHOD", MatchAny,
"TYPE", MatchAny))
3265 COMPLETE_WITH(
"HANDLER");
3268 else if (Matches(
"CREATE",
"COLLATION", MatchAny))
3269 COMPLETE_WITH(
"(",
"FROM");
3270 else if (Matches(
"CREATE",
"COLLATION", MatchAny,
"FROM"))
3271 COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_collations);
3272 else if (HeadMatches(
"CREATE",
"COLLATION", MatchAny,
"(*"))
3274 if (TailMatches(
"(|*,"))
3275 COMPLETE_WITH(
"LOCALE =",
"LC_COLLATE =",
"LC_CTYPE =",
3276 "PROVIDER =",
"DETERMINISTIC =");
3277 else if (TailMatches(
"PROVIDER",
"="))
3278 COMPLETE_WITH(
"libc",
"icu");
3279 else if (TailMatches(
"DETERMINISTIC",
"="))
3280 COMPLETE_WITH(
"true",
"false");
3284 else if (Matches(
"CREATE",
"DATABASE", MatchAny))
3285 COMPLETE_WITH(
"OWNER",
"TEMPLATE",
"ENCODING",
"TABLESPACE",
3286 "IS_TEMPLATE",
"STRATEGY",
3287 "ALLOW_CONNECTIONS",
"CONNECTION LIMIT",
3288 "LC_COLLATE",
"LC_CTYPE",
"LOCALE",
"OID",
3289 "LOCALE_PROVIDER",
"ICU_LOCALE");
3291 else if (Matches(
"CREATE",
"DATABASE", MatchAny,
"TEMPLATE"))
3292 COMPLETE_WITH_QUERY(Query_for_list_of_template_databases);
3293 else if (Matches(
"CREATE",
"DATABASE", MatchAny,
"STRATEGY"))
3294 COMPLETE_WITH(
"WAL_LOG",
"FILE_COPY");
3297 else if (Matches(
"CREATE",
"DOMAIN", MatchAny))
3298 COMPLETE_WITH(
"AS");
3299 else if (Matches(
"CREATE",
"DOMAIN", MatchAny,
"AS"))
3300 COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_datatypes);
3301 else if (Matches(
"CREATE",
"DOMAIN", MatchAny,
"AS", MatchAny))
3302 COMPLETE_WITH(
"COLLATE",
"DEFAULT",
"CONSTRAINT",
3303 "NOT NULL",
"NULL",
"CHECK (");
3304 else if (Matches(
"CREATE",
"DOMAIN", MatchAny,
"COLLATE"))
3305 COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_collations);
3309 else if (Matches(
"CREATE",
"EXTENSION"))
3310 COMPLETE_WITH_QUERY(Query_for_list_of_available_extensions);
3312 else if (Matches(
"CREATE",
"EXTENSION", MatchAny))
3313 COMPLETE_WITH(
"WITH SCHEMA",
"CASCADE",
"VERSION");
3315 else if (Matches(
"CREATE",
"EXTENSION", MatchAny,
"VERSION"))
3317 set_completion_reference(prev2_wd);
3318 COMPLETE_WITH_QUERY(Query_for_list_of_available_extension_versions);
3322 else if (Matches(
"CREATE",
"FOREIGN"))
3323 COMPLETE_WITH(
"DATA WRAPPER",
"TABLE");
3326 else if (Matches(
"CREATE",
"FOREIGN",
"DATA",
"WRAPPER", MatchAny))
3327 COMPLETE_WITH(
"HANDLER",
"VALIDATOR",
"OPTIONS");
3330 else if (Matches(
"CREATE",
"FOREIGN",
"TABLE", MatchAny))
3331 COMPLETE_WITH(
"(",
"PARTITION OF");
3335 else if (TailMatches(
"CREATE",
"UNIQUE"))
3336 COMPLETE_WITH(
"INDEX");
3342 else if (TailMatches(
"CREATE|UNIQUE",
"INDEX"))
3343 COMPLETE_WITH_SCHEMA_QUERY_PLUS(Query_for_list_of_indexes,
3344 "ON",
"CONCURRENTLY");
3350 else if (TailMatches(
"INDEX|CONCURRENTLY", MatchAny,
"ON") ||
3351 TailMatches(
"INDEX|CONCURRENTLY",
"ON"))
3352 COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_indexables);
3358 else if (TailMatches(
"CREATE|UNIQUE",
"INDEX",
"CONCURRENTLY"))
3359 COMPLETE_WITH_SCHEMA_QUERY_PLUS(Query_for_list_of_indexes,
3362 else if (TailMatches(
"CREATE|UNIQUE",
"INDEX", MatchAny) ||
3363 TailMatches(
"CREATE|UNIQUE",
"INDEX",
"CONCURRENTLY", MatchAny))
3364 COMPLETE_WITH(
"ON");
3370 else if (TailMatches(
"INDEX", MatchAny,
"ON", MatchAny) ||
3371 TailMatches(
"INDEX|CONCURRENTLY",
"ON", MatchAny))
3372 COMPLETE_WITH(
"(",
"USING");
3373 else if (TailMatches(
"INDEX", MatchAny,
"ON", MatchAny,
"(") ||
3374 TailMatches(
"INDEX|CONCURRENTLY",
"ON", MatchAny,
"("))
3375 COMPLETE_WITH_ATTR(prev2_wd);
3377 else if (TailMatches(
"ON", MatchAny,
"USING", MatchAny,
"("))
3378 COMPLETE_WITH_ATTR(prev4_wd);
3380 else if (TailMatches(
"INDEX", MatchAny, MatchAny,
"ON", MatchAny,
"USING") ||
3381 TailMatches(
"INDEX", MatchAny,
"ON", MatchAny,
"USING") ||
3382 TailMatches(
"INDEX",
"ON", MatchAny,
"USING"))
3383 COMPLETE_WITH_QUERY(Query_for_list_of_index_access_methods);
3384 else if (TailMatches(
"ON", MatchAny,
"USING", MatchAny) &&
3385 !TailMatches(
"POLICY", MatchAny, MatchAny, MatchAny, MatchAny, MatchAny) &&
3386 !TailMatches(
"FOR", MatchAny, MatchAny, MatchAny))
3390 else if (Matches(
"CREATE",
"OR"))
3391 COMPLETE_WITH(
"REPLACE");
3395 else if (Matches(
"CREATE",
"POLICY", MatchAny))
3396 COMPLETE_WITH(
"ON");
3398 else if (Matches(
"CREATE",
"POLICY", MatchAny,
"ON"))
3399 COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_tables);
3401 else if (Matches(
"CREATE",
"POLICY", MatchAny,
"ON", MatchAny))
3402 COMPLETE_WITH(
"AS",
"FOR",
"TO",
"USING (",
"WITH CHECK (");
3404 else if (Matches(
"CREATE",
"POLICY", MatchAny,
"ON", MatchAny,
"AS"))
3405 COMPLETE_WITH(
"PERMISSIVE",
"RESTRICTIVE");
3411 else if (Matches(
"CREATE",
"POLICY", MatchAny,
"ON", MatchAny,
"AS", MatchAny))
3412 COMPLETE_WITH(
"FOR",
"TO",
"USING",
"WITH CHECK");
3414 else if (Matches(
"CREATE",
"POLICY", MatchAny,
"ON", MatchAny,
"FOR"))
3415 COMPLETE_WITH(
"ALL",
"SELECT",
"INSERT",
"UPDATE",
"DELETE");
3417 else if (Matches(
"CREATE",
"POLICY", MatchAny,
"ON", MatchAny,
"FOR",
"INSERT"))
3418 COMPLETE_WITH(
"TO",
"WITH CHECK (");
3420 else if (Matches(
"CREATE",
"POLICY", MatchAny,
"ON", MatchAny,
"FOR",
"SELECT|DELETE"))
3421 COMPLETE_WITH(
"TO",
"USING (");
3423 else if (Matches(
"CREATE",
"POLICY", MatchAny,
"ON", MatchAny,
"FOR",
"ALL|UPDATE"))
3424 COMPLETE_WITH(
"TO",
"USING (",
"WITH CHECK (");
3426 else if (Matches(
"CREATE",
"POLICY", MatchAny,
"ON", MatchAny,
"TO"))
3427 COMPLETE_WITH_QUERY_PLUS(Query_for_list_of_roles,
3428 Keywords_for_list_of_grant_roles);
3430 else if (Matches(
"CREATE",
"POLICY", MatchAny,
"ON", MatchAny,
"USING"))
3437 else if (Matches(
"CREATE",
"POLICY", MatchAny,
"ON", MatchAny,
"AS", MatchAny,
"FOR"))
3438 COMPLETE_WITH(
"ALL",
"SELECT",
"INSERT",
"UPDATE",
"DELETE");
3444 else if (Matches(
"CREATE",
"POLICY", MatchAny,
"ON", MatchAny,
"AS", MatchAny,
"FOR",
"INSERT"))
3445 COMPLETE_WITH(
"TO",
"WITH CHECK (");
3451 else if (Matches(
"CREATE",
"POLICY", MatchAny,
"ON", MatchAny,
"AS", MatchAny,
"FOR",
"SELECT|DELETE"))
3452 COMPLETE_WITH(
"TO",
"USING (");
3458 else if (Matches(
"CREATE",
"POLICY", MatchAny,
"ON", MatchAny,
"AS", MatchAny,
"FOR",
"ALL|UPDATE"))
3459 COMPLETE_WITH(
"TO",
"USING (",
"WITH CHECK (");
3465 else if (Matches(
"CREATE",
"POLICY", MatchAny,
"ON", MatchAny,
"AS", MatchAny,
"TO"))
3466 COMPLETE_WITH_QUERY_PLUS(Query_for_list_of_roles,
3467 Keywords_for_list_of_grant_roles);
3473 else if (Matches(
"CREATE",
"POLICY", MatchAny,
"ON", MatchAny,
"AS", MatchAny,
"USING"))
3478 else if (Matches(
"CREATE",
"PUBLICATION", MatchAny))
3479 COMPLETE_WITH(
"FOR TABLE",
"FOR ALL TABLES",
"FOR TABLES IN SCHEMA",
"WITH (");
3480 else if (Matches(
"CREATE",
"PUBLICATION", MatchAny,
"FOR"))
3481 COMPLETE_WITH(
"TABLE",
"ALL TABLES",
"TABLES IN SCHEMA");
3482 else if (Matches(
"CREATE",
"PUBLICATION", MatchAny,
"FOR",
"ALL"))
3483 COMPLETE_WITH(
"TABLES");
3484 else if (Matches(
"CREATE",
"PUBLICATION", MatchAny,
"FOR",
"ALL",
"TABLES"))
3485 COMPLETE_WITH(
"WITH (");
3486 else if (Matches(
"CREATE",
"PUBLICATION", MatchAny,
"FOR",
"TABLES"))
3487 COMPLETE_WITH(
"IN SCHEMA");
3488 else if (Matches(
"CREATE",
"PUBLICATION", MatchAny,
"FOR",
"TABLE", MatchAny) && !ends_with(prev_wd,
','))
3489 COMPLETE_WITH(
"WHERE (",
"WITH (");
3491 else if (Matches(
"CREATE",
"PUBLICATION", MatchAny,
"FOR",
"TABLE"))
3492 COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_tables);
3498 else if (Matches(
"CREATE",
"PUBLICATION", MatchAny, MatchAnyN,
"WHERE"))
3500 else if (Matches(
"CREATE",
"PUBLICATION", MatchAny, MatchAnyN,
"WHERE",
"("))
3501 COMPLETE_WITH_ATTR(prev3_wd);
3502 else if (Matches(
"CREATE",
"PUBLICATION", MatchAny, MatchAnyN,
"WHERE",
"(*)"))
3503 COMPLETE_WITH(
" WITH (");
3508 else if (Matches(
"CREATE",
"PUBLICATION", MatchAny,
"FOR",
"TABLES",
"IN",
"SCHEMA"))
3509 COMPLETE_WITH_QUERY_PLUS(Query_for_list_of_schemas
3510 " AND nspname NOT LIKE E'pg\\\\_%%'",
3512 else if (Matches(
"CREATE",
"PUBLICATION", MatchAny,
"FOR",
"TABLES",
"IN",
"SCHEMA", MatchAny) && (!ends_with(prev_wd,
',')))
3513 COMPLETE_WITH(
"WITH (");
3515 else if (Matches(
"CREATE",
"PUBLICATION", MatchAnyN,
"WITH",
"("))
3516 COMPLETE_WITH(
"publish",
"publish_generated_columns",
"publish_via_partition_root");
3520 else if (Matches(
"CREATE",
"RULE", MatchAny) ||
3521 Matches(
"CREATE",
"OR",
"REPLACE",
"RULE", MatchAny))
3522 COMPLETE_WITH(
"AS ON");
3524 else if (Matches(
"CREATE",
"RULE", MatchAny,
"AS") ||
3525 Matches(
"CREATE",
"OR",
"REPLACE",
"RULE", MatchAny,
"AS"))
3526 COMPLETE_WITH(
"ON");
3532 else if (Matches(
"CREATE",
"RULE", MatchAny,
"AS",
"ON") ||
3533 Matches(
"CREATE",
"OR",
"REPLACE",
"RULE", MatchAny,
"AS",
"ON"))
3534 COMPLETE_WITH(
"SELECT",
"UPDATE",
"INSERT",
"DELETE");
3536 else if (TailMatches(
"AS",
"ON",
"SELECT|UPDATE|INSERT|DELETE"))
3537 COMPLETE_WITH(
"TO");
3539 else if (TailMatches(
"AS",
"ON",
"SELECT|UPDATE|INSERT|DELETE",
"TO"))
3540 COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_tables);
3543 else if (Matches(
"CREATE",
"SCHEMA"))
3544 COMPLETE_WITH_QUERY_PLUS(Query_for_list_of_schemas,
3546 else if (Matches(
"CREATE",
"SCHEMA",
"AUTHORIZATION") ||
3547 Matches(
"CREATE",
"SCHEMA", MatchAny,
"AUTHORIZATION"))
3548 COMPLETE_WITH_QUERY_PLUS(Query_for_list_of_roles,
3549 Keywords_for_list_of_owner_roles);
3550 else if (Matches(
"CREATE",
"SCHEMA",
"AUTHORIZATION", MatchAny) ||
3551 Matches(
"CREATE",
"SCHEMA", MatchAny,
"AUTHORIZATION", MatchAny))
3552 COMPLETE_WITH(
"CREATE",
"GRANT");
3553 else if (Matches(
"CREATE",
"SCHEMA", MatchAny))
3554 COMPLETE_WITH(
"AUTHORIZATION",
"CREATE",
"GRANT");
3557 else if (TailMatches(
"CREATE",
"SEQUENCE", MatchAny) ||
3558 TailMatches(
"CREATE",
"TEMP|TEMPORARY",
"SEQUENCE", MatchAny))
3559 COMPLETE_WITH(
"AS",
"INCREMENT BY",
"MINVALUE",
"MAXVALUE",
"NO",
3560 "CACHE",
"CYCLE",
"OWNED BY",
"START WITH");
3561 else if (TailMatches(
"CREATE",
"SEQUENCE", MatchAny,
"AS") ||
3562 TailMatches(
"CREATE",
"TEMP|TEMPORARY",
"SEQUENCE", MatchAny,
"AS"))
3563 COMPLETE_WITH_CS(
"smallint",
"integer",
"bigint");
3564 else if (TailMatches(
"CREATE",
"SEQUENCE", MatchAny,
"NO") ||
3565 TailMatches(
"CREATE",
"TEMP|TEMPORARY",
"SEQUENCE", MatchAny,
"NO"))
3566 COMPLETE_WITH(
"MINVALUE",
"MAXVALUE",
"CYCLE");
3569 else if (Matches(
"CREATE",
"SERVER", MatchAny))
3570 COMPLETE_WITH(
"TYPE",
"VERSION",
"FOREIGN DATA WRAPPER");
3573 else if (Matches(
"CREATE",
"STATISTICS", MatchAny))
3574 COMPLETE_WITH(
"(",
"ON");
3575 else if (Matches(
"CREATE",
"STATISTICS", MatchAny,
"("))
3576 COMPLETE_WITH(
"ndistinct",
"dependencies",
"mcv");
3577 else if (Matches(
"CREATE",
"STATISTICS", MatchAny,
"(*)"))
3578 COMPLETE_WITH(
"ON");
3579 else if (Matches(
"CREATE",
"STATISTICS", MatchAny, MatchAnyN,
"FROM"))
3580 COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_tables);
3584 else if (TailMatches(
"CREATE",
"TEMP|TEMPORARY"))
3585 COMPLETE_WITH(
"SEQUENCE",
"TABLE",
"VIEW");
3587 else if (TailMatches(
"CREATE",
"UNLOGGED"))
3588 COMPLETE_WITH(
"TABLE",
"SEQUENCE");
3590 else if (TailMatches(
"PARTITION",
"BY"))
3591 COMPLETE_WITH(
"RANGE (",
"LIST (",
"HASH (");
3593 else if (TailMatches(
"PARTITION",
"OF"))
3594 COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_partitioned_tables);
3596 else if (TailMatches(
"PARTITION",
"OF", MatchAny))
3597 COMPLETE_WITH(
"FOR VALUES",
"DEFAULT");
3599 else if (TailMatches(
"CREATE",
"TABLE", MatchAny) ||
3600 TailMatches(
"CREATE",
"TEMP|TEMPORARY|UNLOGGED",
"TABLE", MatchAny))
3601 COMPLETE_WITH(
"(",
"AS",
"OF",
"PARTITION OF");
3603 else if (TailMatches(
"CREATE",
"TABLE", MatchAny,
"OF") ||
3604 TailMatches(
"CREATE",
"TEMP|TEMPORARY|UNLOGGED",
"TABLE", MatchAny,
"OF"))
3605 COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_composite_datatypes);
3607 else if (TailMatches(
"CREATE",
"TABLE", MatchAny,
"AS") ||
3608 TailMatches(
"CREATE",
"TABLE", MatchAny,
"(*)",
"AS") ||
3609 TailMatches(
"CREATE",
"TEMP|TEMPORARY|UNLOGGED",
"TABLE", MatchAny,
"AS") ||
3610 TailMatches(
"CREATE",
"TEMP|TEMPORARY|UNLOGGED",
"TABLE", MatchAny,
"(*)",
"AS"))
3611 COMPLETE_WITH(
"EXECUTE",
"SELECT",
"TABLE",
"VALUES",
"WITH");
3613 else if (TailMatches(
"CREATE",
"TABLE", MatchAny,
"(*)") ||
3614 TailMatches(
"CREATE",
"UNLOGGED",
"TABLE", MatchAny,
"(*)"))
3615 COMPLETE_WITH(
"AS",
"INHERITS (",
"PARTITION BY",
"USING",
"TABLESPACE",
"WITH (");
3616 else if (TailMatches(
"CREATE",
"TEMP|TEMPORARY",
"TABLE", MatchAny,
"(*)"))
3617 COMPLETE_WITH(
"AS",
"INHERITS (",
"ON COMMIT",
"PARTITION BY",
3618 "TABLESPACE",
"WITH (");
3620 else if (TailMatches(
"CREATE",
"TABLE", MatchAny,
"(*)",
"USING") ||
3621 TailMatches(
"CREATE",
"TEMP|TEMPORARY|UNLOGGED",
"TABLE", MatchAny,
"(*)",
"USING"))
3622 COMPLETE_WITH_QUERY(Query_for_list_of_table_access_methods);
3624 else if (TailMatches(
"CREATE",
"TABLE", MatchAny,
"(*)",
"WITH",
"(") ||
3625 TailMatches(
"CREATE",
"TEMP|TEMPORARY|UNLOGGED",
"TABLE", MatchAny,
"(*)",
"WITH",
"("))
3626 COMPLETE_WITH_LIST(table_storage_parameters);
3628 else if (TailMatches(
"CREATE",
"TEMP|TEMPORARY",
"TABLE", MatchAny,
"(*)",
"ON",
"COMMIT"))
3629 COMPLETE_WITH(
"DELETE ROWS",
"DROP",
"PRESERVE ROWS");
3632 else if (Matches(
"CREATE",
"TABLESPACE", MatchAny))
3633 COMPLETE_WITH(
"OWNER",
"LOCATION");
3635 else if (Matches(
"CREATE",
"TABLESPACE", MatchAny,
"OWNER", MatchAny))
3636 COMPLETE_WITH(
"LOCATION");
3639 else if (Matches(
"CREATE",
"TEXT",
"SEARCH"))
3640 COMPLETE_WITH(
"CONFIGURATION",
"DICTIONARY",
"PARSER",
"TEMPLATE");
3641 else if (Matches(
"CREATE",
"TEXT",
"SEARCH",
"CONFIGURATION|DICTIONARY|PARSER|TEMPLATE", MatchAny))
3645 else if (Matches(
"CREATE",
"TRANSFORM") ||
3646 Matches(
"CREATE",
"OR",
"REPLACE",
"TRANSFORM"))
3647 COMPLETE_WITH(
"FOR");
3648 else if (Matches(
"CREATE",
"TRANSFORM",
"FOR") ||
3649 Matches(
"CREATE",
"OR",
"REPLACE",
"TRANSFORM",
"FOR"))
3650 COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_datatypes);
3651 else if (Matches(
"CREATE",
"TRANSFORM",
"FOR", MatchAny) ||
3652 Matches(
"CREATE",
"OR",
"REPLACE",
"TRANSFORM",
"FOR", MatchAny))
3653 COMPLETE_WITH(
"LANGUAGE");
3654 else if (Matches(
"CREATE",
"TRANSFORM",
"FOR", MatchAny,
"LANGUAGE") ||
3655 Matches(
"CREATE",
"OR",
"REPLACE",
"TRANSFORM",
"FOR", MatchAny,
"LANGUAGE"))
3657 set_completion_reference(prev2_wd);
3658 COMPLETE_WITH_QUERY(Query_for_list_of_languages);
3662 else if (Matches(
"CREATE",
"SUBSCRIPTION", MatchAny))
3663 COMPLETE_WITH(
"CONNECTION");
3664 else if (Matches(
"CREATE",
"SUBSCRIPTION", MatchAny,
"CONNECTION", MatchAny))
3665 COMPLETE_WITH(
"PUBLICATION");
3666 else if (Matches(
"CREATE",
"SUBSCRIPTION", MatchAny,
"CONNECTION",
3667 MatchAny,
"PUBLICATION"))
3671 else if (Matches(
"CREATE",
"SUBSCRIPTION", MatchAnyN,
"PUBLICATION", MatchAny))
3672 COMPLETE_WITH(
"WITH (");
3674 else if (Matches(
"CREATE",
"SUBSCRIPTION", MatchAnyN,
"WITH",
"("))
3675 COMPLETE_WITH(
"binary",
"connect",
"copy_data",
"create_slot",
3676 "disable_on_error",
"enabled",
"failover",
"origin",
3677 "password_required",
"run_as_owner",
"slot_name",
3678 "streaming",
"synchronous_commit",
"two_phase");
3686 else if (TailMatches(
"CREATE",
"TRIGGER", MatchAny) ||
3687 TailMatches(
"CREATE",
"OR",
"REPLACE",
"TRIGGER", MatchAny))
3688 COMPLETE_WITH(
"BEFORE",
"AFTER",
"INSTEAD OF");
3694 else if (TailMatches(
"CREATE",
"TRIGGER", MatchAny,
"BEFORE|AFTER") ||
3695 TailMatches(
"CREATE",
"OR",
"REPLACE",
"TRIGGER", MatchAny,
"BEFORE|AFTER"))
3696 COMPLETE_WITH(
"INSERT",
"DELETE",
"UPDATE",
"TRUNCATE");
3698 else if (TailMatches(
"CREATE",
"TRIGGER", MatchAny,
"INSTEAD",
"OF") ||
3699 TailMatches(
"CREATE",
"OR",
"REPLACE",
"TRIGGER", MatchAny,
"INSTEAD",
"OF"))
3700 COMPLETE_WITH(
"INSERT",
"DELETE",
"UPDATE");
3706 else if (TailMatches(
"CREATE",
"TRIGGER", MatchAny,
"BEFORE|AFTER", MatchAny) ||
3707 TailMatches(
"CREATE",
"OR",
"REPLACE",
"TRIGGER", MatchAny,
"BEFORE|AFTER", MatchAny) ||
3708 TailMatches(
"CREATE",
"TRIGGER", MatchAny,
"INSTEAD",
"OF", MatchAny) ||
3709 TailMatches(
"CREATE",
"OR",
"REPLACE",
"TRIGGER", MatchAny,
"INSTEAD",
"OF", MatchAny))
3710 COMPLETE_WITH(
"ON",
"OR");
3717 else if (TailMatches(
"CREATE",
"TRIGGER", MatchAny,
"BEFORE|AFTER", MatchAny,
"ON") ||
3718 TailMatches(
"CREATE",
"OR",
"REPLACE",
"TRIGGER", MatchAny,
"BEFORE|AFTER", MatchAny,
"ON"))
3719 COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_tables);
3725 else if (TailMatches(
"CREATE",
"TRIGGER", MatchAny,
"INSTEAD",
"OF", MatchAny,
"ON") ||
3726 TailMatches(
"CREATE",
"OR",
"REPLACE",
"TRIGGER", MatchAny,
"INSTEAD",
"OF", MatchAny,
"ON"))
3727 COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_views);
3728 else if (Matches(
"CREATE",
"TRIGGER", MatchAnyN,
3730 Matches(
"CREATE",
"OR",
"REPLACE",
"TRIGGER", MatchAnyN,
3734 COMPLETE_WITH(
"NOT DEFERRABLE",
"DEFERRABLE",
"INITIALLY",
3735 "REFERENCING",
"FOR",
"WHEN (",
"EXECUTE FUNCTION");
3737 COMPLETE_WITH(
"NOT DEFERRABLE",
"DEFERRABLE",
"INITIALLY",
3738 "REFERENCING",
"FOR",
"WHEN (",
"EXECUTE PROCEDURE");
3740 else if (Matches(
"CREATE",
"TRIGGER", MatchAnyN,
3742 Matches(
"CREATE",
"OR",
"REPLACE",
"TRIGGER", MatchAnyN,
3744 Matches(
"CREATE",
"TRIGGER", MatchAnyN,
3745 "INITIALLY",
"IMMEDIATE|DEFERRED") ||
3746 Matches(
"CREATE",
"OR",
"REPLACE",
"TRIGGER", MatchAnyN,
3747 "INITIALLY",
"IMMEDIATE|DEFERRED"))
3750 COMPLETE_WITH(
"REFERENCING",
"FOR",
"WHEN (",
"EXECUTE FUNCTION");
3752 COMPLETE_WITH(
"REFERENCING",
"FOR",
"WHEN (",
"EXECUTE PROCEDURE");
3754 else if (Matches(
"CREATE",
"TRIGGER", MatchAnyN,
3756 Matches(
"CREATE",
"OR",
"REPLACE",
"TRIGGER", MatchAnyN,
3758 COMPLETE_WITH(
"OLD TABLE",
"NEW TABLE");
3759 else if (Matches(
"CREATE",
"TRIGGER", MatchAnyN,
3760 "OLD|NEW",
"TABLE") ||
3761 Matches(
"CREATE",
"OR",
"REPLACE",
"TRIGGER", MatchAnyN,
3762 "OLD|NEW",
"TABLE"))
3763 COMPLETE_WITH(
"AS");
3764 else if (Matches(
"CREATE",
"TRIGGER", MatchAnyN,
3765 "REFERENCING",
"OLD",
"TABLE",
"AS", MatchAny) ||
3766 Matches(
"CREATE",
"OR",
"REPLACE",
"TRIGGER", MatchAnyN,
3767 "REFERENCING",
"OLD",
"TABLE",
"AS", MatchAny) ||
3768 Matches(
"CREATE",
"TRIGGER", MatchAnyN,
3769 "REFERENCING",
"OLD",
"TABLE", MatchAny) ||
3770 Matches(
"CREATE",
"OR",
"REPLACE",
"TRIGGER", MatchAnyN,
3771 "REFERENCING",
"OLD",
"TABLE", MatchAny))
3774 COMPLETE_WITH(
"NEW TABLE",
"FOR",
"WHEN (",
"EXECUTE FUNCTION");
3776 COMPLETE_WITH(
"NEW TABLE",
"FOR",
"WHEN (",
"EXECUTE PROCEDURE");
3778 else if (Matches(
"CREATE",
"TRIGGER", MatchAnyN,
3779 "REFERENCING",
"NEW",
"TABLE",
"AS", MatchAny) ||
3780 Matches(
"CREATE",
"OR",
"REPLACE",
"TRIGGER", MatchAnyN,
3781 "REFERENCING",
"NEW",
"TABLE",
"AS", MatchAny) ||
3782 Matches(
"CREATE",
"TRIGGER", MatchAnyN,
3783 "REFERENCING",
"NEW",
"TABLE", MatchAny) ||
3784 Matches(
"CREATE",
"OR",
"REPLACE",
"TRIGGER", MatchAnyN,
3785 "REFERENCING",
"NEW",
"TABLE", MatchAny))
3788 COMPLETE_WITH(
"OLD TABLE",
"FOR",
"WHEN (",
"EXECUTE FUNCTION");
3790 COMPLETE_WITH(
"OLD TABLE",
"FOR",
"WHEN (",
"EXECUTE PROCEDURE");
3792 else if (Matches(
"CREATE",
"TRIGGER", MatchAnyN,
3793 "REFERENCING",
"OLD|NEW",
"TABLE",
"AS", MatchAny,
"OLD|NEW",
"TABLE",
"AS", MatchAny) ||
3794 Matches(
"CREATE",
"OR",
"REPLACE",
"TRIGGER", MatchAnyN,
3795 "REFERENCING",
"OLD|NEW",
"TABLE",
"AS", MatchAny,
"OLD|NEW",
"TABLE",
"AS", MatchAny) ||
3796 Matches(
"CREATE",
"TRIGGER", MatchAnyN,
3797 "REFERENCING",
"OLD|NEW",
"TABLE", MatchAny,
"OLD|NEW",
"TABLE",
"AS", MatchAny) ||
3798 Matches(
"CREATE",
"OR",
"REPLACE",
"TRIGGER", MatchAnyN,
3799 "REFERENCING",
"OLD|NEW",
"TABLE", MatchAny,
"OLD|NEW",
"TABLE",
"AS", MatchAny) ||
3800 Matches(
"CREATE",
"TRIGGER", MatchAnyN,
3801 "REFERENCING",
"OLD|NEW",
"TABLE",
"AS", MatchAny,
"OLD|NEW",
"TABLE", MatchAny) ||
3802 Matches(
"CREATE",
"OR",
"REPLACE",
"TRIGGER", MatchAnyN,
3803 "REFERENCING",
"OLD|NEW",
"TABLE",
"AS", MatchAny,
"OLD|NEW",
"TABLE", MatchAny) ||
3804 Matches(
"CREATE",
"TRIGGER", MatchAnyN,
3805 "REFERENCING",
"OLD|NEW",
"TABLE", MatchAny,
"OLD|NEW",
"TABLE", MatchAny) ||
3806 Matches(
"CREATE",
"OR",
"REPLACE",
"TRIGGER", MatchAnyN,
3807 "REFERENCING",
"OLD|NEW",
"TABLE", MatchAny,
"OLD|NEW",
"TABLE", MatchAny))
3810 COMPLETE_WITH(
"FOR",
"WHEN (",
"EXECUTE FUNCTION");
3812 COMPLETE_WITH(
"FOR",
"WHEN (",
"EXECUTE PROCEDURE");
3814 else if (Matches(
"CREATE",
"TRIGGER", MatchAnyN,
3816 Matches(
"CREATE",
"OR",
"REPLACE",
"TRIGGER", MatchAnyN,
3818 COMPLETE_WITH(
"EACH",
"ROW",
"STATEMENT");
3819 else if (Matches(
"CREATE",
"TRIGGER", MatchAnyN,
3821 Matches(
"CREATE",
"OR",
"REPLACE",
"TRIGGER", MatchAnyN,
3823 COMPLETE_WITH(
"ROW",
"STATEMENT");
3824 else if (Matches(
"CREATE",
"TRIGGER", MatchAnyN,
3825 "FOR",
"EACH",
"ROW|STATEMENT") ||
3826 Matches(
"CREATE",
"OR",
"REPLACE",
"TRIGGER", MatchAnyN,
3827 "FOR",
"EACH",
"ROW|STATEMENT") ||
3828 Matches(
"CREATE",
"TRIGGER", MatchAnyN,
3829 "FOR",
"ROW|STATEMENT") ||
3830 Matches(
"CREATE",
"OR",
"REPLACE",
"TRIGGER", MatchAnyN,
3831 "FOR",
"ROW|STATEMENT"))
3834 COMPLETE_WITH(
"WHEN (",
"EXECUTE FUNCTION");
3836 COMPLETE_WITH(
"WHEN (",
"EXECUTE PROCEDURE");
3838 else if (Matches(
"CREATE",
"TRIGGER", MatchAnyN,
3840 Matches(
"CREATE",
"OR",
"REPLACE",
"TRIGGER", MatchAnyN,
3844 COMPLETE_WITH(
"EXECUTE FUNCTION");
3846 COMPLETE_WITH(
"EXECUTE PROCEDURE");
3853 else if (Matches(
"CREATE",
"TRIGGER", MatchAnyN,
3855 Matches(
"CREATE",
"OR",
"REPLACE",
"TRIGGER", MatchAnyN,
3859 COMPLETE_WITH(
"FUNCTION");
3861 COMPLETE_WITH(
"PROCEDURE");
3863 else if (Matches(
"CREATE",
"TRIGGER", MatchAnyN,
3864 "EXECUTE",
"FUNCTION|PROCEDURE") ||
3865 Matches(
"CREATE",
"OR",
"REPLACE",
"TRIGGER", MatchAnyN,
3866 "EXECUTE",
"FUNCTION|PROCEDURE"))
3867 COMPLETE_WITH_VERSIONED_SCHEMA_QUERY(Query_for_list_of_functions);
3870 else if (Matches(
"CREATE",
"ROLE|GROUP|USER", MatchAny) &&
3871 !TailMatches(
"USER",
"MAPPING"))
3872 COMPLETE_WITH(
"ADMIN",
"BYPASSRLS",
"CONNECTION LIMIT",
"CREATEDB",
3873 "CREATEROLE",
"ENCRYPTED PASSWORD",
"IN",
"INHERIT",
3874 "LOGIN",
"NOBYPASSRLS",
3875 "NOCREATEDB",
"NOCREATEROLE",
"NOINHERIT",
3876 "NOLOGIN",
"NOREPLICATION",
"NOSUPERUSER",
"PASSWORD",
3877 "REPLICATION",
"ROLE",
"SUPERUSER",
"SYSID",
3878 "VALID UNTIL",
"WITH");
3881 else if (Matches(
"CREATE",
"ROLE|GROUP|USER", MatchAny,
"WITH"))
3883 COMPLETE_WITH(
"ADMIN",
"BYPASSRLS",
"CONNECTION LIMIT",
"CREATEDB",
3884 "CREATEROLE",
"ENCRYPTED PASSWORD",
"IN",
"INHERIT",
3885 "LOGIN",
"NOBYPASSRLS",
3886 "NOCREATEDB",
"NOCREATEROLE",
"NOINHERIT",
3887 "NOLOGIN",
"NOREPLICATION",
"NOSUPERUSER",
"PASSWORD",
3888 "REPLICATION",
"ROLE",
"SUPERUSER",
"SYSID",
3892 else if (Matches(
"CREATE",
"ROLE|USER|GROUP", MatchAny,
"IN"))
3893 COMPLETE_WITH(
"GROUP",
"ROLE");
3896 else if (Matches(
"CREATE",
"TYPE", MatchAny))
3897 COMPLETE_WITH(
"(",
"AS");
3898 else if (Matches(
"CREATE",
"TYPE", MatchAny,
"AS"))
3899 COMPLETE_WITH(
"ENUM",
"RANGE",
"(");
3900 else if (HeadMatches(
"CREATE",
"TYPE", MatchAny,
"AS",
"("))
3902 if (TailMatches(
"(|*,", MatchAny))
3903 COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_datatypes);
3904 else if (TailMatches(
"(|*,", MatchAny, MatchAnyExcept(
"*)")))
3905 COMPLETE_WITH(
"COLLATE",
",",
")");
3907 else if (Matches(
"CREATE",
"TYPE", MatchAny,
"AS",
"ENUM|RANGE"))
3909 else if (HeadMatches(
"CREATE",
"TYPE", MatchAny,
"("))
3911 if (TailMatches(
"(|*,"))
3912 COMPLETE_WITH(
"INPUT",
"OUTPUT",
"RECEIVE",
"SEND",
3913 "TYPMOD_IN",
"TYPMOD_OUT",
"ANALYZE",
"SUBSCRIPT",
3914 "INTERNALLENGTH",
"PASSEDBYVALUE",
"ALIGNMENT",
3915 "STORAGE",
"LIKE",
"CATEGORY",
"PREFERRED",
3916 "DEFAULT",
"ELEMENT",
"DELIMITER",
3918 else if (TailMatches(
"(*|*,", MatchAnyExcept(
"*=")))
3920 else if (TailMatches(
"=", MatchAnyExcept(
"*)")))
3921 COMPLETE_WITH(
",",
")");
3923 else if (HeadMatches(
"CREATE",
"TYPE", MatchAny,
"AS",
"RANGE",
"("))
3925 if (TailMatches(
"(|*,"))
3926 COMPLETE_WITH(
"SUBTYPE",
"SUBTYPE_OPCLASS",
"COLLATION",
3927 "CANONICAL",
"SUBTYPE_DIFF",
3928 "MULTIRANGE_TYPE_NAME");
3929 else if (TailMatches(
"(*|*,", MatchAnyExcept(
"*=")))
3931 else if (TailMatches(
"=", MatchAnyExcept(
"*)")))
3932 COMPLETE_WITH(
",",
")");
3937 else if (TailMatches(
"CREATE",
"VIEW", MatchAny) ||
3938 TailMatches(
"CREATE",
"OR",
"REPLACE",
"VIEW", MatchAny))
3939 COMPLETE_WITH(
"AS",
"WITH");
3941 else if (TailMatches(
"CREATE",
"VIEW", MatchAny,
"AS") ||
3942 TailMatches(
"CREATE",
"OR",
"REPLACE",
"VIEW", MatchAny,
"AS"))
3943 COMPLETE_WITH(
"SELECT");
3945 else if (TailMatches(
"CREATE",
"VIEW", MatchAny,
"WITH") ||
3946 TailMatches(
"CREATE",
"OR",
"REPLACE",
"VIEW", MatchAny,
"WITH"))
3948 else if (TailMatches(
"CREATE",
"VIEW", MatchAny,
"WITH",
"(") ||
3949 TailMatches(
"CREATE",
"OR",
"REPLACE",
"VIEW", MatchAny,
"WITH",
"("))
3950 COMPLETE_WITH_LIST(view_optional_parameters);
3951 else if (TailMatches(
"CREATE",
"VIEW", MatchAny,
"WITH",
"(",
"check_option") ||
3952 TailMatches(
"CREATE",
"OR",
"REPLACE",
"VIEW", MatchAny,
"WITH",
"(",
"check_option"))
3954 else if (TailMatches(
"CREATE",
"VIEW", MatchAny,
"WITH",
"(",
"check_option",
"=") ||
3955 TailMatches(
"CREATE",
"OR",
"REPLACE",
"VIEW", MatchAny,
"WITH",
"(",
"check_option",
"="))
3956 COMPLETE_WITH(
"local",
"cascaded");
3958 else if (TailMatches(
"CREATE",
"VIEW", MatchAny,
"WITH",
"(*)") ||
3959 TailMatches(
"CREATE",
"OR",
"REPLACE",
"VIEW", MatchAny,
"WITH",
"(*)"))
3960 COMPLETE_WITH(
"AS");
3962 else if (TailMatches(
"CREATE",
"VIEW", MatchAny,
"WITH",
"(*)",
"AS") ||
3963 TailMatches(
"CREATE",
"OR",
"REPLACE",
"VIEW", MatchAny,
"WITH",
"(*)",
"AS"))
3964 COMPLETE_WITH(
"SELECT");
3967 else if (Matches(
"CREATE",
"MATERIALIZED"))
3968 COMPLETE_WITH(
"VIEW");
3970 else if (Matches(
"CREATE",
"MATERIALIZED",
"VIEW", MatchAny))
3971 COMPLETE_WITH(
"AS");
3973 else if (Matches(
"CREATE",
"MATERIALIZED",
"VIEW", MatchAny,
"AS"))
3974 COMPLETE_WITH(
"SELECT");
3977 else if (Matches(
"CREATE",
"EVENT"))
3978 COMPLETE_WITH(
"TRIGGER");
3980 else if (Matches(
"CREATE",
"EVENT",
"TRIGGER", MatchAny))
3981 COMPLETE_WITH(
"ON");
3983 else if (Matches(
"CREATE",
"EVENT",
"TRIGGER", MatchAny,
"ON"))
3984 COMPLETE_WITH(
"ddl_command_start",
"ddl_command_end",
"login",
3985 "sql_drop",
"table_rewrite");
3992 else if (Matches(
"CREATE",
"EVENT",
"TRIGGER", MatchAny,
"ON", MatchAny))
3995 COMPLETE_WITH(
"WHEN TAG IN (",
"EXECUTE FUNCTION");
3997 COMPLETE_WITH(
"WHEN TAG IN (",
"EXECUTE PROCEDURE");
3999 else if (Matches(
"CREATE",
"EVENT",
"TRIGGER", MatchAnyN,
"WHEN|AND", MatchAny,
"IN",
"(*)"))
4002 COMPLETE_WITH(
"EXECUTE FUNCTION");
4004 COMPLETE_WITH(
"EXECUTE PROCEDURE");
4006 else if (Matches(
"CREATE",
"EVENT",
"TRIGGER", MatchAnyN,
"EXECUTE",
"FUNCTION|PROCEDURE"))
4007 COMPLETE_WITH_VERSIONED_SCHEMA_QUERY(Query_for_list_of_functions);
4010 else if (Matches(
"DEALLOCATE"))
4011 COMPLETE_WITH_QUERY_PLUS(Query_for_list_of_prepared_statements,
4020 else if (Matches(
"DECLARE", MatchAny))
4021 COMPLETE_WITH(
"BINARY",
"ASENSITIVE",
"INSENSITIVE",
"SCROLL",
"NO SCROLL",
4031 else if (Matches(
"DECLARE", MatchAnyN,
"BINARY"))
4032 COMPLETE_WITH(
"ASENSITIVE",
"INSENSITIVE",
"SCROLL",
"NO SCROLL",
"CURSOR");
4033 else if (Matches(
"DECLARE", MatchAnyN,
"ASENSITIVE|INSENSITIVE"))
4034 COMPLETE_WITH(
"SCROLL",
"NO SCROLL",
"CURSOR");
4035 else if (Matches(
"DECLARE", MatchAnyN,
"SCROLL"))
4036 COMPLETE_WITH(
"CURSOR");
4038 else if (Matches(
"DECLARE", MatchAnyN,
"NO"))
4039 COMPLETE_WITH(
"SCROLL");
4045 else if (Matches(
"DECLARE", MatchAnyN,
"CURSOR"))
4046 COMPLETE_WITH(
"WITH HOLD",
"WITHOUT HOLD",
"FOR");
4048 else if (Matches(
"DECLARE", MatchAnyN,
"CURSOR",
"WITH|WITHOUT"))
4049 COMPLETE_WITH(
"HOLD");
4051 else if (Matches(
"DECLARE", MatchAnyN,
"CURSOR",
"WITH|WITHOUT",
"HOLD"))
4052 COMPLETE_WITH(
"FOR");
4056 else if (Matches(
"DELETE"))
4057 COMPLETE_WITH(
"FROM");
4059 else if (TailMatches(
"DELETE",
"FROM"))
4060 COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_updatables);
4062 else if (TailMatches(
"DELETE",
"FROM", MatchAny))
4063 COMPLETE_WITH(
"USING",
"WHERE");
4067 else if (Matches(
"DISCARD"))
4068 COMPLETE_WITH(
"ALL",
"PLANS",
"SEQUENCES",
"TEMP");
4071 else if (Matches(
"DO"))
4072 COMPLETE_WITH(
"LANGUAGE");
4076 else if (Matches(
"DROP",
4077 "COLLATION|CONVERSION|DOMAIN|EXTENSION|LANGUAGE|PUBLICATION|SCHEMA|SEQUENCE|SERVER|SUBSCRIPTION|STATISTICS|TABLE|TYPE|VIEW",
4079 Matches(
"DROP",
"ACCESS",
"METHOD", MatchAny) ||
4080 Matches(
"DROP",
"EVENT",
"TRIGGER", MatchAny) ||
4081 Matches(
"DROP",
"FOREIGN",
"DATA",
"WRAPPER", MatchAny) ||
4082 Matches(
"DROP",
"FOREIGN",
"TABLE", MatchAny) ||
4083 Matches(
"DROP",
"TEXT",
"SEARCH",
"CONFIGURATION|DICTIONARY|PARSER|TEMPLATE", MatchAny))
4084 COMPLETE_WITH(
"CASCADE",
"RESTRICT");
4085 else if (Matches(
"DROP",
"AGGREGATE|FUNCTION|PROCEDURE|ROUTINE", MatchAny, MatchAny) &&
4086 ends_with(prev_wd,
')'))
4087 COMPLETE_WITH(
"CASCADE",
"RESTRICT");
4090 else if (Matches(
"DROP",
"AGGREGATE|FUNCTION|PROCEDURE|ROUTINE", MatchAny))
4092 else if (Matches(
"DROP",
"AGGREGATE|FUNCTION|PROCEDURE|ROUTINE", MatchAny,
"("))
4093 COMPLETE_WITH_FUNCTION_ARG(prev2_wd);
4094 else if (Matches(
"DROP",
"FOREIGN"))
4095 COMPLETE_WITH(
"DATA WRAPPER",
"TABLE");
4096 else if (Matches(
"DROP",
"DATABASE", MatchAny))
4097 COMPLETE_WITH(
"WITH (");
4098 else if (HeadMatches(
"DROP",
"DATABASE") && (ends_with(prev_wd,
'(')))
4099 COMPLETE_WITH(
"FORCE");
4102 else if (Matches(
"DROP",
"INDEX"))
4103 COMPLETE_WITH_SCHEMA_QUERY_PLUS(Query_for_list_of_indexes,
4105 else if (Matches(
"DROP",
"INDEX",
"CONCURRENTLY"))
4106 COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_indexes);
4107 else if (Matches(
"DROP",
"INDEX", MatchAny))
4108 COMPLETE_WITH(
"CASCADE",
"RESTRICT");
4109 else if (Matches(
"DROP",
"INDEX",
"CONCURRENTLY", MatchAny))
4110 COMPLETE_WITH(
"CASCADE",
"RESTRICT");
4113 else if (Matches(
"DROP",
"MATERIALIZED"))
4114 COMPLETE_WITH(
"VIEW");
4115 else if (Matches(
"DROP",
"MATERIALIZED",
"VIEW"))
4116 COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_matviews);
4117 else if (Matches(
"DROP",
"MATERIALIZED",
"VIEW", MatchAny))
4118 COMPLETE_WITH(
"CASCADE",
"RESTRICT");
4121 else if (Matches(
"DROP",
"OWNED"))
4122 COMPLETE_WITH(
"BY");
4123 else if (Matches(
"DROP",
"OWNED",
"BY"))
4124 COMPLETE_WITH_QUERY(Query_for_list_of_roles);
4125 else if (Matches(
"DROP",
"OWNED",
"BY", MatchAny))
4126 COMPLETE_WITH(
"CASCADE",
"RESTRICT");
4129 else if (Matches(
"DROP",
"TEXT",
"SEARCH"))
4130 COMPLETE_WITH(
"CONFIGURATION",
"DICTIONARY",
"PARSER",
"TEMPLATE");
4133 else if (Matches(
"DROP",
"TRIGGER", MatchAny))
4134 COMPLETE_WITH(
"ON");
4135 else if (Matches(
"DROP",
"TRIGGER", MatchAny,
"ON"))
4137 set_completion_reference(prev2_wd);
4138 COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_tables_for_trigger);
4140 else if (Matches(
"DROP",
"TRIGGER", MatchAny,
"ON", MatchAny))
4141 COMPLETE_WITH(
"CASCADE",
"RESTRICT");
4144 else if (Matches(
"DROP",
"ACCESS"))
4145 COMPLETE_WITH(
"METHOD");
4146 else if (Matches(
"DROP",
"ACCESS",
"METHOD"))
4147 COMPLETE_WITH_QUERY(Query_for_list_of_access_methods);
4150 else if (Matches(
"DROP",
"EVENT"))
4151 COMPLETE_WITH(
"TRIGGER");
4152 else if (Matches(
"DROP",
"EVENT",
"TRIGGER"))
4153 COMPLETE_WITH_QUERY(Query_for_list_of_event_triggers);
4156 else if (Matches(
"DROP",
"POLICY"))
4157 COMPLETE_WITH_QUERY(Query_for_list_of_policies);
4159 else if (Matches(
"DROP",
"POLICY", MatchAny))
4160 COMPLETE_WITH(
"ON");
4162 else if (Matches(
"DROP",
"POLICY", MatchAny,
"ON"))
4164 set_completion_reference(prev2_wd);
4165 COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_tables_for_policy);
4167 else if (Matches(
"DROP",
"POLICY", MatchAny,
"ON", MatchAny))
4168 COMPLETE_WITH(
"CASCADE",
"RESTRICT");
4171 else if (Matches(
"DROP",
"RULE", MatchAny))
4172 COMPLETE_WITH(
"ON");
4173 else if (Matches(
"DROP",
"RULE", MatchAny,
"ON"))
4175 set_completion_reference(prev2_wd);
4176 COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_tables_for_rule);
4178 else if (Matches(
"DROP",
"RULE", MatchAny,
"ON", MatchAny))
4179 COMPLETE_WITH(
"CASCADE",
"RESTRICT");
4182 else if (Matches(
"DROP",
"TRANSFORM"))
4183 COMPLETE_WITH(
"FOR");
4184 else if (Matches(
"DROP",
"TRANSFORM",
"FOR"))
4185 COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_datatypes);
4186 else if (Matches(
"DROP",
"TRANSFORM",
"FOR", MatchAny))
4187 COMPLETE_WITH(
"LANGUAGE");
4188 else if (Matches(
"DROP",
"TRANSFORM",
"FOR", MatchAny,
"LANGUAGE"))
4190 set_completion_reference(prev2_wd);
4191 COMPLETE_WITH_QUERY(Query_for_list_of_languages);
4193 else if (Matches(
"DROP",
"TRANSFORM",
"FOR", MatchAny,
"LANGUAGE", MatchAny))
4194 COMPLETE_WITH(
"CASCADE",
"RESTRICT");
4197 else if (Matches(
"EXECUTE"))
4198 COMPLETE_WITH_QUERY(Query_for_list_of_prepared_statements);
4204 else if (Matches(
"EXPLAIN"))
4205 COMPLETE_WITH(
"SELECT",
"INSERT INTO",
"DELETE FROM",
"UPDATE",
"DECLARE",
4206 "MERGE INTO",
"EXECUTE",
"ANALYZE",
"VERBOSE");
4207 else if (HeadMatches(
"EXPLAIN",
"(*") &&
4208 !HeadMatches(
"EXPLAIN",
"(*)"))
4215 if (ends_with(prev_wd,
'(') || ends_with(prev_wd,
','))
4216 COMPLETE_WITH(
"ANALYZE",
"VERBOSE",
"COSTS",
"SETTINGS",
"GENERIC_PLAN",
4217 "BUFFERS",
"SERIALIZE",
"WAL",
"TIMING",
"SUMMARY",
4218 "MEMORY",
"FORMAT");
4219 else if (TailMatches(
"ANALYZE|VERBOSE|COSTS|SETTINGS|GENERIC_PLAN|BUFFERS|WAL|TIMING|SUMMARY|MEMORY"))
4220 COMPLETE_WITH(
"ON",
"OFF");
4221 else if (TailMatches(
"SERIALIZE"))
4222 COMPLETE_WITH(
"TEXT",
"NONE",
"BINARY");
4223 else if (TailMatches(
"FORMAT"))
4224 COMPLETE_WITH(
"TEXT",
"XML",
"JSON",
"YAML");
4226 else if (Matches(
"EXPLAIN",
"ANALYZE"))
4227 COMPLETE_WITH(
"SELECT",
"INSERT INTO",
"DELETE FROM",
"UPDATE",
"DECLARE",
4228 "MERGE INTO",
"EXECUTE",
"VERBOSE");
4229 else if (Matches(
"EXPLAIN",
"(*)") ||
4230 Matches(
"EXPLAIN",
"VERBOSE") ||
4231 Matches(
"EXPLAIN",
"ANALYZE",
"VERBOSE"))
4232 COMPLETE_WITH(
"SELECT",
"INSERT INTO",
"DELETE FROM",
"UPDATE",
"DECLARE",
4233 "MERGE INTO",
"EXECUTE");
4241 else if (Matches(
"FETCH|MOVE"))
4242 COMPLETE_WITH_QUERY_PLUS(Query_for_list_of_cursors,
4259 else if (Matches(
"FETCH|MOVE",
"BACKWARD|FORWARD"))
4260 COMPLETE_WITH_QUERY_PLUS(Query_for_list_of_cursors,
4270 else if (Matches(
"FETCH|MOVE",
"ABSOLUTE|BACKWARD|FORWARD|RELATIVE",
4271 MatchAnyExcept(
"FROM|IN")) ||
4272 Matches(
"FETCH|MOVE",
"ALL|NEXT|PRIOR|FIRST|LAST"))
4273 COMPLETE_WITH_QUERY_PLUS(Query_for_list_of_cursors,
4277 else if (Matches(
"FETCH|MOVE", MatchAnyN,
"FROM|IN"))
4278 COMPLETE_WITH_QUERY(Query_for_list_of_cursors);
4282 else if (TailMatches(
"FOREIGN",
"DATA",
"WRAPPER") &&
4283 !TailMatches(
"CREATE", MatchAny, MatchAny, MatchAny))
4284 COMPLETE_WITH_QUERY(Query_for_list_of_fdws);
4286 else if (Matches(
"CREATE",
"SERVER", MatchAnyN,
"FOREIGN",
"DATA",
"WRAPPER", MatchAny))
4287 COMPLETE_WITH(
"OPTIONS");
4290 else if (TailMatches(
"FOREIGN",
"TABLE") &&
4291 !TailMatches(
"CREATE", MatchAny, MatchAny))
4292 COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_foreign_tables);
4295 else if (TailMatches(
"FOREIGN",
"SERVER"))
4296 COMPLETE_WITH_QUERY(Query_for_list_of_servers);
4303 else if (TailMatches(
"GRANT|REVOKE") ||
4304 TailMatches(
"REVOKE",
"ADMIN|GRANT|INHERIT|SET",
"OPTION",
"FOR"))
4310 if (HeadMatches(
"ALTER",
"DEFAULT",
"PRIVILEGES"))
4312 if (TailMatches(
"GRANT") ||
4313 TailMatches(
"REVOKE",
"GRANT",
"OPTION",
"FOR"))
4314 COMPLETE_WITH(
"SELECT",
"INSERT",
"UPDATE",
4315 "DELETE",
"TRUNCATE",
"REFERENCES",
"TRIGGER",
4316 "CREATE",
"EXECUTE",
"USAGE",
"MAINTAIN",
"ALL");
4317 else if (TailMatches(
"REVOKE"))
4318 COMPLETE_WITH(
"SELECT",
"INSERT",
"UPDATE",
4319 "DELETE",
"TRUNCATE",
"REFERENCES",
"TRIGGER",
4320 "CREATE",
"EXECUTE",
"USAGE",
"MAINTAIN",
"ALL",
4321 "GRANT OPTION FOR");
4323 else if (TailMatches(
"GRANT"))
4324 COMPLETE_WITH_QUERY_PLUS(Query_for_list_of_roles,
4325 Privilege_options_of_grant_and_revoke);
4326 else if (TailMatches(
"REVOKE"))
4327 COMPLETE_WITH_QUERY_PLUS(Query_for_list_of_roles,
4328 Privilege_options_of_grant_and_revoke,
4331 "INHERIT OPTION FOR",
4333 else if (TailMatches(
"REVOKE",
"GRANT",
"OPTION",
"FOR"))
4334 COMPLETE_WITH(Privilege_options_of_grant_and_revoke);
4335 else if (TailMatches(
"REVOKE",
"ADMIN|INHERIT|SET",
"OPTION",
"FOR"))
4336 COMPLETE_WITH_QUERY(Query_for_list_of_roles);
4339 else if (TailMatches(
"GRANT|REVOKE",
"ALTER") ||
4340 TailMatches(
"REVOKE",
"GRANT",
"OPTION",
"FOR",
"ALTER"))
4341 COMPLETE_WITH(
"SYSTEM");
4343 else if (TailMatches(
"REVOKE",
"SET"))
4344 COMPLETE_WITH(
"ON PARAMETER",
"OPTION FOR");
4345 else if (TailMatches(
"GRANT",
"SET") ||
4346 TailMatches(
"REVOKE",
"GRANT",
"OPTION",
"FOR",
"SET") ||
4347 TailMatches(
"GRANT|REVOKE",
"ALTER",
"SYSTEM") ||
4348 TailMatches(
"REVOKE",
"GRANT",
"OPTION",
"FOR",
"ALTER",
"SYSTEM"))
4349 COMPLETE_WITH(
"ON PARAMETER");
4351 else if (TailMatches(
"GRANT|REVOKE", MatchAny,
"ON",
"PARAMETER") ||
4352 TailMatches(
"GRANT|REVOKE", MatchAny, MatchAny,
"ON",
"PARAMETER") ||
4353 TailMatches(
"REVOKE",
"GRANT",
"OPTION",
"FOR", MatchAny,
"ON",
"PARAMETER") ||
4354 TailMatches(
"REVOKE",
"GRANT",
"OPTION",
"FOR", MatchAny, MatchAny,
"ON",
"PARAMETER"))
4355 COMPLETE_WITH_QUERY_VERBATIM(Query_for_list_of_alter_system_set_vars);
4357 else if (TailMatches(
"GRANT", MatchAny,
"ON",
"PARAMETER", MatchAny) ||
4358 TailMatches(
"GRANT", MatchAny, MatchAny,
"ON",
"PARAMETER", MatchAny))
4359 COMPLETE_WITH(
"TO");
4361 else if (TailMatches(
"REVOKE", MatchAny,
"ON",
"PARAMETER", MatchAny) ||
4362 TailMatches(
"REVOKE", MatchAny, MatchAny,
"ON",
"PARAMETER", MatchAny) ||
4363 TailMatches(
"REVOKE",
"GRANT",
"OPTION",
"FOR", MatchAny,
"ON",
"PARAMETER", MatchAny) ||
4364 TailMatches(
"REVOKE",
"GRANT",
"OPTION",
"FOR", MatchAny, MatchAny,
"ON",
"PARAMETER", MatchAny))
4365 COMPLETE_WITH(
"FROM");
4371 else if (TailMatches(
"GRANT|REVOKE", MatchAny) ||
4372 TailMatches(
"REVOKE",
"GRANT",
"OPTION",
"FOR", MatchAny))
4374 if (TailMatches(
"SELECT|INSERT|UPDATE|DELETE|TRUNCATE|REFERENCES|TRIGGER|CREATE|CONNECT|TEMPORARY|TEMP|EXECUTE|USAGE|MAINTAIN|ALL"))
4375 COMPLETE_WITH(
"ON");
4376 else if (TailMatches(
"GRANT", MatchAny))
4377 COMPLETE_WITH(
"TO");
4379 COMPLETE_WITH(
"FROM");
4389 else if (TailMatches(
"GRANT|REVOKE", MatchAny,
"ON") ||
4390 TailMatches(
"REVOKE",
"GRANT",
"OPTION",
"FOR", MatchAny,
"ON"))
4396 if (HeadMatches(
"ALTER",
"DEFAULT",
"PRIVILEGES"))
4397 COMPLETE_WITH(
"TABLES",
"SEQUENCES",
"FUNCTIONS",
"PROCEDURES",
"ROUTINES",
"TYPES",
"SCHEMAS");
4399 COMPLETE_WITH_SCHEMA_QUERY_PLUS(Query_for_list_of_grantables,
4400 "ALL FUNCTIONS IN SCHEMA",
4401 "ALL PROCEDURES IN SCHEMA",
4402 "ALL ROUTINES IN SCHEMA",
4403 "ALL SEQUENCES IN SCHEMA",
4404 "ALL TABLES IN SCHEMA",
4407 "FOREIGN DATA WRAPPER",
4421 else if (TailMatches(
"GRANT|REVOKE", MatchAny,
"ON",
"ALL") ||
4422 TailMatches(
"REVOKE",
"GRANT",
"OPTION",
"FOR", MatchAny,
"ON",
"ALL"))
4423 COMPLETE_WITH(
"FUNCTIONS IN SCHEMA",
4424 "PROCEDURES IN SCHEMA",
4425 "ROUTINES IN SCHEMA",
4426 "SEQUENCES IN SCHEMA",
4427 "TABLES IN SCHEMA");
4428 else if (TailMatches(
"GRANT|REVOKE", MatchAny,
"ON",
"FOREIGN") ||
4429 TailMatches(
"REVOKE",
"GRANT",
"OPTION",
"FOR", MatchAny,
"ON",
"FOREIGN"))
4430 COMPLETE_WITH(
"DATA WRAPPER",
"SERVER");
4438 else if (TailMatches(
"GRANT|REVOKE", MatchAny,
"ON", MatchAny) ||
4439 TailMatches(
"REVOKE",
"GRANT",
"OPTION",
"FOR", MatchAny,
"ON", MatchAny))
4441 if (TailMatches(
"DATABASE"))
4442 COMPLETE_WITH_QUERY(Query_for_list_of_databases);
4443 else if (TailMatches(
"DOMAIN"))
4444 COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_domains);
4445 else if (TailMatches(
"FUNCTION"))
4446 COMPLETE_WITH_VERSIONED_SCHEMA_QUERY(Query_for_list_of_functions);
4447 else if (TailMatches(
"LANGUAGE"))
4448 COMPLETE_WITH_QUERY(Query_for_list_of_languages);
4449 else if (TailMatches(
"PROCEDURE"))
4450 COMPLETE_WITH_VERSIONED_SCHEMA_QUERY(Query_for_list_of_procedures);
4451 else if (TailMatches(
"ROUTINE"))
4452 COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_routines);
4453 else if (TailMatches(
"SCHEMA"))
4454 COMPLETE_WITH_QUERY(Query_for_list_of_schemas);
4455 else if (TailMatches(
"SEQUENCE"))
4456 COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_sequences);
4457 else if (TailMatches(
"TABLE"))
4458 COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_grantables);
4459 else if (TailMatches(
"TABLESPACE"))
4460 COMPLETE_WITH_QUERY(Query_for_list_of_tablespaces);
4461 else if (TailMatches(
"TYPE"))
4462 COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_datatypes);
4463 else if (TailMatches(
"GRANT", MatchAny, MatchAny, MatchAny))
4464 COMPLETE_WITH(
"TO");
4466 COMPLETE_WITH(
"FROM");
4473 else if (Matches(
"GRANT", MatchAnyN,
"TO") ||
4474 Matches(
"REVOKE", MatchAnyN,
"FROM"))
4475 COMPLETE_WITH_QUERY_PLUS(Query_for_list_of_roles,
4476 Keywords_for_list_of_grant_roles);
4481 else if (Matches(
"GRANT", MatchAnyN,
"TO", MatchAny))
4482 COMPLETE_WITH(
"WITH ADMIN",
4485 "WITH GRANT OPTION",
4487 else if (Matches(
"GRANT", MatchAnyN,
"TO", MatchAny,
"WITH"))
4488 COMPLETE_WITH(
"ADMIN",
4492 else if (Matches(
"GRANT", MatchAnyN,
"TO", MatchAny,
"WITH",
"ADMIN|INHERIT|SET"))
4493 COMPLETE_WITH(
"OPTION",
"TRUE",
"FALSE");
4494 else if (Matches(
"GRANT", MatchAnyN,
"TO", MatchAny,
"WITH", MatchAny,
"OPTION"))
4495 COMPLETE_WITH(
"GRANTED BY");
4496 else if (Matches(
"GRANT", MatchAnyN,
"TO", MatchAny,
"WITH", MatchAny,
"OPTION",
"GRANTED",
"BY"))
4497 COMPLETE_WITH_QUERY_PLUS(Query_for_list_of_roles,
4498 Keywords_for_list_of_grant_roles);
4500 else if (Matches(
"ALTER",
"DEFAULT",
"PRIVILEGES", MatchAnyN,
"TO|FROM"))
4501 COMPLETE_WITH_QUERY_PLUS(Query_for_list_of_roles,
4502 Keywords_for_list_of_grant_roles);
4504 else if (Matches(
"ALTER",
"DEFAULT",
"PRIVILEGES", MatchAnyN,
"TO", MatchAny))
4505 COMPLETE_WITH(
"WITH GRANT OPTION");
4507 else if (Matches(
"GRANT", MatchAnyN,
"ON", MatchAny, MatchAny))
4508 COMPLETE_WITH(
"TO");
4509 else if (Matches(
"REVOKE", MatchAnyN,
"ON", MatchAny, MatchAny))
4510 COMPLETE_WITH(
"FROM");
4513 else if (TailMatches(
"GRANT|REVOKE", MatchAny,
"ON",
"ALL", MatchAny,
"IN",
"SCHEMA", MatchAny) ||
4514 TailMatches(
"REVOKE",
"GRANT",
"OPTION",
"FOR", MatchAny,
"ON",
"ALL", MatchAny,
"IN",
"SCHEMA", MatchAny))
4516 if (TailMatches(
"GRANT", MatchAny, MatchAny, MatchAny, MatchAny, MatchAny, MatchAny, MatchAny))
4517 COMPLETE_WITH(
"TO");
4519 COMPLETE_WITH(
"FROM");
4523 else if (TailMatches(
"GRANT|REVOKE", MatchAny,
"ON",
"FOREIGN",
"DATA",
"WRAPPER", MatchAny) ||
4524 TailMatches(
"REVOKE",
"GRANT",
"OPTION",
"FOR", MatchAny,
"ON",
"FOREIGN",
"DATA",
"WRAPPER", MatchAny))
4526 if (TailMatches(
"GRANT", MatchAny, MatchAny, MatchAny, MatchAny, MatchAny, MatchAny))
4527 COMPLETE_WITH(
"TO");
4529 COMPLETE_WITH(
"FROM");
4533 else if (TailMatches(
"GRANT|REVOKE", MatchAny,
"ON",
"FOREIGN",
"SERVER", MatchAny) ||
4534 TailMatches(
"REVOKE",
"GRANT",
"OPTION",
"FOR", MatchAny,
"ON",
"FOREIGN",
"SERVER", MatchAny))
4536 if (TailMatches(
"GRANT", MatchAny, MatchAny, MatchAny, MatchAny, MatchAny))
4537 COMPLETE_WITH(
"TO");
4539 COMPLETE_WITH(
"FROM");
4543 else if (TailMatches(
"FROM", MatchAny,
"GROUP"))
4544 COMPLETE_WITH(
"BY");
4547 else if (Matches(
"IMPORT"))
4548 COMPLETE_WITH(
"FOREIGN SCHEMA");
4549 else if (Matches(
"IMPORT",
"FOREIGN"))
4550 COMPLETE_WITH(
"SCHEMA");
4551 else if (Matches(
"IMPORT",
"FOREIGN",
"SCHEMA", MatchAny))
4552 COMPLETE_WITH(
"EXCEPT (",
"FROM SERVER",
"LIMIT TO (");
4553 else if (TailMatches(
"LIMIT",
"TO",
"(*)") ||
4554 TailMatches(
"EXCEPT",
"(*)"))
4555 COMPLETE_WITH(
"FROM SERVER");
4556 else if (TailMatches(
"FROM",
"SERVER", MatchAny))
4557 COMPLETE_WITH(
"INTO");
4558 else if (TailMatches(
"FROM",
"SERVER", MatchAny,
"INTO"))
4559 COMPLETE_WITH_QUERY(Query_for_list_of_schemas);
4560 else if (TailMatches(
"FROM",
"SERVER", MatchAny,
"INTO", MatchAny))
4561 COMPLETE_WITH(
"OPTIONS (");
4565 else if (TailMatches(
"NOT",
"MATCHED",
"THEN",
"INSERT"))
4566 COMPLETE_WITH(
"VALUES",
"(");
4568 else if (TailMatches(
"INSERT"))
4569 COMPLETE_WITH(
"INTO");
4571 else if (TailMatches(
"INSERT",
"INTO"))
4572 COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_updatables);
4574 else if (TailMatches(
"INSERT",
"INTO", MatchAny,
"("))
4575 COMPLETE_WITH_ATTR(prev2_wd);
4581 else if (TailMatches(
"INSERT",
"INTO", MatchAny))
4582 COMPLETE_WITH(
"(",
"DEFAULT VALUES",
"SELECT",
"TABLE",
"VALUES",
"OVERRIDING");
4588 else if (TailMatches(
"INSERT",
"INTO", MatchAny, MatchAny) &&
4589 ends_with(prev_wd,
')'))
4590 COMPLETE_WITH(
"SELECT",
"TABLE",
"VALUES",
"OVERRIDING");
4593 else if (TailMatches(
"OVERRIDING"))
4594 COMPLETE_WITH(
"SYSTEM VALUE",
"USER VALUE");
4597 else if (TailMatches(
"OVERRIDING", MatchAny,
"VALUE"))
4598 COMPLETE_WITH(
"SELECT",
"TABLE",
"VALUES");
4601 else if (TailMatches(
"VALUES") && !TailMatches(
"DEFAULT",
"VALUES"))
4606 else if (Matches(
"LOCK"))
4607 COMPLETE_WITH_SCHEMA_QUERY_PLUS(Query_for_list_of_tables,
4609 else if (Matches(
"LOCK",
"TABLE"))
4610 COMPLETE_WITH_SCHEMA_QUERY_PLUS(Query_for_list_of_tables,
4612 else if (Matches(
"LOCK",
"TABLE",
"ONLY") || Matches(
"LOCK",
"ONLY"))
4613 COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_tables);
4617 else if (Matches(
"LOCK", MatchAnyExcept(
"TABLE|ONLY")) ||
4618 Matches(
"LOCK",
"TABLE", MatchAnyExcept(
"ONLY")) ||
4619 Matches(
"LOCK",
"ONLY", MatchAny) ||
4620 Matches(
"LOCK",
"TABLE",
"ONLY", MatchAny))
4621 COMPLETE_WITH(
"IN",
"NOWAIT");
4624 else if (Matches(
"LOCK", MatchAnyN,
"IN"))
4625 COMPLETE_WITH(
"ACCESS SHARE MODE",
4626 "ROW SHARE MODE",
"ROW EXCLUSIVE MODE",
4627 "SHARE UPDATE EXCLUSIVE MODE",
"SHARE MODE",
4628 "SHARE ROW EXCLUSIVE MODE",
4629 "EXCLUSIVE MODE",
"ACCESS EXCLUSIVE MODE");
4635 else if (Matches(
"LOCK", MatchAnyN,
"IN",
"ACCESS|ROW"))
4636 COMPLETE_WITH(
"EXCLUSIVE MODE",
"SHARE MODE");
4639 else if (Matches(
"LOCK", MatchAnyN,
"IN",
"SHARE"))
4640 COMPLETE_WITH(
"MODE",
"ROW EXCLUSIVE MODE",
4641 "UPDATE EXCLUSIVE MODE");
4644 else if (Matches(
"LOCK", MatchAnyN,
"MODE"))
4645 COMPLETE_WITH(
"NOWAIT");
4648 else if (TailMatches(
"MERGE"))
4649 COMPLETE_WITH(
"INTO");
4650 else if (TailMatches(
"MERGE",
"INTO"))
4651 COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_mergetargets);
4654 else if (TailMatches(
"MERGE",
"INTO", MatchAny))
4655 COMPLETE_WITH(
"USING",
"AS");
4656 else if (TailMatches(
"MERGE",
"INTO", MatchAny,
"AS", MatchAny) ||
4657 TailMatches(
"MERGE",
"INTO", MatchAny, MatchAnyExcept(
"USING|AS")))
4658 COMPLETE_WITH(
"USING");
4664 else if (TailMatches(
"MERGE",
"INTO", MatchAny,
"USING") ||
4665 TailMatches(
"MERGE",
"INTO", MatchAny,
"AS", MatchAny,
"USING") ||
4666 TailMatches(
"MERGE",
"INTO", MatchAny, MatchAny,
"USING"))
4667 COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_selectables);
4673 else if (TailMatches(
"MERGE",
"INTO", MatchAny,
"USING", MatchAny) ||
4674 TailMatches(
"MERGE",
"INTO", MatchAny,
"AS", MatchAny,
"USING", MatchAny) ||
4675 TailMatches(
"MERGE",
"INTO", MatchAny, MatchAny,
"USING", MatchAny))
4676 COMPLETE_WITH(
"AS",
"ON");
4677 else if (TailMatches(
"MERGE",
"INTO", MatchAny,
"USING", MatchAny,
"AS", MatchAny) ||
4678 TailMatches(
"MERGE",
"INTO", MatchAny,
"AS", MatchAny,
"USING", MatchAny,
"AS", MatchAny) ||
4679 TailMatches(
"MERGE",
"INTO", MatchAny, MatchAny,
"USING", MatchAny,
"AS", MatchAny) ||
4680 TailMatches(
"MERGE",
"INTO", MatchAny,
"USING", MatchAny, MatchAnyExcept(
"ON|AS")) ||
4681 TailMatches(
"MERGE",
"INTO", MatchAny,
"AS", MatchAny,
"USING", MatchAny, MatchAnyExcept(
"ON|AS")) ||
4682 TailMatches(
"MERGE",
"INTO", MatchAny, MatchAny,
"USING", MatchAny, MatchAnyExcept(
"ON|AS")))
4683 COMPLETE_WITH(
"ON");
4686 else if (TailMatches(
"INTO", MatchAny,
"USING", MatchAny,
"ON"))
4687 COMPLETE_WITH_ATTR(prev4_wd);
4688 else if (TailMatches(
"INTO", MatchAny,
"AS", MatchAny,
"USING", MatchAny,
"AS", MatchAny,
"ON"))
4689 COMPLETE_WITH_ATTR(prev8_wd);
4690 else if (TailMatches(
"INTO", MatchAny, MatchAny,
"USING", MatchAny, MatchAny,
"ON"))
4691 COMPLETE_WITH_ATTR(prev6_wd);
4698 else if (TailMatches(
"USING", MatchAny,
"ON", MatchAny) ||
4699 TailMatches(
"USING", MatchAny,
"AS", MatchAny,
"ON", MatchAny) ||
4700 TailMatches(
"USING", MatchAny, MatchAny,
"ON", MatchAny) ||
4701 TailMatches(
"USING", MatchAny,
"ON", MatchAny, MatchAnyExcept(
"WHEN"), MatchAnyExcept(
"WHEN")) ||
4702 TailMatches(
"USING", MatchAny,
"AS", MatchAny,
"ON", MatchAny, MatchAnyExcept(
"WHEN"), MatchAnyExcept(
"WHEN")) ||
4703 TailMatches(
"USING", MatchAny, MatchAny,
"ON", MatchAny, MatchAnyExcept(
"WHEN"), MatchAnyExcept(
"WHEN")))
4704 COMPLETE_WITH(
"WHEN MATCHED",
"WHEN NOT MATCHED");
4705 else if (TailMatches(
"USING", MatchAny,
"ON", MatchAny,
"WHEN") ||
4706 TailMatches(
"USING", MatchAny,
"AS", MatchAny,
"ON", MatchAny,
"WHEN") ||
4707 TailMatches(
"USING", MatchAny, MatchAny,
"ON", MatchAny,
"WHEN") ||
4708 TailMatches(
"USING", MatchAny,
"ON", MatchAny, MatchAny, MatchAny,
"WHEN") ||
4709 TailMatches(
"USING", MatchAny,
"AS", MatchAny,
"ON", MatchAny, MatchAny, MatchAny,
"WHEN") ||
4710 TailMatches(
"USING", MatchAny, MatchAny,
"ON", MatchAny, MatchAny, MatchAny,
"WHEN"))
4711 COMPLETE_WITH(
"MATCHED",
"NOT MATCHED");
4717 else if (TailMatches(
"WHEN",
"MATCHED") ||
4718 TailMatches(
"WHEN",
"NOT",
"MATCHED",
"BY",
"SOURCE|TARGET"))
4719 COMPLETE_WITH(
"THEN",
"AND");
4722 else if (TailMatches(
"WHEN",
"NOT",
"MATCHED"))
4723 COMPLETE_WITH(
"BY",
"THEN",
"AND");
4726 else if (TailMatches(
"WHEN",
"NOT",
"MATCHED",
"BY"))
4727 COMPLETE_WITH(
"SOURCE",
"TARGET");
4733 else if (TailMatches(
"WHEN",
"MATCHED",
"THEN") ||
4734 TailMatches(
"WHEN",
"NOT",
"MATCHED",
"BY",
"SOURCE",
"THEN"))
4735 COMPLETE_WITH(
"UPDATE SET",
"DELETE",
"DO NOTHING");
4740 else if (TailMatches(
"WHEN",
"NOT",
"MATCHED",
"THEN") ||
4741 TailMatches(
"WHEN",
"NOT",
"MATCHED",
"BY",
"TARGET",
"THEN"))
4742 COMPLETE_WITH(
"INSERT",
"DO NOTHING");
4745 else if (TailMatches(
"NOTIFY"))
4746 COMPLETE_WITH_QUERY(Query_for_list_of_channels);
4749 else if (TailMatches(
"OPTIONS"))
4753 else if (TailMatches(
"OWNER",
"TO"))
4754 COMPLETE_WITH_QUERY_PLUS(Query_for_list_of_roles,
4755 Keywords_for_list_of_owner_roles);
4758 else if (TailMatches(
"FROM", MatchAny,
"ORDER"))
4759 COMPLETE_WITH(
"BY");
4760 else if (TailMatches(
"FROM", MatchAny,
"ORDER",
"BY"))
4761 COMPLETE_WITH_ATTR(prev3_wd);
4764 else if (Matches(
"PREPARE", MatchAny,
"AS"))
4765 COMPLETE_WITH(
"SELECT",
"UPDATE",
"INSERT INTO",
"DELETE FROM");
4773 else if (Matches(
"REASSIGN"))
4774 COMPLETE_WITH(
"OWNED BY");
4775 else if (Matches(
"REASSIGN",
"OWNED"))
4776 COMPLETE_WITH(
"BY");
4777 else if (Matches(
"REASSIGN",
"OWNED",
"BY"))
4778 COMPLETE_WITH_QUERY(Query_for_list_of_roles);
4779 else if (Matches(
"REASSIGN",
"OWNED",
"BY", MatchAny))
4780 COMPLETE_WITH(
"TO");
4781 else if (Matches(
"REASSIGN",
"OWNED",
"BY", MatchAny,
"TO"))
4782 COMPLETE_WITH_QUERY(Query_for_list_of_roles);
4785 else if (Matches(
"REFRESH"))
4786 COMPLETE_WITH(
"MATERIALIZED VIEW");
4787 else if (Matches(
"REFRESH",
"MATERIALIZED"))
4788 COMPLETE_WITH(
"VIEW");
4789 else if (Matches(
"REFRESH",
"MATERIALIZED",
"VIEW"))
4790 COMPLETE_WITH_SCHEMA_QUERY_PLUS(Query_for_list_of_matviews,
4792 else if (Matches(
"REFRESH",
"MATERIALIZED",
"VIEW",
"CONCURRENTLY"))
4793 COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_matviews);
4794 else if (Matches(
"REFRESH",
"MATERIALIZED",
"VIEW", MatchAny))
4795 COMPLETE_WITH(
"WITH");
4796 else if (Matches(
"REFRESH",
"MATERIALIZED",
"VIEW",
"CONCURRENTLY", MatchAny))
4797 COMPLETE_WITH(
"WITH");
4798 else if (Matches(
"REFRESH",
"MATERIALIZED",
"VIEW", MatchAny,
"WITH"))
4799 COMPLETE_WITH(
"NO DATA",
"DATA");
4800 else if (Matches(
"REFRESH",
"MATERIALIZED",
"VIEW",
"CONCURRENTLY", MatchAny,
"WITH"))
4801 COMPLETE_WITH(
"NO DATA",
"DATA");
4802 else if (Matches(
"REFRESH",
"MATERIALIZED",
"VIEW", MatchAny,
"WITH",
"NO"))
4803 COMPLETE_WITH(
"DATA");
4804 else if (Matches(
"REFRESH",
"MATERIALIZED",
"VIEW",
"CONCURRENTLY", MatchAny,
"WITH",
"NO"))
4805 COMPLETE_WITH(
"DATA");
4808 else if (Matches(
"REINDEX") ||
4809 Matches(
"REINDEX",
"(*)"))
4810 COMPLETE_WITH(
"TABLE",
"INDEX",
"SYSTEM",
"SCHEMA",
"DATABASE");
4811 else if (Matches(
"REINDEX",
"TABLE") ||
4812 Matches(
"REINDEX",
"(*)",
"TABLE"))
4813 COMPLETE_WITH_SCHEMA_QUERY_PLUS(Query_for_list_of_indexables,
4815 else if (Matches(
"REINDEX",
"INDEX") ||
4816 Matches(
"REINDEX",
"(*)",
"INDEX"))
4817 COMPLETE_WITH_SCHEMA_QUERY_PLUS(Query_for_list_of_indexes,
4819 else if (Matches(
"REINDEX",
"SCHEMA") ||
4820 Matches(
"REINDEX",
"(*)",
"SCHEMA"))
4821 COMPLETE_WITH_QUERY_PLUS(Query_for_list_of_schemas,
4823 else if (Matches(
"REINDEX",
"SYSTEM|DATABASE") ||
4824 Matches(
"REINDEX",
"(*)",
"SYSTEM|DATABASE"))
4825 COMPLETE_WITH_QUERY_PLUS(Query_for_list_of_databases,
4827 else if (Matches(
"REINDEX",
"TABLE",
"CONCURRENTLY") ||
4828 Matches(
"REINDEX",
"(*)",
"TABLE",
"CONCURRENTLY"))
4829 COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_indexables);
4830 else if (Matches(
"REINDEX",
"INDEX",
"CONCURRENTLY") ||
4831 Matches(
"REINDEX",
"(*)",
"INDEX",
"CONCURRENTLY"))
4832 COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_indexes);
4833 else if (Matches(
"REINDEX",
"SCHEMA",
"CONCURRENTLY") ||
4834 Matches(
"REINDEX",
"(*)",
"SCHEMA",
"CONCURRENTLY"))
4835 COMPLETE_WITH_QUERY(Query_for_list_of_schemas);
4836 else if (Matches(
"REINDEX",
"SYSTEM|DATABASE",
"CONCURRENTLY") ||
4837 Matches(
"REINDEX",
"(*)",
"SYSTEM|DATABASE",
"CONCURRENTLY"))
4838 COMPLETE_WITH_QUERY(Query_for_list_of_databases);
4839 else if (HeadMatches(
"REINDEX",
"(*") &&
4840 !HeadMatches(
"REINDEX",
"(*)"))
4847 if (ends_with(prev_wd,
'(') || ends_with(prev_wd,
','))
4848 COMPLETE_WITH(
"CONCURRENTLY",
"TABLESPACE",
"VERBOSE");
4849 else if (TailMatches(
"TABLESPACE"))
4850 COMPLETE_WITH_QUERY(Query_for_list_of_tablespaces);
4854 else if (Matches(
"SECURITY"))
4855 COMPLETE_WITH(
"LABEL");
4856 else if (Matches(
"SECURITY",
"LABEL"))
4857 COMPLETE_WITH(
"ON",
"FOR");
4858 else if (Matches(
"SECURITY",
"LABEL",
"FOR", MatchAny))
4859 COMPLETE_WITH(
"ON");
4860 else if (Matches(
"SECURITY",
"LABEL",
"ON") ||
4861 Matches(
"SECURITY",
"LABEL",
"FOR", MatchAny,
"ON"))
4862 COMPLETE_WITH(
"TABLE",
"COLUMN",
"AGGREGATE",
"DATABASE",
"DOMAIN",
4863 "EVENT TRIGGER",
"FOREIGN TABLE",
"FUNCTION",
4864 "LARGE OBJECT",
"MATERIALIZED VIEW",
"LANGUAGE",
4865 "PUBLICATION",
"PROCEDURE",
"ROLE",
"ROUTINE",
"SCHEMA",
4866 "SEQUENCE",
"SUBSCRIPTION",
"TABLESPACE",
"TYPE",
"VIEW");
4867 else if (Matches(
"SECURITY",
"LABEL",
"ON", MatchAny, MatchAny))
4868 COMPLETE_WITH(
"IS");
4875 else if (TailMatches(
"SET|RESET") && !TailMatches(
"UPDATE", MatchAny,
"SET"))
4876 COMPLETE_WITH_QUERY_VERBATIM_PLUS(Query_for_list_of_set_vars,
4883 else if (Matches(
"SHOW"))
4884 COMPLETE_WITH_QUERY_VERBATIM_PLUS(Query_for_list_of_show_vars,
4885 "SESSION AUTHORIZATION",
4887 else if (Matches(
"SHOW",
"SESSION"))
4888 COMPLETE_WITH(
"AUTHORIZATION");
4890 else if (Matches(
"SET",
"TRANSACTION"))
4891 COMPLETE_WITH(
"SNAPSHOT",
"ISOLATION LEVEL",
"READ",
"DEFERRABLE",
"NOT DEFERRABLE");
4892 else if (Matches(
"BEGIN|START",
"TRANSACTION") ||
4893 Matches(
"BEGIN",
"WORK") ||
4895 Matches(
"SET",
"SESSION",
"CHARACTERISTICS",
"AS",
"TRANSACTION"))
4896 COMPLETE_WITH(
"ISOLATION LEVEL",
"READ",
"DEFERRABLE",
"NOT DEFERRABLE");
4897 else if (Matches(
"SET|BEGIN|START",
"TRANSACTION|WORK",
"NOT") ||
4898 Matches(
"BEGIN",
"NOT") ||
4899 Matches(
"SET",
"SESSION",
"CHARACTERISTICS",
"AS",
"TRANSACTION",
"NOT"))
4900 COMPLETE_WITH(
"DEFERRABLE");
4901 else if (Matches(
"SET|BEGIN|START",
"TRANSACTION|WORK",
"ISOLATION") ||
4902 Matches(
"BEGIN",
"ISOLATION") ||
4903 Matches(
"SET",
"SESSION",
"CHARACTERISTICS",
"AS",
"TRANSACTION",
"ISOLATION"))
4904 COMPLETE_WITH(
"LEVEL");
4905 else if (Matches(
"SET|BEGIN|START",
"TRANSACTION|WORK",
"ISOLATION",
"LEVEL") ||
4906 Matches(
"BEGIN",
"ISOLATION",
"LEVEL") ||
4907 Matches(
"SET",
"SESSION",
"CHARACTERISTICS",
"AS",
"TRANSACTION",
"ISOLATION",
"LEVEL"))
4908 COMPLETE_WITH(
"READ",
"REPEATABLE READ",
"SERIALIZABLE");
4909 else if (Matches(
"SET|BEGIN|START",
"TRANSACTION|WORK",
"ISOLATION",
"LEVEL",
"READ") ||
4910 Matches(
"BEGIN",
"ISOLATION",
"LEVEL",
"READ") ||
4911 Matches(
"SET",
"SESSION",
"CHARACTERISTICS",
"AS",
"TRANSACTION",
"ISOLATION",
"LEVEL",
"READ"))
4912 COMPLETE_WITH(
"UNCOMMITTED",
"COMMITTED");
4913 else if (Matches(
"SET|BEGIN|START",
"TRANSACTION|WORK",
"ISOLATION",
"LEVEL",
"REPEATABLE") ||
4914 Matches(
"BEGIN",
"ISOLATION",
"LEVEL",
"REPEATABLE") ||
4915 Matches(
"SET",
"SESSION",
"CHARACTERISTICS",
"AS",
"TRANSACTION",
"ISOLATION",
"LEVEL",
"REPEATABLE"))
4916 COMPLETE_WITH(
"READ");
4917 else if (Matches(
"SET|BEGIN|START",
"TRANSACTION|WORK",
"READ") ||
4918 Matches(
"BEGIN",
"READ") ||
4919 Matches(
"SET",
"SESSION",
"CHARACTERISTICS",
"AS",
"TRANSACTION",
"READ"))
4920 COMPLETE_WITH(
"ONLY",
"WRITE");
4922 else if (Matches(
"SET",
"CONSTRAINTS"))
4923 COMPLETE_WITH_SCHEMA_QUERY_PLUS(Query_for_list_of_constraints_with_schema,
4926 else if (Matches(
"SET",
"CONSTRAINTS", MatchAny))
4927 COMPLETE_WITH(
"DEFERRED",
"IMMEDIATE");
4929 else if (Matches(
"SET",
"ROLE"))
4930 COMPLETE_WITH_QUERY(Query_for_list_of_roles);
4932 else if (Matches(
"SET",
"SESSION"))
4933 COMPLETE_WITH(
"AUTHORIZATION",
"CHARACTERISTICS AS TRANSACTION");
4935 else if (Matches(
"SET",
"SESSION",
"AUTHORIZATION"))
4936 COMPLETE_WITH_QUERY_PLUS(Query_for_list_of_roles,
4939 else if (Matches(
"RESET",
"SESSION"))
4940 COMPLETE_WITH(
"AUTHORIZATION");
4942 else if (Matches(
"SET", MatchAny))
4943 COMPLETE_WITH(
"TO");
4949 else if (Matches(
"ALTER",
"DATABASE|FUNCTION|PROCEDURE|ROLE|ROUTINE|USER", MatchAnyN,
"SET", MatchAnyExcept(
"SCHEMA")))
4950 COMPLETE_WITH(
"FROM CURRENT",
"TO");
4956 else if (TailMatches(
"SET", MatchAny,
"TO|=") &&
4957 !TailMatches(
"UPDATE", MatchAny,
"SET", MatchAny,
"TO|="))
4960 if (TailMatches(
"DateStyle",
"TO|="))
4961 COMPLETE_WITH(
"ISO",
"SQL",
"Postgres",
"German",
4962 "YMD",
"DMY",
"MDY",
4963 "US",
"European",
"NonEuropean",
4965 else if (TailMatches(
"search_path",
"TO|="))
4968 COMPLETE_WITH_QUERY_PLUS(Query_for_list_of_schemas
4969 " AND nspname NOT LIKE E'pg\\\\_toast%%'"
4970 " AND nspname NOT LIKE E'pg\\\\_temp%%'",
4973 else if (TailMatches(
"TimeZone",
"TO|="))
4974 COMPLETE_WITH_TIMEZONE_NAME();
4978 char *guctype = get_guctype(prev2_wd);
4987 if (strcmp(guctype,
"enum") == 0)
4989 set_completion_reference_verbatim(prev2_wd);
4990 COMPLETE_WITH_QUERY_PLUS(Query_for_values_of_enum_GUC,
4993 else if (strcmp(guctype,
"bool") == 0)
4994 COMPLETE_WITH(
"on",
"off",
"true",
"false",
"yes",
"no",
4995 "1",
"0",
"DEFAULT");
4997 COMPLETE_WITH(
"DEFAULT");
5005 else if (Matches(
"START"))
5006 COMPLETE_WITH(
"TRANSACTION");
5009 else if (Matches(
"TABLE"))
5010 COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_selectables);
5013 else if (TailMatches(
"TABLESAMPLE"))
5014 COMPLETE_WITH_QUERY(Query_for_list_of_tablesample_methods);
5015 else if (TailMatches(
"TABLESAMPLE", MatchAny))
5019 else if (Matches(
"TRUNCATE"))
5020 COMPLETE_WITH_SCHEMA_QUERY_PLUS(Query_for_list_of_truncatables,
5022 else if (Matches(
"TRUNCATE",
"TABLE"))
5023 COMPLETE_WITH_SCHEMA_QUERY_PLUS(Query_for_list_of_truncatables,
5025 else if (Matches(
"TRUNCATE", MatchAnyN,
"ONLY"))
5026 COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_truncatables);
5027 else if (Matches(
"TRUNCATE", MatchAny) ||
5028 Matches(
"TRUNCATE",
"TABLE|ONLY", MatchAny) ||
5029 Matches(
"TRUNCATE",
"TABLE",
"ONLY", MatchAny))
5030 COMPLETE_WITH(
"RESTART IDENTITY",
"CONTINUE IDENTITY",
"CASCADE",
"RESTRICT");
5031 else if (Matches(
"TRUNCATE", MatchAnyN,
"IDENTITY"))
5032 COMPLETE_WITH(
"CASCADE",
"RESTRICT");
5035 else if (Matches(
"UNLISTEN"))
5036 COMPLETE_WITH_QUERY_PLUS(Query_for_list_of_channels,
"*");
5040 else if (TailMatches(
"UPDATE"))
5041 COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_updatables);
5043 else if (TailMatches(
"UPDATE", MatchAny))
5044 COMPLETE_WITH(
"SET");
5046 else if (TailMatches(
"UPDATE", MatchAny,
"SET"))
5047 COMPLETE_WITH_ATTR(prev2_wd);
5049 else if (TailMatches(
"UPDATE", MatchAny,
"SET", MatchAnyExcept(
"*=")))
5053 else if (Matches(
"ALTER|CREATE|DROP",
"USER",
"MAPPING"))
5054 COMPLETE_WITH(
"FOR");
5055 else if (Matches(
"CREATE",
"USER",
"MAPPING",
"FOR"))
5056 COMPLETE_WITH_QUERY_PLUS(Query_for_list_of_roles,
5061 else if (Matches(
"ALTER|DROP",
"USER",
"MAPPING",
"FOR"))
5062 COMPLETE_WITH_QUERY(Query_for_list_of_user_mappings);
5063 else if (Matches(
"CREATE|ALTER|DROP",
"USER",
"MAPPING",
"FOR", MatchAny))
5064 COMPLETE_WITH(
"SERVER");
5065 else if (Matches(
"CREATE|ALTER",
"USER",
"MAPPING",
"FOR", MatchAny,
"SERVER", MatchAny))
5066 COMPLETE_WITH(
"OPTIONS");
5072 else if (Matches(
"VACUUM"))
5073 COMPLETE_WITH_SCHEMA_QUERY_PLUS(Query_for_list_of_vacuumables,
5078 else if (Matches(
"VACUUM",
"FULL"))
5079 COMPLETE_WITH_SCHEMA_QUERY_PLUS(Query_for_list_of_vacuumables,
5083 else if (Matches(
"VACUUM",
"FREEZE") ||
5084 Matches(
"VACUUM",
"FULL",
"FREEZE"))
5085 COMPLETE_WITH_SCHEMA_QUERY_PLUS(Query_for_list_of_vacuumables,
5088 else if (Matches(
"VACUUM",
"VERBOSE") ||
5089 Matches(
"VACUUM",
"FULL|FREEZE",
"VERBOSE") ||
5090 Matches(
"VACUUM",
"FULL",
"FREEZE",
"VERBOSE"))
5091 COMPLETE_WITH_SCHEMA_QUERY_PLUS(Query_for_list_of_vacuumables,
5093 else if (HeadMatches(
"VACUUM",
"(*") &&
5094 !HeadMatches(
"VACUUM",
"(*)"))
5101 if (ends_with(prev_wd,
'(') || ends_with(prev_wd,
','))
5102 COMPLETE_WITH(
"FULL",
"FREEZE",
"ANALYZE",
"VERBOSE",
5103 "DISABLE_PAGE_SKIPPING",
"SKIP_LOCKED",
5104 "INDEX_CLEANUP",
"PROCESS_MAIN",
"PROCESS_TOAST",
5105 "TRUNCATE",
"PARALLEL",
"SKIP_DATABASE_STATS",
5106 "ONLY_DATABASE_STATS",
"BUFFER_USAGE_LIMIT");
5107 else if (TailMatches(
"FULL|FREEZE|ANALYZE|VERBOSE|DISABLE_PAGE_SKIPPING|SKIP_LOCKED|PROCESS_MAIN|PROCESS_TOAST|TRUNCATE|SKIP_DATABASE_STATS|ONLY_DATABASE_STATS"))
5108 COMPLETE_WITH(
"ON",
"OFF");
5109 else if (TailMatches(
"INDEX_CLEANUP"))
5110 COMPLETE_WITH(
"AUTO",
"ON",
"OFF");
5112 else if (Matches(
"VACUUM", MatchAnyN,
"("))
5114 COMPLETE_WITH_ATTR(prev2_wd);
5115 else if (HeadMatches(
"VACUUM"))
5116 COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_vacuumables);
5124 else if (Matches(
"WITH"))
5125 COMPLETE_WITH(
"RECURSIVE");
5129 else if (TailMatches(MatchAny,
"WHERE"))
5130 COMPLETE_WITH_ATTR(prev2_wd);
5134 else if (TailMatches(
"FROM") && !Matches(
"COPY|\\copy", MatchAny,
"FROM"))
5135 COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_selectables);
5138 else if (TailMatches(
"JOIN"))
5139 COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_selectables);
5142 else if (TailMatches(
"AT"))
5143 COMPLETE_WITH(
"LOCAL",
"TIME ZONE");
5144 else if (TailMatches(
"AT",
"TIME",
"ZONE"))
5145 COMPLETE_WITH_TIMEZONE_NAME();
5149 else if (TailMatchesCS(
"\\?"))
5150 COMPLETE_WITH_CS(
"commands",
"options",
"variables");
5151 else if (TailMatchesCS(
"\\connect|\\c"))
5154 COMPLETE_WITH_QUERY(Query_for_list_of_databases);
5156 else if (TailMatchesCS(
"\\connect|\\c", MatchAny))
5159 COMPLETE_WITH_QUERY(Query_for_list_of_roles);
5161 else if (TailMatchesCS(
"\\da*"))
5162 COMPLETE_WITH_VERSIONED_SCHEMA_QUERY(Query_for_list_of_aggregates);
5163 else if (TailMatchesCS(
"\\dAc*", MatchAny) ||
5164 TailMatchesCS(
"\\dAf*", MatchAny))
5165 COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_datatypes);
5166 else if (TailMatchesCS(
"\\dAo*", MatchAny) ||
5167 TailMatchesCS(
"\\dAp*", MatchAny))
5168 COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_operator_families);
5169 else if (TailMatchesCS(
"\\dA*"))
5170 COMPLETE_WITH_QUERY(Query_for_list_of_access_methods);
5171 else if (TailMatchesCS(
"\\db*"))
5172 COMPLETE_WITH_QUERY(Query_for_list_of_tablespaces);
5173 else if (TailMatchesCS(
"\\dconfig*"))
5174 COMPLETE_WITH_QUERY_VERBATIM(Query_for_list_of_show_vars);
5175 else if (TailMatchesCS(
"\\dD*"))
5176 COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_domains);
5177 else if (TailMatchesCS(
"\\des*"))
5178 COMPLETE_WITH_QUERY(Query_for_list_of_servers);
5179 else if (TailMatchesCS(
"\\deu*"))
5180 COMPLETE_WITH_QUERY(Query_for_list_of_user_mappings);
5181 else if (TailMatchesCS(
"\\dew*"))
5182 COMPLETE_WITH_QUERY(Query_for_list_of_fdws);
5183 else if (TailMatchesCS(
"\\df*"))
5184 COMPLETE_WITH_VERSIONED_SCHEMA_QUERY(Query_for_list_of_functions);
5185 else if (HeadMatchesCS(
"\\df*"))
5186 COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_datatypes);
5188 else if (TailMatchesCS(
"\\dFd*"))
5189 COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_ts_dictionaries);
5190 else if (TailMatchesCS(
"\\dFp*"))
5191 COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_ts_parsers);
5192 else if (TailMatchesCS(
"\\dFt*"))
5193 COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_ts_templates);
5195 else if (TailMatchesCS(
"\\dF*"))
5196 COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_ts_configurations);
5198 else if (TailMatchesCS(
"\\di*"))
5199 COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_indexes);
5200 else if (TailMatchesCS(
"\\dL*"))
5201 COMPLETE_WITH_QUERY(Query_for_list_of_languages);
5202 else if (TailMatchesCS(
"\\dn*"))
5203 COMPLETE_WITH_QUERY(Query_for_list_of_schemas);
5205 else if (HeadMatchesCS(
"\\do*", MatchAny))
5206 COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_datatypes);
5207 else if (TailMatchesCS(
"\\dp") || TailMatchesCS(
"\\z"))
5208 COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_grantables);
5209 else if (TailMatchesCS(
"\\dPi*"))
5210 COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_partitioned_indexes);
5211 else if (TailMatchesCS(
"\\dPt*"))
5212 COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_partitioned_tables);
5213 else if (TailMatchesCS(
"\\dP*"))
5214 COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_partitioned_relations);
5215 else if (TailMatchesCS(
"\\dRp*"))
5216 COMPLETE_WITH_VERSIONED_QUERY(Query_for_list_of_publications);
5217 else if (TailMatchesCS(
"\\dRs*"))
5218 COMPLETE_WITH_VERSIONED_QUERY(Query_for_list_of_subscriptions);
5219 else if (TailMatchesCS(
"\\ds*"))
5220 COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_sequences);
5221 else if (TailMatchesCS(
"\\dt*"))
5222 COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_tables);
5223 else if (TailMatchesCS(
"\\dT*"))
5224 COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_datatypes);
5225 else if (TailMatchesCS(
"\\du*") ||
5226 TailMatchesCS(
"\\dg*") ||
5227 TailMatchesCS(
"\\drg*"))
5228 COMPLETE_WITH_QUERY(Query_for_list_of_roles);
5229 else if (TailMatchesCS(
"\\dv*"))
5230 COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_views);
5231 else if (TailMatchesCS(
"\\dx*"))
5232 COMPLETE_WITH_QUERY(Query_for_list_of_extensions);
5233 else if (TailMatchesCS(
"\\dX*"))
5234 COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_statistics);
5235 else if (TailMatchesCS(
"\\dm*"))
5236 COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_matviews);
5237 else if (TailMatchesCS(
"\\dE*"))
5238 COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_foreign_tables);
5239 else if (TailMatchesCS(
"\\dy*"))
5240 COMPLETE_WITH_QUERY(Query_for_list_of_event_triggers);
5243 else if (TailMatchesCS(
"\\d*"))
5244 COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_relations);
5246 else if (TailMatchesCS(
"\\ef"))
5247 COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_routines);
5248 else if (TailMatchesCS(
"\\ev"))
5249 COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_views);
5251 else if (TailMatchesCS(
"\\encoding"))
5252 COMPLETE_WITH_QUERY_VERBATIM(Query_for_list_of_encodings);
5253 else if (TailMatchesCS(
"\\h|\\help"))
5254 COMPLETE_WITH_LIST(sql_commands);
5255 else if (TailMatchesCS(
"\\h|\\help", MatchAny))
5257 if (TailMatches(
"DROP"))
5258 matches = rl_completion_matches(
text, drop_command_generator);
5259 else if (TailMatches(
"ALTER"))
5260 matches = rl_completion_matches(
text, alter_command_generator);
5267 else if (TailMatchesCS(
"\\h|\\help", MatchAny, MatchAny))
5269 if (TailMatches(
"CREATE|DROP",
"ACCESS"))
5270 COMPLETE_WITH(
"METHOD");
5271 else if (TailMatches(
"ALTER",
"DEFAULT"))
5272 COMPLETE_WITH(
"PRIVILEGES");
5273 else if (TailMatches(
"CREATE|ALTER|DROP",
"EVENT"))
5274 COMPLETE_WITH(
"TRIGGER");
5275 else if (TailMatches(
"CREATE|ALTER|DROP",
"FOREIGN"))
5276 COMPLETE_WITH(
"DATA WRAPPER",
"TABLE");
5277 else if (TailMatches(
"ALTER",
"LARGE"))
5278 COMPLETE_WITH(
"OBJECT");
5279 else if (TailMatches(
"CREATE|ALTER|DROP",
"MATERIALIZED"))
5280 COMPLETE_WITH(
"VIEW");
5281 else if (TailMatches(
"CREATE|ALTER|DROP",
"TEXT"))
5282 COMPLETE_WITH(
"SEARCH");
5283 else if (TailMatches(
"CREATE|ALTER|DROP",
"USER"))
5284 COMPLETE_WITH(
"MAPPING FOR");
5286 else if (TailMatchesCS(
"\\h|\\help", MatchAny, MatchAny, MatchAny))
5288 if (TailMatches(
"CREATE|ALTER|DROP",
"FOREIGN",
"DATA"))
5289 COMPLETE_WITH(
"WRAPPER");
5290 else if (TailMatches(
"CREATE|ALTER|DROP",
"TEXT",
"SEARCH"))
5291 COMPLETE_WITH(
"CONFIGURATION",
"DICTIONARY",
"PARSER",
"TEMPLATE");
5292 else if (TailMatches(
"CREATE|ALTER|DROP",
"USER",
"MAPPING"))
5293 COMPLETE_WITH(
"FOR");
5295 else if (TailMatchesCS(
"\\l*") && !TailMatchesCS(
"\\lo*"))
5296 COMPLETE_WITH_QUERY(Query_for_list_of_databases);
5297 else if (TailMatchesCS(
"\\password"))
5298 COMPLETE_WITH_QUERY(Query_for_list_of_roles);
5299 else if (TailMatchesCS(
"\\pset"))
5300 COMPLETE_WITH_CS(
"border",
"columns",
"csv_fieldsep",
"expanded",
5301 "fieldsep",
"fieldsep_zero",
"footer",
"format",
5302 "linestyle",
"null",
"numericlocale",
5303 "pager",
"pager_min_lines",
5304 "recordsep",
"recordsep_zero",
5305 "tableattr",
"title",
"tuples_only",
5306 "unicode_border_linestyle",
5307 "unicode_column_linestyle",
5308 "unicode_header_linestyle",
5310 else if (TailMatchesCS(
"\\pset", MatchAny))
5312 if (TailMatchesCS(
"format"))
5313 COMPLETE_WITH_CS(
"aligned",
"asciidoc",
"csv",
"html",
"latex",
5314 "latex-longtable",
"troff-ms",
"unaligned",
5316 else if (TailMatchesCS(
"xheader_width"))
5317 COMPLETE_WITH_CS(
"full",
"column",
"page");
5318 else if (TailMatchesCS(
"linestyle"))
5319 COMPLETE_WITH_CS(
"ascii",
"old-ascii",
"unicode");
5320 else if (TailMatchesCS(
"pager"))
5321 COMPLETE_WITH_CS(
"on",
"off",
"always");
5322 else if (TailMatchesCS(
"unicode_border_linestyle|"
5323 "unicode_column_linestyle|"
5324 "unicode_header_linestyle"))
5325 COMPLETE_WITH_CS(
"single",
"double");
5327 else if (TailMatchesCS(
"\\unset"))
5328 matches = complete_from_variables(
text,
"",
"",
true);
5329 else if (TailMatchesCS(
"\\set"))
5330 matches = complete_from_variables(
text,
"",
"",
false);
5331 else if (TailMatchesCS(
"\\set", MatchAny))
5333 if (TailMatchesCS(
"AUTOCOMMIT|ON_ERROR_STOP|QUIET|SHOW_ALL_RESULTS|"
5334 "SINGLELINE|SINGLESTEP"))
5335 COMPLETE_WITH_CS(
"on",
"off");
5336 else if (TailMatchesCS(
"COMP_KEYWORD_CASE"))
5337 COMPLETE_WITH_CS(
"lower",
"upper",
5338 "preserve-lower",
"preserve-upper");
5339 else if (TailMatchesCS(
"ECHO"))
5340 COMPLETE_WITH_CS(
"errors",
"queries",
"all",
"none");
5341 else if (TailMatchesCS(
"ECHO_HIDDEN"))
5342 COMPLETE_WITH_CS(
"noexec",
"off",
"on");
5343 else if (TailMatchesCS(
"HISTCONTROL"))
5344 COMPLETE_WITH_CS(
"ignorespace",
"ignoredups",
5345 "ignoreboth",
"none");
5346 else if (TailMatchesCS(
"ON_ERROR_ROLLBACK"))
5347 COMPLETE_WITH_CS(
"on",
"off",
"interactive");
5348 else if (TailMatchesCS(
"SHOW_CONTEXT"))
5349 COMPLETE_WITH_CS(
"never",
"errors",
"always");
5350 else if (TailMatchesCS(
"VERBOSITY"))
5351 COMPLETE_WITH_CS(
"default",
"verbose",
"terse",
"sqlstate");
5353 else if (TailMatchesCS(
"\\sf*"))
5354 COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_routines);
5355 else if (TailMatchesCS(
"\\sv*"))
5356 COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_views);
5357 else if (TailMatchesCS(
"\\cd|\\e|\\edit|\\g|\\gx|\\i|\\include|"
5358 "\\ir|\\include_relative|\\o|\\out|"
5359 "\\s|\\w|\\write|\\lo_import"))
5361 completion_charp =
"\\";
5362 completion_force_quote =
false;
5363 matches = rl_completion_matches(
text, complete_from_files);
5392 create_or_drop_command_generator(
const char *
text,
int state,
bits32 excluded)
5394 static int list_index,
5402 string_length = strlen(
text);
5406 while ((
name = words_after_create[list_index++].
name))
5409 !(words_after_create[list_index - 1].flags & excluded))
5410 return pg_strdup_keyword_case(
name,
text);
5421 create_command_generator(
const char *
text,
int state)
5423 return create_or_drop_command_generator(
text,
state, THING_NO_CREATE);
5430 drop_command_generator(
const char *
text,
int state)
5432 return create_or_drop_command_generator(
text,
state, THING_NO_DROP);
5439 alter_command_generator(
const char *
text,
int state)
5441 return create_or_drop_command_generator(
text,
state, THING_NO_ALTER);
5450 complete_from_query(
const char *
text,
int state)
5453 return _complete_from_query(completion_charp, NULL, completion_charpp,
5458 complete_from_versioned_query(
const char *
text,
int state)
5460 const VersionedQuery *vquery = completion_vquery;
5466 if (vquery->query == NULL)
5469 return _complete_from_query(vquery->query, NULL, completion_charpp,
5474 complete_from_schema_query(
const char *
text,
int state)
5477 return _complete_from_query(NULL, completion_squery, completion_charpp,
5482 complete_from_versioned_schema_query(
const char *
text,
int state)
5484 const SchemaQuery *squery = completion_squery;
5490 if (squery->catname == NULL)
5493 return _complete_from_query(NULL, squery, completion_charpp,
5540 _complete_from_query(
const char *simple_query,
5541 const SchemaQuery *schema_query,
5542 const char *
const *keywords,
5546 static int list_index,
5551 static bool non_empty_object;
5552 static bool schemaquoted;
5553 static bool objectquoted;
5564 char *e_object_like;
5571 num_schema_only = 0;
5572 num_query_other = 0;
5585 parse_identifier(
text,
5586 &schemaname, &objectname,
5587 &schemaquoted, &objectquoted);
5591 non_empty_object = (*objectname !=
'\0');
5597 e_object_like = make_like_pattern(objectname);
5600 e_schemaname = escape_string(schemaname);
5602 e_schemaname = NULL;
5604 if (completion_ref_object)
5605 e_ref_object = escape_string(completion_ref_object);
5607 e_ref_object = NULL;
5609 if (completion_ref_schema)
5610 e_ref_schema = escape_string(completion_ref_schema);
5612 e_ref_schema = NULL;
5618 Assert(simple_query == NULL);
5625 if (schemaname == NULL || schema_query->namespace == NULL)
5629 if (schema_query->use_distinct)
5632 "%s, NULL::pg_catalog.text FROM %s",
5633 schema_query->result,
5634 schema_query->catname);
5635 if (schema_query->refnamespace && completion_ref_schema)
5637 ", pg_catalog.pg_namespace nr");
5639 if (schema_query->selcondition)
5641 schema_query->selcondition);
5643 schema_query->result,
5645 if (schema_query->viscondition)
5647 schema_query->viscondition);
5648 if (schema_query->refname)
5650 Assert(completion_ref_object);
5652 schema_query->refname, e_ref_object);
5653 if (schema_query->refnamespace && completion_ref_schema)
5655 " AND %s = nr.oid AND nr.nspname = '%s'",
5656 schema_query->refnamespace,
5658 else if (schema_query->refviscondition)
5661 schema_query->refviscondition);
5671 if (strcmp(schema_query->catname,
5672 "pg_catalog.pg_class c") == 0 &&
5673 strncmp(objectname,
"pg_", 3) != 0)
5676 " AND c.relnamespace <> (SELECT oid FROM"
5677 " pg_catalog.pg_namespace WHERE nspname = 'pg_catalog')");
5684 if (schema_query->namespace)
5687 "SELECT NULL::pg_catalog.text, n.nspname "
5688 "FROM pg_catalog.pg_namespace n "
5689 "WHERE n.nspname LIKE '%s'",
5696 if (strncmp(objectname,
"pg_", 3) != 0)
5698 " AND n.nspname NOT LIKE E'pg\\\\_%'");
5705 schemaquoted = objectquoted;
5712 if (schema_query->use_distinct)
5715 "FROM %s, pg_catalog.pg_namespace n",
5716 schema_query->result,
5717 schema_query->catname);
5718 if (schema_query->refnamespace && completion_ref_schema)
5720 ", pg_catalog.pg_namespace nr");
5722 schema_query->namespace);
5723 if (schema_query->selcondition)
5725 schema_query->selcondition);
5727 schema_query->result,
5731 if (schema_query->refname)
5733 Assert(completion_ref_object);
5735 schema_query->refname, e_ref_object);
5736 if (schema_query->refnamespace && completion_ref_schema)
5738 " AND %s = nr.oid AND nr.nspname = '%s'",
5739 schema_query->refnamespace,
5741 else if (schema_query->refviscondition)
5744 schema_query->refviscondition);
5754 e_ref_object, e_ref_schema);
5759 completion_max_records);
5762 result = exec_query(query_buffer.
data);
5768 free(e_object_like);
5781 const char *item = NULL;
5782 const char *nsp = NULL;
5805 if (non_empty_object)
5807 if (item && !objectquoted && identifier_needs_quotes(item))
5809 if (nsp && !schemaquoted && identifier_needs_quotes(nsp))
5814 if (item == NULL && nsp != NULL)
5819 return requote_identifier(nsp, item, schemaquoted, objectquoted);
5828 if (schema_query && schema_query->keywords)
5830 const char *
const *itemp = schema_query->keywords;
5834 const char *item = *itemp++;
5842 return pg_strdup_keyword_case(item,
text);
5848 const char *
const *itemp = keywords;
5852 const char *item = *itemp++;
5860 return pg_strdup_keyword_case(item,
text);
5871 if (num_schema_only > 0 && num_query_other == 0 && num_keywords == 0)
5872 rl_completion_append_character =
'\0';
5887 set_completion_reference(
const char *
word)
5892 parse_identifier(
word,
5893 &completion_ref_schema, &completion_ref_object,
5894 &schemaquoted, &objectquoted);
5902 set_completion_reference_verbatim(
const char *
word)
5904 completion_ref_schema = NULL;
5915 complete_from_list(
const char *
text,
int state)
5917 static int string_length,
5920 static bool casesensitive;
5924 Assert(completion_charpp != NULL);
5930 string_length = strlen(
text);
5931 casesensitive = completion_case_sensitive;
5935 while ((item = completion_charpp[list_index++]))
5938 if (casesensitive && strncmp(
text, item, string_length) == 0)
5947 if (completion_case_sensitive)
5955 return pg_strdup_keyword_case(item,
text);
5963 if (casesensitive && matches == 0)
5965 casesensitive =
false;
5995 complete_from_const(
const char *
text,
int state)
5997 Assert(completion_charp != NULL);
6000 if (completion_case_sensitive)
6008 return pg_strdup_keyword_case(completion_charp,
text);
6020 append_variable_names(
char ***varnames,
int *nvars,
6021 int *maxvars,
const char *varname,
6022 const char *prefix,
const char *suffix)
6024 if (*nvars >= *maxvars)
6028 ((*maxvars) + 1) *
sizeof(
char *));
6031 (*varnames)[(*nvars)++] =
psprintf(
"%s%s%s", prefix, varname, suffix);
6043 complete_from_variables(
const char *
text,
const char *prefix,
const char *suffix,
6053 varnames = (
char **)
pg_malloc((maxvars + 1) *
sizeof(
char *));
6057 if (need_value && !(ptr->
value))
6059 append_variable_names(&varnames, &nvars, &maxvars, ptr->
name,
6063 varnames[nvars] = NULL;
6064 COMPLETE_WITH_LIST_CS((
const char *
const *) varnames);
6066 for (
i = 0;
i < nvars;
i++)
6088 complete_from_files(
const char *
text,
int state)
6090 #ifdef USE_FILENAME_QUOTING_FUNCTIONS
6107 #ifdef HAVE_RL_COMPLETION_SUPPRESS_QUOTE
6108 rl_completion_suppress_quote = 1;
6113 completion_force_quote =
true;
6115 return rl_filename_completion_function(
text,
state);
6121 static const char *unquoted_text;
6122 char *unquoted_match;
6127 completion_force_quote =
true;
6132 unquoted_text =
strtokx(
text,
"", NULL,
"'", *completion_charp,
6138 unquoted_text =
text;
6142 unquoted_match = rl_filename_completion_function(unquoted_text,
state);
6145 struct stat statbuf;
6146 bool is_dir = (
stat(unquoted_match, &statbuf) == 0 &&
6147 S_ISDIR(statbuf.st_mode) != 0);
6151 '\'', *completion_charp,
6152 completion_force_quote,
6155 free(unquoted_match);
6157 ret = unquoted_match;
6164 if (*ret ==
'\'' && is_dir)
6166 char *retend = ret + strlen(ret) - 1;
6171 rl_completion_append_character =
'\0';
6188 pg_strdup_keyword_case(
const char *s,
const char *ref)
6192 unsigned char first = ref[0];
6201 for (p = ret; *p; p++)
6206 for (p = ret; *p; p++)
6220 escape_string(
const char *
text)
6243 make_like_pattern(
const char *
word)
6247 char *bptr = buffer;
6270 result = escape_string(buffer);
6289 parse_identifier(
const char *
ident,
6290 char **schemaname,
char **objectname,
6291 bool *schemaquoted,
bool *objectquoted)
6293 size_t buflen = strlen(
ident) + 1;
6303 *schemaquoted = *objectquoted =
false;
6309 unsigned char ch = (
unsigned char) *
ident++;
6313 if (inquotes && *
ident ==
'"')
6321 inquotes = !inquotes;
6322 *objectquoted =
true;
6325 else if (ch ==
'.' && !inquotes)
6333 *schemaquoted = *objectquoted;
6334 *objectquoted =
false;
6346 *optr++ = (char) ch;
6361 if (ch >=
'A' && ch <=
'Z')
6363 else if (enc_is_single_byte &&
IS_HIGHBIT_SET(ch) && isupper(ch))
6366 *optr++ = (char) ch;
6371 *schemaname = sname;
6372 *objectname = oname;
6388 requote_identifier(
const char *schemaname,
const char *objectname,
6389 bool quote_schema,
bool quote_object)
6401 buflen += strlen(schemaname) + 1;
6403 quote_schema = identifier_needs_quotes(schemaname);
6407 for (
const char *p = schemaname; *p; p++)
6416 buflen += strlen(objectname);
6418 quote_object = identifier_needs_quotes(objectname);
6422 for (
const char *p = objectname; *p; p++)
6435 for (
const char *p = schemaname; *p; p++)
6449 for (
const char *p = objectname; *p; p++)
6470 identifier_needs_quotes(
const char *
ident)
6477 if (strspn(
ident,
"abcdefghijklmnopqrstuvwxyz0123456789_$") != strlen(
ident))
6503 exec_query(
const char *query)
6520 pg_log_error(
"tab completion query failed: %s\nQuery was:\n%s",
6543 get_previous_words(
int point,
char **buffer,
int *nwords)
6545 char **previous_words;
6548 int words_found = 0;
6562 memcpy(
buf +
i, rl_line_buffer, point);
6569 buf = rl_line_buffer;
6578 previous_words = (
char **)
pg_malloc(point *
sizeof(
char *));
6579 *buffer = outptr = (
char *)
pg_malloc(point * 2);
6586 for (
i = point - 1;
i >= 0;
i--)
6588 if (strchr(WORD_BREAKS,
buf[
i]))
6602 bool inquotes =
false;
6603 int parentheses = 0;
6607 for (
i = point;
i >= 0;
i--)
6609 if (!isspace((
unsigned char)
buf[
i]))
6628 inquotes = !inquotes;
6635 if (--parentheses <= 0)
6638 else if (parentheses == 0 &&
6639 strchr(WORD_BREAKS,
buf[
start - 1]))
6645 previous_words[words_found++] = outptr;
6656 if (
buf != rl_line_buffer)
6659 *nwords = words_found;
6660 return previous_words;
6670 get_guctype(
const char *varname)
6675 char *guctype = NULL;
6677 e_varname = escape_string(varname);
6681 "SELECT vartype FROM pg_catalog.pg_settings "
6682 "WHERE pg_catalog.lower(name) = pg_catalog.lower('%s')",
6685 result = exec_query(query_buffer.
data);
6697 #ifdef USE_FILENAME_QUOTING_FUNCTIONS
6706 quote_file_name(
char *fname,
int match_type,
char *quote_pointer)
6709 struct stat statbuf;
6713 '\'', *completion_charp,
6714 completion_force_quote,
6729 completion_last_char !=
'\'' &&
6730 (match_type != SINGLE_MATCH ||
6731 (quote_pointer && *quote_pointer ==
'\'') ||
6732 stat(fname, &statbuf) != 0 ||
6735 char *
send = s + strlen(s) - 1;
6746 #ifdef HAVE_RL_COMPLETION_SUPPRESS_QUOTE
6747 rl_completion_suppress_quote = 0;
6755 if (quote_pointer && *quote_pointer !=
'\'')
6756 *quote_pointer =
'\0';
6767 dequote_file_name(
char *fname,
int quote_char)
6769 char *unquoted_fname;
6776 if (quote_char ==
'\'')
6778 char *workspace = (
char *)
pg_malloc(strlen(fname) + 2);
6780 workspace[0] = quote_char;
6781 strcpy(workspace + 1, fname);
6782 unquoted_fname =
strtokx(workspace,
"", NULL,
"'", *completion_charp,
6787 unquoted_fname =
strtokx(fname,
"", NULL,
"'", *completion_charp,
6791 if (!unquoted_fname)
6794 unquoted_fname = fname;
bool recognized_connection_string(const char *connstr)
#define IS_HIGHBIT_SET(ch)
#define Assert(condition)
const uint8 ScanKeywordCategories[SCANKEYWORDS_NUM_KEYWORDS]
char * PQerrorMessage(const PGconn *conn)
ConnStatusType PQstatus(const PGconn *conn)
size_t PQescapeStringConn(PGconn *conn, char *to, const char *from, size_t length, int *error)
ExecStatusType PQresultStatus(const PGresult *res)
int PQntuples(const PGresult *res)
PGresult * PQexec(PGconn *conn, const char *query)
char * PQgetvalue(const PGresult *res, int tup_num, int field_num)
int PQgetisnull(const PGresult *res, int tup_num, int field_num)
int PQnfields(const PGresult *res)
int PQmblenBounded(const char *s, int encoding)
void * pg_realloc(void *ptr, size_t size)
char * pg_strdup(const char *in)
void * pg_malloc(size_t size)
PGDLLIMPORT const ScanKeywordList ScanKeywords
#define UNRESERVED_KEYWORD
int ScanKeywordLookup(const char *str, const ScanKeywordList *keywords)
#define pg_log_error(...)
char * pnstrdup(const char *in, Size len)
int pg_strcasecmp(const char *s1, const char *s2)
unsigned char pg_toupper(unsigned char ch)
unsigned char pg_tolower(unsigned char ch)
int pg_strncasecmp(const char *s1, const char *s2, size_t n)
void initPQExpBuffer(PQExpBuffer str)
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
void termPQExpBuffer(PQExpBuffer str)
char * psprintf(const char *fmt,...)
static void word(struct vars *v, int dir, struct state *lp, struct state *rp)
@ PSQL_COMP_CASE_PRESERVE_LOWER
@ PSQL_COMP_CASE_PRESERVE_UPPER
char * quote_if_needed(const char *source, const char *entails_quote, char quote, char escape, bool force_quote, int encoding)
char * strtokx(const char *s, const char *whitespace, const char *delim, const char *quote, char escape, bool e_strings, bool del_quotes, int encoding)
void initialize_readline(void)
PQExpBuffer tab_completion_query_buf
static int32 text_length(Datum str)
int pg_encoding_max_length(int encoding)
#define send(s, buf, len, flags)