| 1 |
/* |
| 2 |
* psql - the PostgreSQL interactive terminal |
| 3 |
* |
| 4 |
* Copyright (c) 2000-2025, PostgreSQL Global Development Group |
| 5 |
* |
| 6 |
* src/bin/psql/tab-complete.in.c |
| 7 |
* |
| 8 |
* Note: this will compile and work as-is if SWITCH_CONVERSION_APPLIED |
| 9 |
* is not defined. However, the expected usage is that it's first run |
| 10 |
* through gen_tabcomplete.pl, which will #define that symbol, fill in the |
| 11 |
* tcpatterns[] array, and convert the else-if chain in match_previous_words() |
| 12 |
* into a switch. See comments for match_previous_words() and the header |
| 13 |
* comment in gen_tabcomplete.pl for more detail. |
| 14 |
*/ |
| 15 |
|
| 16 |
/*---------------------------------------------------------------------- |
| 17 |
* This file implements a somewhat more sophisticated readline "TAB |
| 18 |
* completion" in psql. It is not intended to be AI, to replace |
| 19 |
* learning SQL, or to relieve you from thinking about what you're |
| 20 |
* doing. Also it does not always give you all the syntactically legal |
| 21 |
* completions, only those that are the most common or the ones that |
| 22 |
* the programmer felt most like implementing. |
| 23 |
* |
| 24 |
* CAVEAT: Tab completion causes queries to be sent to the backend. |
| 25 |
* The number of tuples returned gets limited, in most default |
| 26 |
* installations to 1000, but if you still don't like this prospect, |
| 27 |
* you can turn off tab completion in your ~/.inputrc (or else |
| 28 |
* ${INPUTRC}) file so: |
| 29 |
* |
| 30 |
* $if psql |
| 31 |
* set disable-completion on |
| 32 |
* $endif |
| 33 |
* |
| 34 |
* See `man 3 readline' or `info readline' for the full details. |
| 35 |
* |
| 36 |
* BUGS: |
| 37 |
* - Quotes, parentheses, and other funny characters are not handled |
| 38 |
* all that gracefully. |
| 39 |
*---------------------------------------------------------------------- |
| 40 |
*/ |
| 41 |
|
| 42 |
#include "postgres_fe.h" |
| 43 |
|
| 44 |
#include "input.h" |
| 45 |
#include "tab-complete.h" |
| 46 |
|
| 47 |
/* If we don't have this, we might as well forget about the whole thing: */ |
| 48 |
#ifdef USE_READLINE |
| 49 |
|
| 50 |
#include <ctype.h> |
| 51 |
#include <sys/stat.h> |
| 52 |
|
| 53 |
#include "catalog/pg_am_d.h" |
| 54 |
#include "catalog/pg_class_d.h" |
| 55 |
#include "common.h" |
| 56 |
#include "common/keywords.h" |
| 57 |
#include "libpq-fe.h" |
| 58 |
#include "mb/pg_wchar.h" |
| 59 |
#include "pqexpbuffer.h" |
| 60 |
#include "settings.h" |
| 61 |
#include "stringutils.h" |
| 62 |
|
| 63 |
/* |
| 64 |
* Ancient versions of libedit provide filename_completion_function() |
| 65 |
* instead of rl_filename_completion_function(). Likewise for |
| 66 |
* [rl_]completion_matches(). |
| 67 |
*/ |
| 68 |
#ifndef HAVE_RL_FILENAME_COMPLETION_FUNCTION |
| 69 |
#define rl_filename_completion_function filename_completion_function |
| 70 |
#endif |
| 71 |
|
| 72 |
#ifndef HAVE_RL_COMPLETION_MATCHES |
| 73 |
#define rl_completion_matches completion_matches |
| 74 |
#endif |
| 75 |
|
| 76 |
/* |
| 77 |
* Currently we assume that rl_filename_dequoting_function exists if |
| 78 |
* rl_filename_quoting_function does. If that proves not to be the case, |
| 79 |
* we'd need to test for the former, or possibly both, in configure. |
| 80 |
*/ |
| 81 |
#ifdef HAVE_RL_FILENAME_QUOTING_FUNCTION |
| 82 |
#define USE_FILENAME_QUOTING_FUNCTIONS 1 |
| 83 |
#endif |
| 84 |
|
| 85 |
/* word break characters */ |
| 86 |
#define WORD_BREAKS "\t\n@><=;|&() " |
| 87 |
|
| 88 |
/* |
| 89 |
* Since readline doesn't let us pass any state through to the tab completion |
| 90 |
* callback, we have to use this global variable to let get_previous_words() |
| 91 |
* get at the previous lines of the current command. Ick. |
| 92 |
*/ |
| 93 |
PQExpBuffer tab_completion_query_buf = NULL; |
| 94 |
|
| 95 |
/* |
| 96 |
* In some situations, the query to find out what names are available to |
| 97 |
* complete with must vary depending on server version. We handle this by |
| 98 |
* storing a list of queries, each tagged with the minimum server version |
| 99 |
* it will work for. Each list must be stored in descending server version |
| 100 |
* order, so that the first satisfactory query is the one to use. |
| 101 |
* |
| 102 |
* When the query string is otherwise constant, an array of VersionedQuery |
| 103 |
* suffices. Terminate the array with an entry having min_server_version = 0. |
| 104 |
* That entry's query string can be a query that works in all supported older |
| 105 |
* server versions, or NULL to give up and do no completion. |
| 106 |
*/ |
| 107 |
typedef struct VersionedQuery |
| 108 |
{ |
| 109 |
int min_server_version; |
| 110 |
const char *query; |
| 111 |
} VersionedQuery; |
| 112 |
|
| 113 |
/* |
| 114 |
* This struct is used to define "schema queries", which are custom-built |
| 115 |
* to obtain possibly-schema-qualified names of database objects. There is |
| 116 |
* enough similarity in the structure that we don't want to repeat it each |
| 117 |
* time. So we put the components of each query into this struct and |
| 118 |
* assemble them with the common boilerplate in _complete_from_query(). |
| 119 |
* |
| 120 |
* We also use this struct to define queries that use completion_ref_object, |
| 121 |
* which is some object related to the one(s) we want to get the names of |
| 122 |
* (for example, the table we want the indexes of). In that usage the |
| 123 |
* objects we're completing might not have a schema of their own, but the |
| 124 |
* reference object almost always does (passed in completion_ref_schema). |
| 125 |
* |
| 126 |
* As with VersionedQuery, we can use an array of these if the query details |
| 127 |
* must vary across versions. |
| 128 |
*/ |
| 129 |
typedef struct SchemaQuery |
| 130 |
{ |
| 131 |
/* |
| 132 |
* If not zero, minimum server version this struct applies to. If not |
| 133 |
* zero, there should be a following struct with a smaller minimum server |
| 134 |
* version; use catname == NULL in the last entry if we should do nothing. |
| 135 |
*/ |
| 136 |
int min_server_version; |
| 137 |
|
| 138 |
/* |
| 139 |
* Name of catalog or catalogs to be queried, with alias(es), eg. |
| 140 |
* "pg_catalog.pg_class c". Note that "pg_namespace n" and/or |
| 141 |
* "pg_namespace nr" will be added automatically when needed. |
| 142 |
*/ |
| 143 |
const char *catname; |
| 144 |
|
| 145 |
/* |
| 146 |
* Selection condition --- only rows meeting this condition are candidates |
| 147 |
* to display. If catname mentions multiple tables, include the necessary |
| 148 |
* join condition here. For example, this might look like "c.relkind = " |
| 149 |
* CppAsString2(RELKIND_RELATION). Write NULL (not an empty string) if |
| 150 |
* not needed. |
| 151 |
*/ |
| 152 |
const char *selcondition; |
| 153 |
|
| 154 |
/* |
| 155 |
* Visibility condition --- which rows are visible without schema |
| 156 |
* qualification? For example, "pg_catalog.pg_table_is_visible(c.oid)". |
| 157 |
* NULL if not needed. |
| 158 |
*/ |
| 159 |
const char *viscondition; |
| 160 |
|
| 161 |
/* |
| 162 |
* Namespace --- name of field to join to pg_namespace.oid when there is |
| 163 |
* schema qualification. For example, "c.relnamespace". NULL if we don't |
| 164 |
* want to join to pg_namespace (then any schema part in the input word |
| 165 |
* will be ignored). |
| 166 |
*/ |
| 167 |
const char *namespace; |
| 168 |
|
| 169 |
/* |
| 170 |
* Result --- the base object name to return. For example, "c.relname". |
| 171 |
*/ |
| 172 |
const char *result; |
| 173 |
|
| 174 |
/* |
| 175 |
* In some cases, it's difficult to keep the query from returning the same |
| 176 |
* object multiple times. Specify use_distinct to filter out duplicates. |
| 177 |
*/ |
| 178 |
bool use_distinct; |
| 179 |
|
| 180 |
/* |
| 181 |
* Additional literal strings (usually keywords) to be offered along with |
| 182 |
* the query results. Provide a NULL-terminated array of constant |
| 183 |
* strings, or NULL if none. |
| 184 |
*/ |
| 185 |
const char *const *keywords; |
| 186 |
|
| 187 |
/* |
| 188 |
* If this query uses completion_ref_object/completion_ref_schema, |
| 189 |
* populate the remaining fields, else leave them NULL. When using this |
| 190 |
* capability, catname must include the catalog that defines the |
| 191 |
* completion_ref_object, and selcondition must include the join condition |
| 192 |
* that connects it to the result's catalog. |
| 193 |
* |
| 194 |
* refname is the field that should be equated to completion_ref_object, |
| 195 |
* for example "cr.relname". |
| 196 |
*/ |
| 197 |
const char *refname; |
| 198 |
|
| 199 |
/* |
| 200 |
* Visibility condition to use when completion_ref_schema is not set. For |
| 201 |
* example, "pg_catalog.pg_table_is_visible(cr.oid)". NULL if not needed. |
| 202 |
*/ |
| 203 |
const char *refviscondition; |
| 204 |
|
| 205 |
/* |
| 206 |
* Name of field to join to pg_namespace.oid when completion_ref_schema is |
| 207 |
* set. For example, "cr.relnamespace". NULL if we don't want to |
| 208 |
* consider completion_ref_schema. |
| 209 |
*/ |
| 210 |
const char *refnamespace; |
| 211 |
} SchemaQuery; |
| 212 |
|
| 213 |
|
| 214 |
/* Store maximum number of records we want from database queries |
| 215 |
* (implemented via SELECT ... LIMIT xx). |
| 216 |
*/ |
| 217 |
static int completion_max_records; |
| 218 |
|
| 219 |
/* |
| 220 |
* Communication variables set by psql_completion (mostly in COMPLETE_WITH_FOO |
| 221 |
* macros) and then used by the completion callback functions. Ugly but there |
| 222 |
* is no better way. |
| 223 |
*/ |
| 224 |
static char completion_last_char; /* last char of input word */ |
| 225 |
static const char *completion_charp; /* to pass a string */ |
| 226 |
static const char *const *completion_charpp; /* to pass a list of strings */ |
| 227 |
static const VersionedQuery *completion_vquery; /* to pass a VersionedQuery */ |
| 228 |
static const SchemaQuery *completion_squery; /* to pass a SchemaQuery */ |
| 229 |
static char *completion_ref_object; /* name of reference object */ |
| 230 |
static char *completion_ref_schema; /* schema name of reference object */ |
| 231 |
static bool completion_case_sensitive; /* completion is case sensitive */ |
| 232 |
static bool completion_verbatim; /* completion is verbatim */ |
| 233 |
static bool completion_force_quote; /* true to force-quote filenames */ |
| 234 |
|
| 235 |
/* |
| 236 |
* A few macros to ease typing. You can use these to complete the given |
| 237 |
* string with |
| 238 |
* 1) The result from a query you pass it. (Perhaps one of those below?) |
| 239 |
* We support both simple and versioned queries. |
| 240 |
* 2) The result from a schema query you pass it. |
| 241 |
* We support both simple and versioned schema queries. |
| 242 |
* 3) The items from a null-pointer-terminated list (with or without |
| 243 |
* case-sensitive comparison); if the list is constant you can build it |
| 244 |
* with COMPLETE_WITH() or COMPLETE_WITH_CS(). The QUERY_LIST and |
| 245 |
* QUERY_PLUS forms combine such literal lists with a query result. |
| 246 |
* 4) The list of attributes of the given table (possibly schema-qualified). |
| 247 |
* 5) The list of arguments to the given function (possibly schema-qualified). |
| 248 |
* |
| 249 |
* The query is generally expected to return raw SQL identifiers; matching |
| 250 |
* to what the user typed is done in a quoting-aware fashion. If what is |
| 251 |
* returned is not SQL identifiers, use one of the VERBATIM forms, in which |
| 252 |
* case the query results are matched to the user's text without double-quote |
| 253 |
* processing (so if quoting is needed, you must provide it in the query |
| 254 |
* results). |
| 255 |
*/ |
| 256 |
#define COMPLETE_WITH_QUERY(query) \ |
| 257 |
COMPLETE_WITH_QUERY_LIST(query, NULL) |
| 258 |
|
| 259 |
#define COMPLETE_WITH_QUERY_LIST(query, list) \ |
| 260 |
do { \ |
| 261 |
completion_charp = query; \ |
| 262 |
completion_charpp = list; \ |
| 263 |
completion_verbatim = false; \ |
| 264 |
matches = rl_completion_matches(text, complete_from_query); \ |
| 265 |
} while (0) |
| 266 |
|
| 267 |
#define COMPLETE_WITH_QUERY_PLUS(query, ...) \ |
| 268 |
do { \ |
| 269 |
static const char *const list[] = { __VA_ARGS__, NULL }; \ |
| 270 |
COMPLETE_WITH_QUERY_LIST(query, list); \ |
| 271 |
} while (0) |
| 272 |
|
| 273 |
#define COMPLETE_WITH_QUERY_VERBATIM(query) \ |
| 274 |
COMPLETE_WITH_QUERY_VERBATIM_LIST(query, NULL) |
| 275 |
|
| 276 |
#define COMPLETE_WITH_QUERY_VERBATIM_LIST(query, list) \ |
| 277 |
do { \ |
| 278 |
completion_charp = query; \ |
| 279 |
completion_charpp = list; \ |
| 280 |
completion_verbatim = true; \ |
| 281 |
matches = rl_completion_matches(text, complete_from_query); \ |
| 282 |
} while (0) |
| 283 |
|
| 284 |
#define COMPLETE_WITH_QUERY_VERBATIM_PLUS(query, ...) \ |
| 285 |
do { \ |
| 286 |
static const char *const list[] = { __VA_ARGS__, NULL }; \ |
| 287 |
COMPLETE_WITH_QUERY_VERBATIM_LIST(query, list); \ |
| 288 |
} while (0) |
| 289 |
|
| 290 |
#define COMPLETE_WITH_VERSIONED_QUERY(query) \ |
| 291 |
COMPLETE_WITH_VERSIONED_QUERY_LIST(query, NULL) |
| 292 |
|
| 293 |
#define COMPLETE_WITH_VERSIONED_QUERY_LIST(query, list) \ |
| 294 |
do { \ |
| 295 |
completion_vquery = query; \ |
| 296 |
completion_charpp = list; \ |
| 297 |
completion_verbatim = false; \ |
| 298 |
matches = rl_completion_matches(text, complete_from_versioned_query); \ |
| 299 |
} while (0) |
| 300 |
|
| 301 |
#define COMPLETE_WITH_VERSIONED_QUERY_PLUS(query, ...) \ |
| 302 |
do { \ |
| 303 |
static const char *const list[] = { __VA_ARGS__, NULL }; \ |
| 304 |
COMPLETE_WITH_VERSIONED_QUERY_LIST(query, list); \ |
| 305 |
} while (0) |
| 306 |
|
| 307 |
#define COMPLETE_WITH_SCHEMA_QUERY(query) \ |
| 308 |
COMPLETE_WITH_SCHEMA_QUERY_LIST(query, NULL) |
| 309 |
|
| 310 |
#define COMPLETE_WITH_SCHEMA_QUERY_LIST(query, list) \ |
| 311 |
do { \ |
| 312 |
completion_squery = &(query); \ |
| 313 |
completion_charpp = list; \ |
| 314 |
completion_verbatim = false; \ |
| 315 |
matches = rl_completion_matches(text, complete_from_schema_query); \ |
| 316 |
} while (0) |
| 317 |
|
| 318 |
#define COMPLETE_WITH_SCHEMA_QUERY_PLUS(query, ...) \ |
| 319 |
do { \ |
| 320 |
static const char *const list[] = { __VA_ARGS__, NULL }; \ |
| 321 |
COMPLETE_WITH_SCHEMA_QUERY_LIST(query, list); \ |
| 322 |
} while (0) |
| 323 |
|
| 324 |
#define COMPLETE_WITH_SCHEMA_QUERY_VERBATIM(query) \ |
| 325 |
do { \ |
| 326 |
completion_squery = &(query); \ |
| 327 |
completion_charpp = NULL; \ |
| 328 |
completion_verbatim = true; \ |
| 329 |
matches = rl_completion_matches(text, complete_from_schema_query); \ |
| 330 |
} while (0) |
| 331 |
|
| 332 |
#define COMPLETE_WITH_VERSIONED_SCHEMA_QUERY(query) \ |
| 333 |
COMPLETE_WITH_VERSIONED_SCHEMA_QUERY_LIST(query, NULL) |
| 334 |
|
| 335 |
#define COMPLETE_WITH_VERSIONED_SCHEMA_QUERY_LIST(query, list) \ |
| 336 |
do { \ |
| 337 |
completion_squery = query; \ |
| 338 |
completion_charpp = list; \ |
| 339 |
completion_verbatim = false; \ |
| 340 |
matches = rl_completion_matches(text, complete_from_versioned_schema_query); \ |
| 341 |
} while (0) |
| 342 |
|
| 343 |
#define COMPLETE_WITH_VERSIONED_SCHEMA_QUERY_PLUS(query, ...) \ |
| 344 |
do { \ |
| 345 |
static const char *const list[] = { __VA_ARGS__, NULL }; \ |
| 346 |
COMPLETE_WITH_VERSIONED_SCHEMA_QUERY_LIST(query, list); \ |
| 347 |
} while (0) |
| 348 |
|
| 349 |
/* |
| 350 |
* Caution: COMPLETE_WITH_CONST is not for general-purpose use; you probably |
| 351 |
* want COMPLETE_WITH() with one element, instead. |
| 352 |
*/ |
| 353 |
#define COMPLETE_WITH_CONST(cs, con) \ |
| 354 |
do { \ |
| 355 |
completion_case_sensitive = (cs); \ |
| 356 |
completion_charp = (con); \ |
| 357 |
matches = rl_completion_matches(text, complete_from_const); \ |
| 358 |
} while (0) |
| 359 |
|
| 360 |
#define COMPLETE_WITH_LIST_INT(cs, list) \ |
| 361 |
do { \ |
| 362 |
completion_case_sensitive = (cs); \ |
| 363 |
completion_charpp = (list); \ |
| 364 |
matches = rl_completion_matches(text, complete_from_list); \ |
| 365 |
} while (0) |
| 366 |
|
| 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) |
| 369 |
|
| 370 |
#define COMPLETE_WITH(...) \ |
| 371 |
do { \ |
| 372 |
static const char *const list[] = { __VA_ARGS__, NULL }; \ |
| 373 |
COMPLETE_WITH_LIST(list); \ |
| 374 |
} while (0) |
| 375 |
|
| 376 |
#define COMPLETE_WITH_CS(...) \ |
| 377 |
do { \ |
| 378 |
static const char *const list[] = { __VA_ARGS__, NULL }; \ |
| 379 |
COMPLETE_WITH_LIST_CS(list); \ |
| 380 |
} while (0) |
| 381 |
|
| 382 |
#define COMPLETE_WITH_ATTR(relation) \ |
| 383 |
COMPLETE_WITH_ATTR_LIST(relation, NULL) |
| 384 |
|
| 385 |
#define COMPLETE_WITH_ATTR_LIST(relation, list) \ |
| 386 |
do { \ |
| 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); \ |
| 392 |
} while (0) |
| 393 |
|
| 394 |
#define COMPLETE_WITH_ATTR_PLUS(relation, ...) \ |
| 395 |
do { \ |
| 396 |
static const char *const list[] = { __VA_ARGS__, NULL }; \ |
| 397 |
COMPLETE_WITH_ATTR_LIST(relation, list); \ |
| 398 |
} while (0) |
| 399 |
|
| 400 |
/* |
| 401 |
* libedit will typically include the literal's leading single quote in |
| 402 |
* "text", while readline will not. Adapt our offered strings to fit. |
| 403 |
* But include a quote if there's not one just before "text", to get the |
| 404 |
* user off to the right start. |
| 405 |
*/ |
| 406 |
#define COMPLETE_WITH_ENUM_VALUE(type) \ |
| 407 |
do { \ |
| 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); \ |
| 412 |
else \ |
| 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); \ |
| 417 |
} while (0) |
| 418 |
|
| 419 |
/* |
| 420 |
* Timezone completion is mostly like enum label completion, but we work |
| 421 |
* a little harder since this is a more common use-case. |
| 422 |
*/ |
| 423 |
#define COMPLETE_WITH_TIMEZONE_NAME() \ |
| 424 |
do { \ |
| 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; \ |
| 430 |
else \ |
| 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); \ |
| 435 |
} while (0) |
| 436 |
|
| 437 |
#define COMPLETE_WITH_FUNCTION_ARG(function) \ |
| 438 |
do { \ |
| 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); \ |
| 444 |
} while (0) |
| 445 |
|
| 446 |
/* |
| 447 |
* Assembly instructions for schema queries |
| 448 |
* |
| 449 |
* Note that toast tables are not included in those queries to avoid |
| 450 |
* unnecessary bloat in the completions generated. |
| 451 |
*/ |
| 452 |
|
| 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", |
| 460 |
}; |
| 461 |
|
| 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", |
| 469 |
}; |
| 470 |
|
| 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", |
| 478 |
}; |
| 479 |
|
| 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", |
| 487 |
}; |
| 488 |
|
| 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", |
| 496 |
}; |
| 497 |
|
| 498 |
static const SchemaQuery Query_for_list_of_aggregates[] = { |
| 499 |
{ |
| 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", |
| 506 |
}, |
| 507 |
{ |
| 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", |
| 513 |
} |
| 514 |
}; |
| 515 |
|
| 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", |
| 522 |
}; |
| 523 |
|
| 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", |
| 531 |
}; |
| 532 |
|
| 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", |
| 540 |
}; |
| 541 |
|
| 542 |
static const char *const Keywords_for_list_of_datatypes[] = { |
| 543 |
"bigint", |
| 544 |
"boolean", |
| 545 |
"character", |
| 546 |
"double precision", |
| 547 |
"integer", |
| 548 |
"real", |
| 549 |
"smallint", |
| 550 |
|
| 551 |
/* |
| 552 |
* Note: currently there's no value in offering the following multiword |
| 553 |
* type names, because tab completion cannot succeed for them: we can't |
| 554 |
* disambiguate until somewhere in the second word, at which point we |
| 555 |
* won't have the first word as context. ("double precision" does work, |
| 556 |
* as long as no other type name begins with "double".) Leave them out to |
| 557 |
* encourage users to use the PG-specific aliases, which we can complete. |
| 558 |
*/ |
| 559 |
#ifdef NOT_USED |
| 560 |
"bit varying", |
| 561 |
"character varying", |
| 562 |
"time with time zone", |
| 563 |
"time without time zone", |
| 564 |
"timestamp with time zone", |
| 565 |
"timestamp without time zone", |
| 566 |
#endif |
| 567 |
NULL |
| 568 |
}; |
| 569 |
|
| 570 |
static const SchemaQuery Query_for_list_of_datatypes = { |
| 571 |
.catname = "pg_catalog.pg_type t", |
| 572 |
/* selcondition --- ignore table rowtypes and array types */ |
| 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, |
| 581 |
}; |
| 582 |
|
| 583 |
static const SchemaQuery Query_for_list_of_composite_datatypes = { |
| 584 |
.catname = "pg_catalog.pg_type t", |
| 585 |
/* selcondition --- only get composite types */ |
| 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", |
| 592 |
}; |
| 593 |
|
| 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", |
| 600 |
}; |
| 601 |
|
| 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", |
| 609 |
}; |
| 610 |
|
| 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", |
| 618 |
}; |
| 619 |
|
| 620 |
/* Note: this intentionally accepts aggregates as well as plain functions */ |
| 621 |
static const SchemaQuery Query_for_list_of_functions[] = { |
| 622 |
{ |
| 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", |
| 629 |
}, |
| 630 |
{ |
| 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", |
| 635 |
} |
| 636 |
}; |
| 637 |
|
| 638 |
static const SchemaQuery Query_for_list_of_procedures[] = { |
| 639 |
{ |
| 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", |
| 646 |
}, |
| 647 |
{ |
| 648 |
/* not supported in older versions */ |
| 649 |
.catname = NULL, |
| 650 |
} |
| 651 |
}; |
| 652 |
|
| 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", |
| 658 |
}; |
| 659 |
|
| 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", |
| 666 |
}; |
| 667 |
|
| 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", |
| 674 |
}; |
| 675 |
|
| 676 |
static const SchemaQuery Query_for_list_of_tables = { |
| 677 |
.catname = "pg_catalog.pg_class c", |
| 678 |
.selcondition = |
| 679 |
"c.relkind IN (" CppAsString2(RELKIND_RELATION) ", " |
| 680 |
CppAsString2(RELKIND_PARTITIONED_TABLE) ")", |
| 681 |
.viscondition = "pg_catalog.pg_table_is_visible(c.oid)", |
| 682 |
.namespace = "c.relnamespace", |
| 683 |
.result = "c.relname", |
| 684 |
}; |
| 685 |
|
| 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", |
| 692 |
}; |
| 693 |
|
| 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 (" |
| 697 |
CppAsString2(RELKIND_RELATION) ", " |
| 698 |
CppAsString2(RELKIND_PARTITIONED_TABLE) ")", |
| 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", |
| 704 |
}; |
| 705 |
|
| 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", |
| 714 |
}; |
| 715 |
|
| 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", |
| 724 |
}; |
| 725 |
|
| 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", |
| 734 |
}; |
| 735 |
|
| 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", |
| 741 |
}; |
| 742 |
|
| 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", |
| 748 |
}; |
| 749 |
|
| 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", |
| 755 |
}; |
| 756 |
|
| 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", |
| 762 |
}; |
| 763 |
|
| 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", |
| 770 |
}; |
| 771 |
|
| 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", |
| 778 |
}; |
| 779 |
|
| 780 |
static const SchemaQuery Query_for_list_of_indexes = { |
| 781 |
.catname = "pg_catalog.pg_class c", |
| 782 |
.selcondition = |
| 783 |
"c.relkind IN (" CppAsString2(RELKIND_INDEX) ", " |
| 784 |
CppAsString2(RELKIND_PARTITIONED_INDEX) ")", |
| 785 |
.viscondition = "pg_catalog.pg_table_is_visible(c.oid)", |
| 786 |
.namespace = "c.relnamespace", |
| 787 |
.result = "c.relname", |
| 788 |
}; |
| 789 |
|
| 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", |
| 796 |
}; |
| 797 |
|
| 798 |
|
| 799 |
/* All relations */ |
| 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", |
| 805 |
}; |
| 806 |
|
| 807 |
/* partitioned relations */ |
| 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) |
| 811 |
", " CppAsString2(RELKIND_PARTITIONED_INDEX) ")", |
| 812 |
.viscondition = "pg_catalog.pg_table_is_visible(c.oid)", |
| 813 |
.namespace = "c.relnamespace", |
| 814 |
.result = "c.relname", |
| 815 |
}; |
| 816 |
|
| 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", |
| 822 |
}; |
| 823 |
|
| 824 |
/* Relations supporting INSERT, UPDATE or DELETE */ |
| 825 |
static const SchemaQuery Query_for_list_of_updatables = { |
| 826 |
.catname = "pg_catalog.pg_class c", |
| 827 |
.selcondition = |
| 828 |
"c.relkind IN (" CppAsString2(RELKIND_RELATION) ", " |
| 829 |
CppAsString2(RELKIND_FOREIGN_TABLE) ", " |
| 830 |
CppAsString2(RELKIND_VIEW) ", " |
| 831 |
CppAsString2(RELKIND_PARTITIONED_TABLE) ")", |
| 832 |
.viscondition = "pg_catalog.pg_table_is_visible(c.oid)", |
| 833 |
.namespace = "c.relnamespace", |
| 834 |
.result = "c.relname", |
| 835 |
}; |
| 836 |
|
| 837 |
/* Relations supporting MERGE */ |
| 838 |
static const SchemaQuery Query_for_list_of_mergetargets = { |
| 839 |
.catname = "pg_catalog.pg_class c", |
| 840 |
.selcondition = |
| 841 |
"c.relkind IN (" CppAsString2(RELKIND_RELATION) ", " |
| 842 |
CppAsString2(RELKIND_VIEW) ", " |
| 843 |
CppAsString2(RELKIND_PARTITIONED_TABLE) ") ", |
| 844 |
.viscondition = "pg_catalog.pg_table_is_visible(c.oid)", |
| 845 |
.namespace = "c.relnamespace", |
| 846 |
.result = "c.relname", |
| 847 |
}; |
| 848 |
|
| 849 |
/* Relations supporting SELECT */ |
| 850 |
static const SchemaQuery Query_for_list_of_selectables = { |
| 851 |
.catname = "pg_catalog.pg_class c", |
| 852 |
.selcondition = |
| 853 |
"c.relkind IN (" CppAsString2(RELKIND_RELATION) ", " |
| 854 |
CppAsString2(RELKIND_SEQUENCE) ", " |
| 855 |
CppAsString2(RELKIND_VIEW) ", " |
| 856 |
CppAsString2(RELKIND_MATVIEW) ", " |
| 857 |
CppAsString2(RELKIND_FOREIGN_TABLE) ", " |
| 858 |
CppAsString2(RELKIND_PARTITIONED_TABLE) ")", |
| 859 |
.viscondition = "pg_catalog.pg_table_is_visible(c.oid)", |
| 860 |
.namespace = "c.relnamespace", |
| 861 |
.result = "c.relname", |
| 862 |
}; |
| 863 |
|
| 864 |
/* Relations supporting TRUNCATE */ |
| 865 |
static const SchemaQuery Query_for_list_of_truncatables = { |
| 866 |
.catname = "pg_catalog.pg_class c", |
| 867 |
.selcondition = |
| 868 |
"c.relkind IN (" CppAsString2(RELKIND_RELATION) ", " |
| 869 |
CppAsString2(RELKIND_FOREIGN_TABLE) ", " |
| 870 |
CppAsString2(RELKIND_PARTITIONED_TABLE) ")", |
| 871 |
.viscondition = "pg_catalog.pg_table_is_visible(c.oid)", |
| 872 |
.namespace = "c.relnamespace", |
| 873 |
.result = "c.relname", |
| 874 |
}; |
| 875 |
|
| 876 |
/* Relations supporting GRANT are currently same as those supporting SELECT */ |
| 877 |
#define Query_for_list_of_grantables Query_for_list_of_selectables |
| 878 |
|
| 879 |
/* Relations supporting ANALYZE */ |
| 880 |
static const SchemaQuery Query_for_list_of_analyzables = { |
| 881 |
.catname = "pg_catalog.pg_class c", |
| 882 |
.selcondition = |
| 883 |
"c.relkind IN (" CppAsString2(RELKIND_RELATION) ", " |
| 884 |
CppAsString2(RELKIND_PARTITIONED_TABLE) ", " |
| 885 |
CppAsString2(RELKIND_MATVIEW) ", " |
| 886 |
CppAsString2(RELKIND_FOREIGN_TABLE) ")", |
| 887 |
.viscondition = "pg_catalog.pg_table_is_visible(c.oid)", |
| 888 |
.namespace = "c.relnamespace", |
| 889 |
.result = "c.relname", |
| 890 |
}; |
| 891 |
|
| 892 |
/* Relations supporting index creation */ |
| 893 |
static const SchemaQuery Query_for_list_of_indexables = { |
| 894 |
.catname = "pg_catalog.pg_class c", |
| 895 |
.selcondition = |
| 896 |
"c.relkind IN (" CppAsString2(RELKIND_RELATION) ", " |
| 897 |
CppAsString2(RELKIND_PARTITIONED_TABLE) ", " |
| 898 |
CppAsString2(RELKIND_MATVIEW) ")", |
| 899 |
.viscondition = "pg_catalog.pg_table_is_visible(c.oid)", |
| 900 |
.namespace = "c.relnamespace", |
| 901 |
.result = "c.relname", |
| 902 |
}; |
| 903 |
|
| 904 |
/* |
| 905 |
* Relations supporting VACUUM are currently same as those supporting |
| 906 |
* indexing. |
| 907 |
*/ |
| 908 |
#define Query_for_list_of_vacuumables Query_for_list_of_indexables |
| 909 |
|
| 910 |
/* Relations supporting CLUSTER */ |
| 911 |
static const SchemaQuery Query_for_list_of_clusterables = { |
| 912 |
.catname = "pg_catalog.pg_class c", |
| 913 |
.selcondition = |
| 914 |
"c.relkind IN (" CppAsString2(RELKIND_RELATION) ", " |
| 915 |
CppAsString2(RELKIND_PARTITIONED_TABLE) ", " |
| 916 |
CppAsString2(RELKIND_MATVIEW) ")", |
| 917 |
.viscondition = "pg_catalog.pg_table_is_visible(c.oid)", |
| 918 |
.namespace = "c.relnamespace", |
| 919 |
.result = "c.relname", |
| 920 |
}; |
| 921 |
|
| 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", |
| 927 |
}; |
| 928 |
|
| 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", |
| 934 |
}; |
| 935 |
|
| 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", |
| 942 |
}; |
| 943 |
|
| 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", |
| 953 |
}; |
| 954 |
|
| 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", |
| 962 |
}; |
| 963 |
|
| 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", |
| 971 |
}; |
| 972 |
|
| 973 |
|
| 974 |
/* |
| 975 |
* Queries to get lists of names of various kinds of things, possibly |
| 976 |
* restricted to names matching a partially entered name. Don't use |
| 977 |
* this method where the user might wish to enter a schema-qualified |
| 978 |
* name; make a SchemaQuery instead. |
| 979 |
* |
| 980 |
* In these queries, there must be a restriction clause of the form |
| 981 |
* output LIKE '%s' |
| 982 |
* where "output" is the same string that the query returns. The %s |
| 983 |
* will be replaced by a LIKE pattern to match the already-typed text. |
| 984 |
* |
| 985 |
* There can be a second '%s', which will be replaced by a suitably-escaped |
| 986 |
* version of the string provided in completion_ref_object. If there is a |
| 987 |
* third '%s', it will be replaced by a suitably-escaped version of the string |
| 988 |
* provided in completion_ref_schema. NOTE: using completion_ref_object |
| 989 |
* that way is usually the wrong thing, and using completion_ref_schema |
| 990 |
* that way is always the wrong thing. Make a SchemaQuery instead. |
| 991 |
*/ |
| 992 |
|
| 993 |
#define Query_for_list_of_template_databases \ |
| 994 |
"SELECT d.datname "\ |
| 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'))" |
| 998 |
|
| 999 |
#define Query_for_list_of_databases \ |
| 1000 |
"SELECT datname FROM pg_catalog.pg_database "\ |
| 1001 |
" WHERE datname LIKE '%s'" |
| 1002 |
|
| 1003 |
#define Query_for_list_of_database_vars \ |
| 1004 |
"SELECT conf FROM ("\ |
| 1005 |
" SELECT setdatabase, pg_catalog.split_part(pg_catalog.unnest(setconfig),'=',1) conf"\ |
| 1006 |
" FROM pg_db_role_setting "\ |
| 1007 |
" ) s, pg_database d "\ |
| 1008 |
" WHERE s.setdatabase = d.oid "\ |
| 1009 |
" AND conf LIKE '%s'"\ |
| 1010 |
" AND d.datname LIKE '%s'" |
| 1011 |
|
| 1012 |
#define Query_for_list_of_tablespaces \ |
| 1013 |
"SELECT spcname FROM pg_catalog.pg_tablespace "\ |
| 1014 |
" WHERE spcname LIKE '%s'" |
| 1015 |
|
| 1016 |
#define Query_for_list_of_encodings \ |
| 1017 |
" SELECT DISTINCT pg_catalog.pg_encoding_to_char(conforencoding) "\ |
| 1018 |
" FROM pg_catalog.pg_conversion "\ |
| 1019 |
" WHERE pg_catalog.pg_encoding_to_char(conforencoding) LIKE pg_catalog.upper('%s')" |
| 1020 |
|
| 1021 |
#define Query_for_list_of_languages \ |
| 1022 |
"SELECT lanname "\ |
| 1023 |
" FROM pg_catalog.pg_language "\ |
| 1024 |
" WHERE lanname != 'internal' "\ |
| 1025 |
" AND lanname LIKE '%s'" |
| 1026 |
|
| 1027 |
#define Query_for_list_of_schemas \ |
| 1028 |
"SELECT nspname FROM pg_catalog.pg_namespace "\ |
| 1029 |
" WHERE nspname LIKE '%s'" |
| 1030 |
|
| 1031 |
/* Use COMPLETE_WITH_QUERY_VERBATIM with these queries for GUC names: */ |
| 1032 |
#define Query_for_list_of_alter_system_set_vars \ |
| 1033 |
"SELECT pg_catalog.lower(name) FROM pg_catalog.pg_settings "\ |
| 1034 |
" WHERE context != 'internal' "\ |
| 1035 |
" AND pg_catalog.lower(name) LIKE pg_catalog.lower('%s')" |
| 1036 |
|
| 1037 |
#define Query_for_list_of_set_vars \ |
| 1038 |
"SELECT pg_catalog.lower(name) FROM pg_catalog.pg_settings "\ |
| 1039 |
" WHERE context IN ('user', 'superuser') "\ |
| 1040 |
" AND pg_catalog.lower(name) LIKE pg_catalog.lower('%s')" |
| 1041 |
|
| 1042 |
#define Query_for_list_of_show_vars \ |
| 1043 |
"SELECT pg_catalog.lower(name) FROM pg_catalog.pg_settings "\ |
| 1044 |
" WHERE pg_catalog.lower(name) LIKE pg_catalog.lower('%s')" |
| 1045 |
|
| 1046 |
#define Query_for_list_of_roles \ |
| 1047 |
" SELECT rolname "\ |
| 1048 |
" FROM pg_catalog.pg_roles "\ |
| 1049 |
" WHERE rolname LIKE '%s'" |
| 1050 |
|
| 1051 |
/* add these to Query_for_list_of_roles in OWNER contexts */ |
| 1052 |
#define Keywords_for_list_of_owner_roles \ |
| 1053 |
"CURRENT_ROLE", "CURRENT_USER", "SESSION_USER" |
| 1054 |
|
| 1055 |
/* add these to Query_for_list_of_roles in GRANT contexts */ |
| 1056 |
#define Keywords_for_list_of_grant_roles \ |
| 1057 |
Keywords_for_list_of_owner_roles, "PUBLIC" |
| 1058 |
|
| 1059 |
#define Query_for_all_table_constraints \ |
| 1060 |
"SELECT conname "\ |
| 1061 |
" FROM pg_catalog.pg_constraint c "\ |
| 1062 |
" WHERE c.conrelid <> 0 "\ |
| 1063 |
" and conname LIKE '%s'" |
| 1064 |
|
| 1065 |
#define Query_for_list_of_fdws \ |
| 1066 |
" SELECT fdwname "\ |
| 1067 |
" FROM pg_catalog.pg_foreign_data_wrapper "\ |
| 1068 |
" WHERE fdwname LIKE '%s'" |
| 1069 |
|
| 1070 |
#define Query_for_list_of_servers \ |
| 1071 |
" SELECT srvname "\ |
| 1072 |
" FROM pg_catalog.pg_foreign_server "\ |
| 1073 |
" WHERE srvname LIKE '%s'" |
| 1074 |
|
| 1075 |
#define Query_for_list_of_user_mappings \ |
| 1076 |
" SELECT usename "\ |
| 1077 |
" FROM pg_catalog.pg_user_mappings "\ |
| 1078 |
" WHERE usename LIKE '%s'" |
| 1079 |
|
| 1080 |
#define Query_for_list_of_user_vars \ |
| 1081 |
"SELECT conf FROM ("\ |
| 1082 |
" SELECT rolname, pg_catalog.split_part(pg_catalog.unnest(rolconfig),'=',1) conf"\ |
| 1083 |
" FROM pg_catalog.pg_roles"\ |
| 1084 |
" ) s"\ |
| 1085 |
" WHERE s.conf like '%s' "\ |
| 1086 |
" AND s.rolname LIKE '%s'" |
| 1087 |
|
| 1088 |
#define Query_for_list_of_access_methods \ |
| 1089 |
" SELECT amname "\ |
| 1090 |
" FROM pg_catalog.pg_am "\ |
| 1091 |
" WHERE amname LIKE '%s'" |
| 1092 |
|
| 1093 |
#define Query_for_list_of_index_access_methods \ |
| 1094 |
" SELECT amname "\ |
| 1095 |
" FROM pg_catalog.pg_am "\ |
| 1096 |
" WHERE amname LIKE '%s' AND "\ |
| 1097 |
" amtype=" CppAsString2(AMTYPE_INDEX) |
| 1098 |
|
| 1099 |
#define Query_for_list_of_table_access_methods \ |
| 1100 |
" SELECT amname "\ |
| 1101 |
" FROM pg_catalog.pg_am "\ |
| 1102 |
" WHERE amname LIKE '%s' AND "\ |
| 1103 |
" amtype=" CppAsString2(AMTYPE_TABLE) |
| 1104 |
|
| 1105 |
#define Query_for_list_of_extensions \ |
| 1106 |
" SELECT extname "\ |
| 1107 |
" FROM pg_catalog.pg_extension "\ |
| 1108 |
" WHERE extname LIKE '%s'" |
| 1109 |
|
| 1110 |
#define Query_for_list_of_available_extensions \ |
| 1111 |
" SELECT name "\ |
| 1112 |
" FROM pg_catalog.pg_available_extensions "\ |
| 1113 |
" WHERE name LIKE '%s' AND installed_version IS NULL" |
| 1114 |
|
| 1115 |
#define Query_for_list_of_available_extension_versions \ |
| 1116 |
" SELECT version "\ |
| 1117 |
" FROM pg_catalog.pg_available_extension_versions "\ |
| 1118 |
" WHERE version LIKE '%s' AND name='%s'" |
| 1119 |
|
| 1120 |
#define Query_for_list_of_prepared_statements \ |
| 1121 |
" SELECT name "\ |
| 1122 |
" FROM pg_catalog.pg_prepared_statements "\ |
| 1123 |
" WHERE name LIKE '%s'" |
| 1124 |
|
| 1125 |
#define Query_for_list_of_event_triggers \ |
| 1126 |
" SELECT evtname "\ |
| 1127 |
" FROM pg_catalog.pg_event_trigger "\ |
| 1128 |
" WHERE evtname LIKE '%s'" |
| 1129 |
|
| 1130 |
#define Query_for_list_of_tablesample_methods \ |
| 1131 |
" SELECT proname "\ |
| 1132 |
" FROM pg_catalog.pg_proc "\ |
| 1133 |
" WHERE prorettype = 'pg_catalog.tsm_handler'::pg_catalog.regtype AND "\ |
| 1134 |
" proargtypes[0] = 'pg_catalog.internal'::pg_catalog.regtype AND "\ |
| 1135 |
" proname LIKE '%s'" |
| 1136 |
|
| 1137 |
#define Query_for_list_of_policies \ |
| 1138 |
" SELECT polname "\ |
| 1139 |
" FROM pg_catalog.pg_policy "\ |
| 1140 |
" WHERE polname LIKE '%s'" |
| 1141 |
|
| 1142 |
#define Query_for_values_of_enum_GUC \ |
| 1143 |
" SELECT val FROM ( "\ |
| 1144 |
" SELECT name, pg_catalog.unnest(enumvals) AS val "\ |
| 1145 |
" FROM pg_catalog.pg_settings "\ |
| 1146 |
" ) ss "\ |
| 1147 |
" WHERE val LIKE '%s'"\ |
| 1148 |
" and pg_catalog.lower(name)=pg_catalog.lower('%s')" |
| 1149 |
|
| 1150 |
#define Query_for_list_of_channels \ |
| 1151 |
" SELECT channel "\ |
| 1152 |
" FROM pg_catalog.pg_listening_channels() AS channel "\ |
| 1153 |
" WHERE channel LIKE '%s'" |
| 1154 |
|
| 1155 |
#define Query_for_list_of_cursors \ |
| 1156 |
" SELECT name "\ |
| 1157 |
" FROM pg_catalog.pg_cursors "\ |
| 1158 |
" WHERE name LIKE '%s'" |
| 1159 |
|
| 1160 |
#define Query_for_list_of_timezone_names_unquoted \ |
| 1161 |
" SELECT name "\ |
| 1162 |
" FROM pg_catalog.pg_timezone_names() "\ |
| 1163 |
" WHERE pg_catalog.lower(name) LIKE pg_catalog.lower('%s')" |
| 1164 |
|
| 1165 |
#define Query_for_list_of_timezone_names_quoted_out \ |
| 1166 |
"SELECT pg_catalog.quote_literal(name) AS name "\ |
| 1167 |
" FROM pg_catalog.pg_timezone_names() "\ |
| 1168 |
" WHERE pg_catalog.lower(name) LIKE pg_catalog.lower('%s')" |
| 1169 |
|
| 1170 |
#define Query_for_list_of_timezone_names_quoted_in \ |
| 1171 |
"SELECT pg_catalog.quote_literal(name) AS name "\ |
| 1172 |
" FROM pg_catalog.pg_timezone_names() "\ |
| 1173 |
" WHERE pg_catalog.quote_literal(pg_catalog.lower(name)) LIKE pg_catalog.lower('%s')" |
| 1174 |
|
| 1175 |
/* Privilege options shared between GRANT and REVOKE */ |
| 1176 |
#define Privilege_options_of_grant_and_revoke \ |
| 1177 |
"SELECT", "INSERT", "UPDATE", "DELETE", "TRUNCATE", "REFERENCES", "TRIGGER", \ |
| 1178 |
"CREATE", "CONNECT", "TEMPORARY", "EXECUTE", "USAGE", "SET", "ALTER SYSTEM", \ |
| 1179 |
"MAINTAIN", "ALL" |
| 1180 |
|
| 1181 |
/* ALTER PROCEDURE options */ |
| 1182 |
#define Alter_procedure_options \ |
| 1183 |
"DEPENDS ON EXTENSION", "EXTERNAL SECURITY", "NO DEPENDS ON EXTENSION", \ |
| 1184 |
"OWNER TO", "RENAME TO", "RESET", "SECURITY", "SET" |
| 1185 |
|
| 1186 |
/* ALTER ROUTINE options */ |
| 1187 |
#define Alter_routine_options \ |
| 1188 |
Alter_procedure_options, "COST", "IMMUTABLE", "LEAKPROOF", "NOT LEAKPROOF", \ |
| 1189 |
"PARALLEL", "ROWS", "STABLE", "VOLATILE" |
| 1190 |
|
| 1191 |
/* ALTER FUNCTION options */ |
| 1192 |
#define Alter_function_options \ |
| 1193 |
Alter_routine_options, "CALLED ON NULL INPUT", "RETURNS NULL ON NULL INPUT", \ |
| 1194 |
"STRICT", "SUPPORT" |
| 1195 |
|
| 1196 |
/* COPY options shared between FROM and TO */ |
| 1197 |
#define Copy_common_options \ |
| 1198 |
"DELIMITER", "ENCODING", "ESCAPE", "FORMAT", "HEADER", "NULL", "QUOTE" |
| 1199 |
|
| 1200 |
/* COPY FROM options */ |
| 1201 |
#define Copy_from_options \ |
| 1202 |
Copy_common_options, "DEFAULT", "FORCE_NOT_NULL", "FORCE_NULL", "FREEZE", \ |
| 1203 |
"LOG_VERBOSITY", "ON_ERROR", "REJECT_LIMIT" |
| 1204 |
|
| 1205 |
/* COPY TO options */ |
| 1206 |
#define Copy_to_options \ |
| 1207 |
Copy_common_options, "FORCE_QUOTE" |
| 1208 |
|
| 1209 |
/* |
| 1210 |
* These object types were introduced later than our support cutoff of |
| 1211 |
* server version 9.2. We use the VersionedQuery infrastructure so that |
| 1212 |
* we don't send certain-to-fail queries to older servers. |
| 1213 |
*/ |
| 1214 |
|
| 1215 |
static const VersionedQuery Query_for_list_of_publications[] = { |
| 1216 |
{100000, |
| 1217 |
" SELECT pubname " |
| 1218 |
" FROM pg_catalog.pg_publication " |
| 1219 |
" WHERE pubname LIKE '%s'" |
| 1220 |
}, |
| 1221 |
{0, NULL} |
| 1222 |
}; |
| 1223 |
|
| 1224 |
static const VersionedQuery Query_for_list_of_subscriptions[] = { |
| 1225 |
{100000, |
| 1226 |
" SELECT s.subname " |
| 1227 |
" FROM pg_catalog.pg_subscription s, pg_catalog.pg_database d " |
| 1228 |
" WHERE s.subname LIKE '%s' " |
| 1229 |
" AND d.datname = pg_catalog.current_database() " |
| 1230 |
" AND s.subdbid = d.oid" |
| 1231 |
}, |
| 1232 |
{0, NULL} |
| 1233 |
}; |
| 1234 |
|
| 1235 |
/* Known command-starting keywords. */ |
| 1236 |
static const char *const sql_commands[] = { |
| 1237 |
"ABORT", "ALTER", "ANALYZE", "BEGIN", "CALL", "CHECKPOINT", "CLOSE", "CLUSTER", |
| 1238 |
"COMMENT", "COMMIT", "COPY", "CREATE", "DEALLOCATE", "DECLARE", |
| 1239 |
"DELETE FROM", "DISCARD", "DO", "DROP", "END", "EXECUTE", "EXPLAIN", |
| 1240 |
"FETCH", "GRANT", "IMPORT FOREIGN SCHEMA", "INSERT INTO", "LISTEN", "LOAD", "LOCK", |
| 1241 |
"MERGE INTO", "MOVE", "NOTIFY", "PREPARE", |
| 1242 |
"REASSIGN", "REFRESH MATERIALIZED VIEW", "REINDEX", "RELEASE", |
| 1243 |
"RESET", "REVOKE", "ROLLBACK", |
| 1244 |
"SAVEPOINT", "SECURITY LABEL", "SELECT", "SET", "SHOW", "START", |
| 1245 |
"TABLE", "TRUNCATE", "UNLISTEN", "UPDATE", "VACUUM", "VALUES", "WITH", |
| 1246 |
NULL |
| 1247 |
}; |
| 1248 |
|
| 1249 |
/* |
| 1250 |
* This is a list of all "things" in Pgsql, which can show up after CREATE or |
| 1251 |
* DROP; and there is also a query to get a list of them. |
| 1252 |
*/ |
| 1253 |
|
| 1254 |
typedef struct |
| 1255 |
{ |
| 1256 |
const char *name; |
| 1257 |
/* Provide at most one of these three types of query: */ |
| 1258 |
const char *query; /* simple query, or NULL */ |
| 1259 |
const VersionedQuery *vquery; /* versioned query, or NULL */ |
| 1260 |
const SchemaQuery *squery; /* schema query, or NULL */ |
| 1261 |
const char *const *keywords; /* keywords to be offered as well */ |
| 1262 |
const bits32 flags; /* visibility flags, see below */ |
| 1263 |
} pgsql_thing_t; |
| 1264 |
|
| 1265 |
#define THING_NO_CREATE (1 << 0) /* should not show up after CREATE */ |
| 1266 |
#define THING_NO_DROP (1 << 1) /* should not show up after DROP */ |
| 1267 |
#define THING_NO_ALTER (1 << 2) /* should not show up after ALTER */ |
| 1268 |
#define THING_NO_SHOW (THING_NO_CREATE | THING_NO_DROP | THING_NO_ALTER) |
| 1269 |
|
| 1270 |
/* When we have DROP USER etc, also offer MAPPING FOR */ |
| 1271 |
static const char *const Keywords_for_user_thing[] = { |
| 1272 |
"MAPPING FOR", |
| 1273 |
NULL |
| 1274 |
}; |
| 1275 |
|
| 1276 |
static const pgsql_thing_t words_after_create[] = { |
| 1277 |
{"ACCESS METHOD", NULL, NULL, NULL, NULL, THING_NO_ALTER}, |
| 1278 |
{"AGGREGATE", NULL, NULL, Query_for_list_of_aggregates}, |
| 1279 |
{"CAST", NULL, NULL, NULL}, /* Casts have complex structures for names, so |
| 1280 |
* skip it */ |
| 1281 |
{"COLLATION", NULL, NULL, &Query_for_list_of_collations}, |
| 1282 |
|
| 1283 |
/* |
| 1284 |
* CREATE CONSTRAINT TRIGGER is not supported here because it is designed |
| 1285 |
* to be used only by pg_dump. |
| 1286 |
*/ |
| 1287 |
{"CONFIGURATION", NULL, NULL, &Query_for_list_of_ts_configurations, NULL, THING_NO_SHOW}, |
| 1288 |
{"CONVERSION", "SELECT conname FROM pg_catalog.pg_conversion WHERE conname LIKE '%s'"}, |
| 1289 |
{"DATABASE", Query_for_list_of_databases}, |
| 1290 |
{"DEFAULT PRIVILEGES", NULL, NULL, NULL, NULL, THING_NO_CREATE | THING_NO_DROP}, |
| 1291 |
{"DICTIONARY", NULL, NULL, &Query_for_list_of_ts_dictionaries, NULL, THING_NO_SHOW}, |
| 1292 |
{"DOMAIN", NULL, NULL, &Query_for_list_of_domains}, |
| 1293 |
{"EVENT TRIGGER", NULL, NULL, NULL}, |
| 1294 |
{"EXTENSION", Query_for_list_of_extensions}, |
| 1295 |
{"FOREIGN DATA WRAPPER", NULL, NULL, NULL}, |
| 1296 |
{"FOREIGN TABLE", NULL, NULL, NULL}, |
| 1297 |
{"FUNCTION", NULL, NULL, Query_for_list_of_functions}, |
| 1298 |
{"GROUP", Query_for_list_of_roles}, |
| 1299 |
{"INDEX", NULL, NULL, &Query_for_list_of_indexes}, |
| 1300 |
{"LANGUAGE", Query_for_list_of_languages}, |
| 1301 |
{"LARGE OBJECT", NULL, NULL, NULL, NULL, THING_NO_CREATE | THING_NO_DROP}, |
| 1302 |
{"MATERIALIZED VIEW", NULL, NULL, &Query_for_list_of_matviews}, |
| 1303 |
{"OPERATOR", NULL, NULL, NULL}, /* Querying for this is probably not such |
| 1304 |
* a good idea. */ |
| 1305 |
{"OR REPLACE", NULL, NULL, NULL, NULL, THING_NO_DROP | THING_NO_ALTER}, |
| 1306 |
{"OWNED", NULL, NULL, NULL, NULL, THING_NO_CREATE | THING_NO_ALTER}, /* for DROP OWNED BY ... */ |
| 1307 |
{"PARSER", NULL, NULL, &Query_for_list_of_ts_parsers, NULL, THING_NO_SHOW}, |
| 1308 |
{"POLICY", NULL, NULL, NULL}, |
| 1309 |
{"PROCEDURE", NULL, NULL, Query_for_list_of_procedures}, |
| 1310 |
{"PUBLICATION", NULL, Query_for_list_of_publications}, |
| 1311 |
{"ROLE", Query_for_list_of_roles}, |
| 1312 |
{"ROUTINE", NULL, NULL, &Query_for_list_of_routines, NULL, THING_NO_CREATE}, |
| 1313 |
{"RULE", "SELECT rulename FROM pg_catalog.pg_rules WHERE rulename LIKE '%s'"}, |
| 1314 |
{"SCHEMA", Query_for_list_of_schemas}, |
| 1315 |
{"SEQUENCE", NULL, NULL, &Query_for_list_of_sequences}, |
| 1316 |
{"SERVER", Query_for_list_of_servers}, |
| 1317 |
{"STATISTICS", NULL, NULL, &Query_for_list_of_statistics}, |
| 1318 |
{"SUBSCRIPTION", NULL, Query_for_list_of_subscriptions}, |
| 1319 |
{"SYSTEM", NULL, NULL, NULL, NULL, THING_NO_CREATE | THING_NO_DROP}, |
| 1320 |
{"TABLE", NULL, NULL, &Query_for_list_of_tables}, |
| 1321 |
{"TABLESPACE", Query_for_list_of_tablespaces}, |
| 1322 |
{"TEMP", NULL, NULL, NULL, NULL, THING_NO_DROP | THING_NO_ALTER}, /* for CREATE TEMP TABLE |
| 1323 |
* ... */ |
| 1324 |
{"TEMPLATE", NULL, NULL, &Query_for_list_of_ts_templates, NULL, THING_NO_SHOW}, |
| 1325 |
{"TEMPORARY", NULL, NULL, NULL, NULL, THING_NO_DROP | THING_NO_ALTER}, /* for CREATE TEMPORARY |
| 1326 |
* TABLE ... */ |
| 1327 |
{"TEXT SEARCH", NULL, NULL, NULL}, |
| 1328 |
{"TRANSFORM", NULL, NULL, NULL, NULL, THING_NO_ALTER}, |
| 1329 |
{"TRIGGER", "SELECT tgname FROM pg_catalog.pg_trigger WHERE tgname LIKE '%s' AND NOT tgisinternal"}, |
| 1330 |
{"TYPE", NULL, NULL, &Query_for_list_of_datatypes}, |
| 1331 |
{"UNIQUE", NULL, NULL, NULL, NULL, THING_NO_DROP | THING_NO_ALTER}, /* for CREATE UNIQUE |
| 1332 |
* INDEX ... */ |
| 1333 |
{"UNLOGGED", NULL, NULL, NULL, NULL, THING_NO_DROP | THING_NO_ALTER}, /* for CREATE UNLOGGED |
| 1334 |
* TABLE ... */ |
| 1335 |
{"USER", Query_for_list_of_roles, NULL, NULL, Keywords_for_user_thing}, |
| 1336 |
{"USER MAPPING FOR", NULL, NULL, NULL}, |
| 1337 |
{"VIEW", NULL, NULL, &Query_for_list_of_views}, |
| 1338 |
{NULL} /* end of list */ |
| 1339 |
}; |
| 1340 |
|
| 1341 |
/* |
| 1342 |
* The tcpatterns[] table provides the initial pattern-match rule for each |
| 1343 |
* switch case in match_previous_words(). The contents of the table |
| 1344 |
* are constructed by gen_tabcomplete.pl. |
| 1345 |
*/ |
| 1346 |
|
| 1347 |
/* Basic match rules appearing in tcpatterns[].kind */ |
| 1348 |
enum TCPatternKind |
| 1349 |
{ |
| 1350 |
Match, |
| 1351 |
MatchCS, |
| 1352 |
HeadMatch, |
| 1353 |
HeadMatchCS, |
| 1354 |
TailMatch, |
| 1355 |
TailMatchCS, |
| 1356 |
}; |
| 1357 |
|
| 1358 |
/* Things besides string literals that can appear in tcpatterns[].words */ |
| 1359 |
#define MatchAny NULL |
| 1360 |
#define MatchAnyExcept(pattern) ("!" pattern) |
| 1361 |
#define MatchAnyN "" |
| 1362 |
|
| 1363 |
/* One entry in tcpatterns[] */ |
| 1364 |
typedef struct |
| 1365 |
{ |
| 1366 |
int id; /* case label used in match_previous_words */ |
| 1367 |
enum TCPatternKind kind; /* match kind, see above */ |
| 1368 |
int nwords; /* length of words[] array */ |
| 1369 |
const char *const *words; /* array of match words */ |
| 1370 |
} TCPattern; |
| 1371 |
|
| 1372 |
/* Macro emitted by gen_tabcomplete.pl to fill a tcpatterns[] entry */ |
| 1373 |
#define TCPAT(id, kind, ...) \ |
| 1374 |
{ (id), (kind), VA_ARGS_NARGS(__VA_ARGS__), \ |
| 1375 |
(const char * const []) { __VA_ARGS__ } } |
| 1376 |
|
| 1377 |
#ifdef SWITCH_CONVERSION_APPLIED |
| 1378 |
|
| 1379 |
static const TCPattern tcpatterns[] = |
| 1380 |
{ |
| 1381 |
/* Insert tab-completion pattern data here. */ |
| 1382 |
}; |
| 1383 |
|
| 1384 |
#endif /* SWITCH_CONVERSION_APPLIED */ |
| 1385 |
|
| 1386 |
/* Storage parameters for CREATE TABLE and ALTER TABLE */ |
| 1387 |
static const char *const table_storage_parameters[] = { |
| 1388 |
"autovacuum_analyze_scale_factor", |
| 1389 |
"autovacuum_analyze_threshold", |
| 1390 |
"autovacuum_enabled", |
| 1391 |
"autovacuum_freeze_max_age", |
| 1392 |
"autovacuum_freeze_min_age", |
| 1393 |
"autovacuum_freeze_table_age", |
| 1394 |
"autovacuum_multixact_freeze_max_age", |
| 1395 |
"autovacuum_multixact_freeze_min_age", |
| 1396 |
"autovacuum_multixact_freeze_table_age", |
| 1397 |
"autovacuum_vacuum_cost_delay", |
| 1398 |
"autovacuum_vacuum_cost_limit", |
| 1399 |
"autovacuum_vacuum_insert_scale_factor", |
| 1400 |
"autovacuum_vacuum_insert_threshold", |
| 1401 |
"autovacuum_vacuum_max_threshold", |
| 1402 |
"autovacuum_vacuum_scale_factor", |
| 1403 |
"autovacuum_vacuum_threshold", |
| 1404 |
"fillfactor", |
| 1405 |
"log_autovacuum_min_duration", |
| 1406 |
"parallel_workers", |
| 1407 |
"toast.autovacuum_enabled", |
| 1408 |
"toast.autovacuum_freeze_max_age", |
| 1409 |
"toast.autovacuum_freeze_min_age", |
| 1410 |
"toast.autovacuum_freeze_table_age", |
| 1411 |
"toast.autovacuum_multixact_freeze_max_age", |
| 1412 |
"toast.autovacuum_multixact_freeze_min_age", |
| 1413 |
"toast.autovacuum_multixact_freeze_table_age", |
| 1414 |
"toast.autovacuum_vacuum_cost_delay", |
| 1415 |
"toast.autovacuum_vacuum_cost_limit", |
| 1416 |
"toast.autovacuum_vacuum_insert_scale_factor", |
| 1417 |
"toast.autovacuum_vacuum_insert_threshold", |
| 1418 |
"toast.autovacuum_vacuum_max_threshold", |
| 1419 |
"toast.autovacuum_vacuum_scale_factor", |
| 1420 |
"toast.autovacuum_vacuum_threshold", |
| 1421 |
"toast.log_autovacuum_min_duration", |
| 1422 |
"toast.vacuum_index_cleanup", |
| 1423 |
"toast.vacuum_max_eager_freeze_failure_rate", |
| 1424 |
"toast.vacuum_truncate", |
| 1425 |
"toast_tuple_target", |
| 1426 |
"user_catalog_table", |
| 1427 |
"vacuum_index_cleanup", |
| 1428 |
"vacuum_max_eager_freeze_failure_rate", |
| 1429 |
"vacuum_truncate", |
| 1430 |
NULL |
| 1431 |
}; |
| 1432 |
|
| 1433 |
/* Optional parameters for CREATE VIEW and ALTER VIEW */ |
| 1434 |
static const char *const view_optional_parameters[] = { |
| 1435 |
"check_option", |
| 1436 |
"security_barrier", |
| 1437 |
"security_invoker", |
| 1438 |
NULL |
| 1439 |
}; |
| 1440 |
|
| 1441 |
/* Forward declaration of functions */ |
| 1442 |
static char **psql_completion(const char *text, int start, int end); |
| 1443 |
static char **match_previous_words(int pattern_id, |
| 1444 |
const char *text, int start, int end, |
| 1445 |
char **previous_words, |
| 1446 |
int previous_words_count); |
| 1447 |
static char *create_command_generator(const char *text, int state); |
| 1448 |
static char *drop_command_generator(const char *text, int state); |
| 1449 |
static char *alter_command_generator(const char *text, int state); |
| 1450 |
static char *complete_from_query(const char *text, int state); |
| 1451 |
static char *complete_from_versioned_query(const char *text, int state); |
| 1452 |
static char *complete_from_schema_query(const char *text, int state); |
| 1453 |
static char *complete_from_versioned_schema_query(const char *text, int state); |
| 1454 |
static char *_complete_from_query(const char *simple_query, |
| 1455 |
const SchemaQuery *schema_query, |
| 1456 |
const char *const *keywords, |
| 1457 |
bool verbatim, |
| 1458 |
const char *text, int state); |
| 1459 |
static void set_completion_reference(const char *word); |
| 1460 |
static void set_completion_reference_verbatim(const char *word); |
| 1461 |
static char *complete_from_list(const char *text, int state); |
| 1462 |
static char *complete_from_const(const char *text, int state); |
| 1463 |
static void append_variable_names(char ***varnames, int *nvars, |
| 1464 |
int *maxvars, const char *varname, |
| 1465 |
const char *prefix, const char *suffix); |
| 1466 |
static char **complete_from_variables(const char *text, |
| 1467 |
const char *prefix, const char *suffix, bool need_value); |
| 1468 |
static char *complete_from_files(const char *text, int state); |
| 1469 |
|
| 1470 |
static char *pg_strdup_keyword_case(const char *s, const char *ref); |
| 1471 |
static char *escape_string(const char *text); |
| 1472 |
static char *make_like_pattern(const char *word); |
| 1473 |
static void parse_identifier(const char *ident, |
| 1474 |
char **schemaname, char **objectname, |
| 1475 |
bool *schemaquoted, bool *objectquoted); |
| 1476 |
static char *requote_identifier(const char *schemaname, const char *objectname, |
| 1477 |
bool quote_schema, bool quote_object); |
| 1478 |
static bool identifier_needs_quotes(const char *ident); |
| 1479 |
static PGresult *exec_query(const char *query); |
| 1480 |
|
| 1481 |
static char **get_previous_words(int point, char **buffer, int *nwords); |
| 1482 |
|
| 1483 |
static char *get_guctype(const char *varname); |
| 1484 |
|
| 1485 |
#ifdef USE_FILENAME_QUOTING_FUNCTIONS |
| 1486 |
static char *quote_file_name(char *fname, int match_type, char *quote_pointer); |
| 1487 |
static char *dequote_file_name(char *fname, int quote_char); |
| 1488 |
#endif |
| 1489 |
|
| 1490 |
|
| 1491 |
/* |
| 1492 |
* Initialize the readline library for our purposes. |
| 1493 |
*/ |
| 1494 |
void |
| 1495 |
initialize_readline(void) |
| 1496 |
{ |
| 1497 |
rl_readline_name = (char *) pset.progname; |
| 1498 |
rl_attempted_completion_function = psql_completion; |
| 1499 |
|
| 1500 |
#ifdef USE_FILENAME_QUOTING_FUNCTIONS |
| 1501 |
rl_filename_quoting_function = quote_file_name; |
| 1502 |
rl_filename_dequoting_function = dequote_file_name; |
| 1503 |
#endif |
| 1504 |
|
| 1505 |
rl_basic_word_break_characters = WORD_BREAKS; |
| 1506 |
|
| 1507 |
/* |
| 1508 |
* Ideally we'd include '"' in rl_completer_quote_characters too, which |
| 1509 |
* should allow us to complete quoted identifiers that include spaces. |
| 1510 |
* However, the library support for rl_completer_quote_characters is |
| 1511 |
* presently too inconsistent to want to mess with that. (Note in |
| 1512 |
* particular that libedit has this variable but completely ignores it.) |
| 1513 |
*/ |
| 1514 |
rl_completer_quote_characters = "'"; |
| 1515 |
|
| 1516 |
/* |
| 1517 |
* Set rl_filename_quote_characters to "all possible characters", |
| 1518 |
* otherwise Readline will skip filename quoting if it thinks a filename |
| 1519 |
* doesn't need quoting. Readline actually interprets this as bytes, so |
| 1520 |
* there are no encoding considerations here. |
| 1521 |
*/ |
| 1522 |
#ifdef HAVE_RL_FILENAME_QUOTE_CHARACTERS |
| 1523 |
{ |
| 1524 |
unsigned char *fqc = (unsigned char *) pg_malloc(256); |
| 1525 |
|
| 1526 |
for (int i = 0; i < 255; i++) |
| 1527 |
fqc[i] = (unsigned char) (i + 1); |
| 1528 |
fqc[255] = '\0'; |
| 1529 |
rl_filename_quote_characters = (const char *) fqc; |
| 1530 |
} |
| 1531 |
#endif |
| 1532 |
|
| 1533 |
completion_max_records = 1000; |
| 1534 |
|
| 1535 |
/* |
| 1536 |
* There is a variable rl_completion_query_items for this but apparently |
| 1537 |
* it's not defined everywhere. |
| 1538 |
*/ |
| 1539 |
} |
| 1540 |
|
| 1541 |
/* |
| 1542 |
* Check if 'word' matches any of the '|'-separated strings in 'pattern', |
| 1543 |
* using case-insensitive or case-sensitive comparisons. |
| 1544 |
* |
| 1545 |
* If pattern is NULL, it's a wild card that matches any word. |
| 1546 |
* If pattern begins with '!', the result is negated, ie we check that 'word' |
| 1547 |
* does *not* match any alternative appearing in the rest of 'pattern'. |
| 1548 |
* Any alternative can contain '*' which is a wild card, i.e., it can match |
| 1549 |
* any substring; however, we allow at most one '*' per alternative. |
| 1550 |
* |
| 1551 |
* For readability, callers should use the macros MatchAny and MatchAnyExcept |
| 1552 |
* to invoke those two special cases for 'pattern'. (But '|' and '*' must |
| 1553 |
* just be written directly in patterns.) There is also MatchAnyN, but that |
| 1554 |
* is supported only in Matches/MatchesCS and is not handled here. |
| 1555 |
*/ |
| 1556 |
static bool |
| 1557 |
word_matches(const char *pattern, |
| 1558 |
const char *word, |
| 1559 |
bool case_sensitive) |
| 1560 |
{ |
| 1561 |
size_t wordlen; |
| 1562 |
|
| 1563 |
#define cimatch(s1, s2, n) \ |
| 1564 |
(case_sensitive ? strncmp(s1, s2, n) == 0 : pg_strncasecmp(s1, s2, n) == 0) |
| 1565 |
|
| 1566 |
/* NULL pattern matches anything. */ |
| 1567 |
if (pattern == NULL) |
| 1568 |
return true; |
| 1569 |
|
| 1570 |
/* Handle negated patterns from the MatchAnyExcept macro. */ |
| 1571 |
if (*pattern == '!') |
| 1572 |
return !word_matches(pattern + 1, word, case_sensitive); |
| 1573 |
|
| 1574 |
/* Else consider each alternative in the pattern. */ |
| 1575 |
wordlen = strlen(word); |
| 1576 |
for (;;) |
| 1577 |
{ |
| 1578 |
const char *star = NULL; |
| 1579 |
const char *c; |
| 1580 |
|
| 1581 |
/* Find end of current alternative, and locate any wild card. */ |
| 1582 |
c = pattern; |
| 1583 |
while (*c != '\0' && *c != '|') |
| 1584 |
{ |
| 1585 |
if (*c == '*') |
| 1586 |
star = c; |
| 1587 |
c++; |
| 1588 |
} |
| 1589 |
/* Was there a wild card? */ |
| 1590 |
if (star) |
| 1591 |
{ |
| 1592 |
/* Yes, wildcard match? */ |
| 1593 |
size_t beforelen = star - pattern, |
| 1594 |
afterlen = c - star - 1; |
| 1595 |
|
| 1596 |
if (wordlen >= (beforelen + afterlen) && |
| 1597 |
cimatch(word, pattern, beforelen) && |
| 1598 |
cimatch(word + wordlen - afterlen, star + 1, afterlen)) |
| 1599 |
return true; |
| 1600 |
} |
| 1601 |
else |
| 1602 |
{ |
| 1603 |
/* No, plain match? */ |
| 1604 |
if (wordlen == (c - pattern) && |
| 1605 |
cimatch(word, pattern, wordlen)) |
| 1606 |
return true; |
| 1607 |
} |
| 1608 |
/* Out of alternatives? */ |
| 1609 |
if (*c == '\0') |
| 1610 |
break; |
| 1611 |
/* Nope, try next alternative. */ |
| 1612 |
pattern = c + 1; |
| 1613 |
} |
| 1614 |
|
| 1615 |
return false; |
| 1616 |
} |
| 1617 |
|
| 1618 |
/* |
| 1619 |
* Implementation of TailMatches and TailMatchesCS tests: do the last N words |
| 1620 |
* in previous_words match the pattern arguments? |
| 1621 |
* |
| 1622 |
* The array indexing might look backwards, but remember that |
| 1623 |
* previous_words[0] contains the *last* word on the line, not the first. |
| 1624 |
*/ |
| 1625 |
static bool |
| 1626 |
TailMatchesArray(bool case_sensitive, |
| 1627 |
int previous_words_count, char **previous_words, |
| 1628 |
int narg, const char *const *args) |
| 1629 |
{ |
| 1630 |
if (previous_words_count < narg) |
| 1631 |
return false; |
| 1632 |
|
| 1633 |
for (int argno = 0; argno < narg; argno++) |
| 1634 |
{ |
| 1635 |
const char *arg = args[argno]; |
| 1636 |
|
| 1637 |
if (!word_matches(arg, previous_words[narg - argno - 1], |
| 1638 |
case_sensitive)) |
| 1639 |
return false; |
| 1640 |
} |
| 1641 |
|
| 1642 |
return true; |
| 1643 |
} |
| 1644 |
|
| 1645 |
/* |
| 1646 |
* As above, but the pattern is passed as a variadic argument list. |
| 1647 |
*/ |
| 1648 |
static bool |
| 1649 |
TailMatchesImpl(bool case_sensitive, |
| 1650 |
int previous_words_count, char **previous_words, |
| 1651 |
int narg,...) |
| 1652 |
{ |
| 1653 |
const char *argarray[64]; |
| 1654 |
va_list args; |
| 1655 |
|
| 1656 |
Assert(narg <= lengthof(argarray)); |
| 1657 |
|
| 1658 |
if (previous_words_count < narg) |
| 1659 |
return false; |
| 1660 |
|
| 1661 |
va_start(args, narg); |
| 1662 |
for (int argno = 0; argno < narg; argno++) |
| 1663 |
argarray[argno] = va_arg(args, const char *); |
| 1664 |
va_end(args); |
| 1665 |
|
| 1666 |
return TailMatchesArray(case_sensitive, |
| 1667 |
previous_words_count, previous_words, |
| 1668 |
narg, argarray); |
| 1669 |
} |
| 1670 |
|
| 1671 |
/* |
| 1672 |
* Implementation of HeadMatches and HeadMatchesCS tests: do the first N |
| 1673 |
* words in previous_words match the pattern arguments? |
| 1674 |
*/ |
| 1675 |
static bool |
| 1676 |
HeadMatchesArray(bool case_sensitive, |
| 1677 |
int previous_words_count, char **previous_words, |
| 1678 |
int narg, const char *const *args) |
| 1679 |
{ |
| 1680 |
if (previous_words_count < narg) |
| 1681 |
return false; |
| 1682 |
|
| 1683 |
for (int argno = 0; argno < narg; argno++) |
| 1684 |
{ |
| 1685 |
const char *arg = args[argno]; |
| 1686 |
|
| 1687 |
if (!word_matches(arg, previous_words[previous_words_count - argno - 1], |
| 1688 |
case_sensitive)) |
| 1689 |
return false; |
| 1690 |
} |
| 1691 |
|
| 1692 |
return true; |
| 1693 |
} |
| 1694 |
|
| 1695 |
/* |
| 1696 |
* As above, but the pattern is passed as a variadic argument list. |
| 1697 |
*/ |
| 1698 |
static bool |
| 1699 |
HeadMatchesImpl(bool case_sensitive, |
| 1700 |
int previous_words_count, char **previous_words, |
| 1701 |
int narg,...) |
| 1702 |
{ |
| 1703 |
const char *argarray[64]; |
| 1704 |
va_list args; |
| 1705 |
|
| 1706 |
Assert(narg <= lengthof(argarray)); |
| 1707 |
|
| 1708 |
if (previous_words_count < narg) |
| 1709 |
return false; |
| 1710 |
|
| 1711 |
va_start(args, narg); |
| 1712 |
for (int argno = 0; argno < narg; argno++) |
| 1713 |
argarray[argno] = va_arg(args, const char *); |
| 1714 |
va_end(args); |
| 1715 |
|
| 1716 |
return HeadMatchesArray(case_sensitive, |
| 1717 |
previous_words_count, previous_words, |
| 1718 |
narg, argarray); |
| 1719 |
} |
| 1720 |
|
| 1721 |
/* |
| 1722 |
* Implementation of Matches and MatchesCS tests: do all of the words |
| 1723 |
* in previous_words match the pattern arguments? |
| 1724 |
* |
| 1725 |
* This supports an additional kind of wildcard: MatchAnyN (represented as "") |
| 1726 |
* can match any number of words, including zero, in the middle of the list. |
| 1727 |
*/ |
| 1728 |
static bool |
| 1729 |
MatchesArray(bool case_sensitive, |
| 1730 |
int previous_words_count, char **previous_words, |
| 1731 |
int narg, const char *const *args) |
| 1732 |
{ |
| 1733 |
int match_any_pos = -1; |
| 1734 |
|
| 1735 |
/* Even with MatchAnyN, there must be at least N-1 words */ |
| 1736 |
if (previous_words_count < narg - 1) |
| 1737 |
return false; |
| 1738 |
|
| 1739 |
/* Check for MatchAnyN */ |
| 1740 |
for (int argno = 0; argno < narg; argno++) |
| 1741 |
{ |
| 1742 |
const char *arg = args[argno]; |
| 1743 |
|
| 1744 |
if (arg != NULL && arg[0] == '\0') |
| 1745 |
{ |
| 1746 |
match_any_pos = argno; |
| 1747 |
break; |
| 1748 |
} |
| 1749 |
} |
| 1750 |
|
| 1751 |
if (match_any_pos < 0) |
| 1752 |
{ |
| 1753 |
/* Standard case without MatchAnyN */ |
| 1754 |
if (previous_words_count != narg) |
| 1755 |
return false; |
| 1756 |
|
| 1757 |
/* Either Head or Tail match will do for the rest */ |
| 1758 |
if (!HeadMatchesArray(case_sensitive, |
| 1759 |
previous_words_count, previous_words, |
| 1760 |
narg, args)) |
| 1761 |
return false; |
| 1762 |
} |
| 1763 |
else |
| 1764 |
{ |
| 1765 |
/* Match against head */ |
| 1766 |
if (!HeadMatchesArray(case_sensitive, |
| 1767 |
previous_words_count, previous_words, |
| 1768 |
match_any_pos, args)) |
| 1769 |
return false; |
| 1770 |
|
| 1771 |
/* Match against tail */ |
| 1772 |
if (!TailMatchesArray(case_sensitive, |
| 1773 |
previous_words_count, previous_words, |
| 1774 |
narg - match_any_pos - 1, |
| 1775 |
args + match_any_pos + 1)) |
| 1776 |
return false; |
| 1777 |
} |
| 1778 |
|
| 1779 |
return true; |
| 1780 |
} |
| 1781 |
|
| 1782 |
/* |
| 1783 |
* As above, but the pattern is passed as a variadic argument list. |
| 1784 |
*/ |
| 1785 |
static bool |
| 1786 |
MatchesImpl(bool case_sensitive, |
| 1787 |
int previous_words_count, char **previous_words, |
| 1788 |
int narg,...) |
| 1789 |
{ |
| 1790 |
const char *argarray[64]; |
| 1791 |
va_list args; |
| 1792 |
|
| 1793 |
Assert(narg <= lengthof(argarray)); |
| 1794 |
|
| 1795 |
/* Even with MatchAnyN, there must be at least N-1 words */ |
| 1796 |
if (previous_words_count < narg - 1) |
| 1797 |
return false; |
| 1798 |
|
| 1799 |
va_start(args, narg); |
| 1800 |
for (int argno = 0; argno < narg; argno++) |
| 1801 |
argarray[argno] = va_arg(args, const char *); |
| 1802 |
va_end(args); |
| 1803 |
|
| 1804 |
return MatchesArray(case_sensitive, |
| 1805 |
previous_words_count, previous_words, |
| 1806 |
narg, argarray); |
| 1807 |
} |
| 1808 |
|
| 1809 |
/* |
| 1810 |
* Check if the final character of 's' is 'c'. |
| 1811 |
*/ |
| 1812 |
static bool |
| 1813 |
ends_with(const char *s, char c) |
| 1814 |
{ |
| 1815 |
size_t length = strlen(s); |
| 1816 |
|
| 1817 |
return (length > 0 && s[length - 1] == c); |
| 1818 |
} |
| 1819 |
|
| 1820 |
/* |
| 1821 |
* The completion function. |
| 1822 |
* |
| 1823 |
* According to readline spec this gets passed the text entered so far and its |
| 1824 |
* start and end positions in the readline buffer. The return value is some |
| 1825 |
* partially obscure list format that can be generated by readline's |
| 1826 |
* rl_completion_matches() function, so we don't have to worry about it. |
| 1827 |
*/ |
| 1828 |
static char ** |
| 1829 |
psql_completion(const char *text, int start, int end) |
| 1830 |
{ |
| 1831 |
/* This is the variable we'll return. */ |
| 1832 |
char **matches = NULL; |
| 1833 |
|
| 1834 |
/* Workspace for parsed words. */ |
| 1835 |
char *words_buffer; |
| 1836 |
|
| 1837 |
/* This array will contain pointers to parsed words. */ |
| 1838 |
char **previous_words; |
| 1839 |
|
| 1840 |
/* The number of words found on the input line. */ |
| 1841 |
int previous_words_count; |
| 1842 |
|
| 1843 |
/* |
| 1844 |
* For compactness, we use these macros to reference previous_words[]. |
| 1845 |
* Caution: do not access a previous_words[] entry without having checked |
| 1846 |
* previous_words_count to be sure it's valid. In most cases below, that |
| 1847 |
* check is implicit in a TailMatches() or similar macro, but in some |
| 1848 |
* places we have to check it explicitly. |
| 1849 |
*/ |
| 1850 |
#define prev_wd (previous_words[0]) |
| 1851 |
#define prev2_wd (previous_words[1]) |
| 1852 |
#define prev3_wd (previous_words[2]) |
| 1853 |
#define prev4_wd (previous_words[3]) |
| 1854 |
#define prev5_wd (previous_words[4]) |
| 1855 |
#define prev6_wd (previous_words[5]) |
| 1856 |
#define prev7_wd (previous_words[6]) |
| 1857 |
#define prev8_wd (previous_words[7]) |
| 1858 |
#define prev9_wd (previous_words[8]) |
| 1859 |
|
| 1860 |
/* Match the last N words before point, case-insensitively. */ |
| 1861 |
#define TailMatches(...) \ |
| 1862 |
TailMatchesImpl(false, previous_words_count, previous_words, \ |
| 1863 |
VA_ARGS_NARGS(__VA_ARGS__), __VA_ARGS__) |
| 1864 |
|
| 1865 |
/* Match the last N words before point, case-sensitively. */ |
| 1866 |
#define TailMatchesCS(...) \ |
| 1867 |
TailMatchesImpl(true, previous_words_count, previous_words, \ |
| 1868 |
VA_ARGS_NARGS(__VA_ARGS__), __VA_ARGS__) |
| 1869 |
|
| 1870 |
/* Match N words representing all of the line, case-insensitively. */ |
| 1871 |
#define Matches(...) \ |
| 1872 |
MatchesImpl(false, previous_words_count, previous_words, \ |
| 1873 |
VA_ARGS_NARGS(__VA_ARGS__), __VA_ARGS__) |
| 1874 |
|
| 1875 |
/* Match N words representing all of the line, case-sensitively. */ |
| 1876 |
#define MatchesCS(...) \ |
| 1877 |
MatchesImpl(true, previous_words_count, previous_words, \ |
| 1878 |
VA_ARGS_NARGS(__VA_ARGS__), __VA_ARGS__) |
| 1879 |
|
| 1880 |
/* Match the first N words on the line, case-insensitively. */ |
| 1881 |
#define HeadMatches(...) \ |
| 1882 |
HeadMatchesImpl(false, previous_words_count, previous_words, \ |
| 1883 |
VA_ARGS_NARGS(__VA_ARGS__), __VA_ARGS__) |
| 1884 |
|
| 1885 |
/* Match the first N words on the line, case-sensitively. */ |
| 1886 |
#define HeadMatchesCS(...) \ |
| 1887 |
HeadMatchesImpl(true, previous_words_count, previous_words, \ |
| 1888 |
VA_ARGS_NARGS(__VA_ARGS__), __VA_ARGS__) |
| 1889 |
|
| 1890 |
/* psql's backslash commands. */ |
| 1891 |
static const char *const backslash_commands[] = { |
| 1892 |
"\\a", |
| 1893 |
"\\bind", "\\bind_named", |
| 1894 |
"\\connect", "\\conninfo", "\\C", "\\cd", "\\close_prepared", "\\copy", |
| 1895 |
"\\copyright", "\\crosstabview", |
| 1896 |
"\\d", "\\da", "\\dA", "\\dAc", "\\dAf", "\\dAo", "\\dAp", |
| 1897 |
"\\db", "\\dc", "\\dconfig", "\\dC", "\\dd", "\\ddp", "\\dD", |
| 1898 |
"\\des", "\\det", "\\deu", "\\dew", "\\dE", "\\df", |
| 1899 |
"\\dF", "\\dFd", "\\dFp", "\\dFt", "\\dg", "\\di", "\\dl", "\\dL", |
| 1900 |
"\\dm", "\\dn", "\\do", "\\dO", "\\dp", "\\dP", "\\dPi", "\\dPt", |
| 1901 |
"\\drds", "\\drg", "\\dRs", "\\dRp", "\\ds", |
| 1902 |
"\\dt", "\\dT", "\\dv", "\\du", "\\dx", "\\dX", "\\dy", |
| 1903 |
"\\echo", "\\edit", "\\ef", "\\elif", "\\else", "\\encoding", |
| 1904 |
"\\endif", "\\endpipeline", "\\errverbose", "\\ev", |
| 1905 |
"\\f", "\\flush", "\\flushrequest", |
| 1906 |
"\\g", "\\gdesc", "\\getenv", "\\getresults", "\\gexec", "\\gset", "\\gx", |
| 1907 |
"\\help", "\\html", |
| 1908 |
"\\if", "\\include", "\\include_relative", "\\ir", |
| 1909 |
"\\list", "\\lo_import", "\\lo_export", "\\lo_list", "\\lo_unlink", |
| 1910 |
"\\out", |
| 1911 |
"\\parse", "\\password", "\\print", "\\prompt", "\\pset", |
| 1912 |
"\\qecho", "\\quit", |
| 1913 |
"\\reset", "\\restrict", |
| 1914 |
"\\s", "\\sendpipeline", "\\set", "\\setenv", "\\sf", |
| 1915 |
"\\startpipeline", "\\sv", "\\syncpipeline", |
| 1916 |
"\\t", "\\T", "\\timing", |
| 1917 |
"\\unrestrict", "\\unset", |
| 1918 |
"\\x", |
| 1919 |
"\\warn", "\\watch", "\\write", |
| 1920 |
"\\z", |
| 1921 |
"\\!", "\\?", |
| 1922 |
NULL |
| 1923 |
}; |
| 1924 |
|
| 1925 |
/* |
| 1926 |
* Temporary workaround for a bug in recent (2019) libedit: it incorrectly |
| 1927 |
* de-escapes the input "text", causing us to fail to recognize backslash |
| 1928 |
* commands. So get the string to look at from rl_line_buffer instead. |
| 1929 |
*/ |
| 1930 |
char *text_copy = pnstrdup(rl_line_buffer + start, end - start); |
| 1931 |
text = text_copy; |
| 1932 |
|
| 1933 |
/* Remember last char of the given input word. */ |
| 1934 |
completion_last_char = (end > start) ? text[end - start - 1] : '\0'; |
| 1935 |
|
| 1936 |
/* We usually want the append character to be a space. */ |
| 1937 |
rl_completion_append_character = ' '; |
| 1938 |
|
| 1939 |
/* Clear a few things. */ |
| 1940 |
completion_charp = NULL; |
| 1941 |
completion_charpp = NULL; |
| 1942 |
completion_vquery = NULL; |
| 1943 |
completion_squery = NULL; |
| 1944 |
completion_ref_object = NULL; |
| 1945 |
completion_ref_schema = NULL; |
| 1946 |
|
| 1947 |
/* |
| 1948 |
* Scan the input line to extract the words before our current position. |
| 1949 |
* According to those we'll make some smart decisions on what the user is |
| 1950 |
* probably intending to type. |
| 1951 |
*/ |
| 1952 |
previous_words = get_previous_words(start, |
| 1953 |
&words_buffer, |
| 1954 |
&previous_words_count); |
| 1955 |
|
| 1956 |
/* If current word is a backslash command, offer completions for that */ |
| 1957 |
if (text[0] == '\\') |
| 1958 |
COMPLETE_WITH_LIST_CS(backslash_commands); |
| 1959 |
|
| 1960 |
/* If current word is a variable interpolation, handle that case */ |
| 1961 |
else if (text[0] == ':' && text[1] != ':') |
| 1962 |
{ |
| 1963 |
if (text[1] == '\'') |
| 1964 |
matches = complete_from_variables(text, ":'", "'", true); |
| 1965 |
else if (text[1] == '"') |
| 1966 |
matches = complete_from_variables(text, ":\"", "\"", true); |
| 1967 |
else if (text[1] == '{' && text[2] == '?') |
| 1968 |
matches = complete_from_variables(text, ":{?", "}", true); |
| 1969 |
else |
| 1970 |
matches = complete_from_variables(text, ":", "", true); |
| 1971 |
} |
| 1972 |
|
| 1973 |
/* If no previous word, suggest one of the basic sql commands */ |
| 1974 |
else if (previous_words_count == 0) |
| 1975 |
COMPLETE_WITH_LIST(sql_commands); |
| 1976 |
|
| 1977 |
/* Else try completions based on matching patterns of previous words */ |
| 1978 |
else |
| 1979 |
{ |
| 1980 |
#ifdef SWITCH_CONVERSION_APPLIED |
| 1981 |
/* |
| 1982 |
* If we have transformed match_previous_words into a switch, iterate |
| 1983 |
* through tcpatterns[] to see which pattern ids match. |
| 1984 |
* |
| 1985 |
* For now, we have to try the patterns in the order they are stored |
| 1986 |
* (matching the order of switch cases in match_previous_words), |
| 1987 |
* because some of the logic in match_previous_words assumes that |
| 1988 |
* previous matches have been eliminated. This is fairly |
| 1989 |
* unprincipled, and it is likely that there are undesirable as well |
| 1990 |
* as desirable interactions hidden in the order of the pattern |
| 1991 |
* checks. TODO: think about a better way to manage that. |
| 1992 |
*/ |
| 1993 |
for (int tindx = 0; tindx < lengthof(tcpatterns); tindx++) |
| 1994 |
{ |
| 1995 |
const TCPattern *tcpat = tcpatterns + tindx; |
| 1996 |
bool match = false; |
| 1997 |
|
| 1998 |
switch (tcpat->kind) |
| 1999 |
{ |
| 2000 |
case Match: |
| 2001 |
match = MatchesArray(false, |
| 2002 |
previous_words_count, |
| 2003 |
previous_words, |
| 2004 |
tcpat->nwords, tcpat->words); |
| 2005 |
break; |
| 2006 |
case MatchCS: |
| 2007 |
match = MatchesArray(true, |
| 2008 |
previous_words_count, |
| 2009 |
previous_words, |
| 2010 |
tcpat->nwords, tcpat->words); |
| 2011 |
break; |
| 2012 |
case HeadMatch: |
| 2013 |
match = HeadMatchesArray(false, |
| 2014 |
previous_words_count, |
| 2015 |
previous_words, |
| 2016 |
tcpat->nwords, tcpat->words); |
| 2017 |
break; |
| 2018 |
case HeadMatchCS: |
| 2019 |
match = HeadMatchesArray(true, |
| 2020 |
previous_words_count, |
| 2021 |
previous_words, |
| 2022 |
tcpat->nwords, tcpat->words); |
| 2023 |
break; |
| 2024 |
case TailMatch: |
| 2025 |
match = TailMatchesArray(false, |
| 2026 |
previous_words_count, |
| 2027 |
previous_words, |
| 2028 |
tcpat->nwords, tcpat->words); |
| 2029 |
break; |
| 2030 |
case TailMatchCS: |
| 2031 |
match = TailMatchesArray(true, |
| 2032 |
previous_words_count, |
| 2033 |
previous_words, |
| 2034 |
tcpat->nwords, tcpat->words); |
| 2035 |
break; |
| 2036 |
} |
| 2037 |
if (match) |
| 2038 |
{ |
| 2039 |
matches = match_previous_words(tcpat->id, text, start, end, |
| 2040 |
previous_words, |
| 2041 |
previous_words_count); |
| 2042 |
if (matches != NULL) |
| 2043 |
break; |
| 2044 |
} |
| 2045 |
} |
| 2046 |
#else /* !SWITCH_CONVERSION_APPLIED */ |
| 2047 |
/* |
| 2048 |
* If gen_tabcomplete.pl hasn't been applied to this code, just let |
| 2049 |
* match_previous_words scan through all its patterns. |
| 2050 |
*/ |
| 2051 |
matches = match_previous_words(0, text, start, end, |
| 2052 |
previous_words, |
| 2053 |
previous_words_count); |
| 2054 |
#endif /* SWITCH_CONVERSION_APPLIED */ |
| 2055 |
} |
| 2056 |
|
| 2057 |
/* |
| 2058 |
* Finally, we look through the list of "things", such as TABLE, INDEX and |
| 2059 |
* check if that was the previous word. If so, execute the query to get a |
| 2060 |
* list of them. |
| 2061 |
*/ |
| 2062 |
if (matches == NULL && previous_words_count > 0) |
| 2063 |
{ |
| 2064 |
const pgsql_thing_t *wac; |
| 2065 |
|
| 2066 |
for (wac = words_after_create; wac->name != NULL; wac++) |
| 2067 |
{ |
| 2068 |
if (pg_strcasecmp(prev_wd, wac->name) == 0) |
| 2069 |
{ |
| 2070 |
if (wac->query) |
| 2071 |
COMPLETE_WITH_QUERY_LIST(wac->query, |
| 2072 |
wac->keywords); |
| 2073 |
else if (wac->vquery) |
| 2074 |
COMPLETE_WITH_VERSIONED_QUERY_LIST(wac->vquery, |
| 2075 |
wac->keywords); |
| 2076 |
else if (wac->squery) |
| 2077 |
COMPLETE_WITH_VERSIONED_SCHEMA_QUERY_LIST(wac->squery, |
| 2078 |
wac->keywords); |
| 2079 |
break; |
| 2080 |
} |
| 2081 |
} |
| 2082 |
} |
| 2083 |
|
| 2084 |
/* |
| 2085 |
* If we still don't have anything to match we have to fabricate some sort |
| 2086 |
* of default list. If we were to just return NULL, readline automatically |
| 2087 |
* attempts filename completion, and that's usually no good. |
| 2088 |
*/ |
| 2089 |
if (matches == NULL) |
| 2090 |
{ |
| 2091 |
COMPLETE_WITH_CONST(true, ""); |
| 2092 |
/* Also, prevent Readline from appending stuff to the non-match */ |
| 2093 |
rl_completion_append_character = '\0'; |
| 2094 |
#ifdef HAVE_RL_COMPLETION_SUPPRESS_QUOTE |
| 2095 |
rl_completion_suppress_quote = 1; |
| 2096 |
#endif |
| 2097 |
} |
| 2098 |
|
| 2099 |
/* free storage */ |
| 2100 |
free(previous_words); |
| 2101 |
free(words_buffer); |
| 2102 |
free(text_copy); |
| 2103 |
free(completion_ref_object); |
| 2104 |
completion_ref_object = NULL; |
| 2105 |
free(completion_ref_schema); |
| 2106 |
completion_ref_schema = NULL; |
| 2107 |
|
| 2108 |
/* Return our Grand List O' Matches */ |
| 2109 |
return matches; |
| 2110 |
} |
| 2111 |
|
| 2112 |
/* |
| 2113 |
* Subroutine to try matches based on previous_words. |
| 2114 |
* |
| 2115 |
* This can operate in one of two modes. As presented, the body of the |
| 2116 |
* function is a long if-else-if chain that sequentially tries each known |
| 2117 |
* match rule. That works, but some C compilers have trouble with such a long |
| 2118 |
* else-if chain, either taking extra time to compile or failing altogether. |
| 2119 |
* Therefore, we prefer to transform the else-if chain into a switch, and then |
| 2120 |
* each call of this function considers just one match rule (under control of |
| 2121 |
* a loop in psql_completion()). Compilers tend to be more ready to deal |
| 2122 |
* with many-arm switches than many-arm else-if chains. |
| 2123 |
* |
| 2124 |
* Each if-condition in this function must begin with a call of one of the |
| 2125 |
* functions Matches, HeadMatches, TailMatches, MatchesCS, HeadMatchesCS, or |
| 2126 |
* TailMatchesCS. The preprocessor gen_tabcomplete.pl strips out those |
| 2127 |
* calls and converts them into entries in tcpatterns[], which are evaluated |
| 2128 |
* by the calling loop in psql_completion(). Successful matches result in |
| 2129 |
* calls to this function with the appropriate pattern_id, causing just the |
| 2130 |
* corresponding switch case to be executed. |
| 2131 |
* |
| 2132 |
* If-conditions in this function can be more complex than a single *Matches |
| 2133 |
* function call in one of two ways (but not both!). They can be OR's |
| 2134 |
* of *Matches calls, such as |
| 2135 |
* else if (Matches("ALTER", "VIEW", MatchAny, "ALTER", MatchAny) || |
| 2136 |
* Matches("ALTER", "VIEW", MatchAny, "ALTER", "COLUMN", MatchAny)) |
| 2137 |
* or they can be a *Matches call AND'ed with some other condition, e.g. |
| 2138 |
* else if (Matches("CREATE", "PUBLICATION", MatchAny, "FOR", "TABLE", MatchAny) && |
| 2139 |
* !ends_with(prev_wd, ',')) |
| 2140 |
* The former case is transformed into multiple tcpatterns[] entries and |
| 2141 |
* multiple case labels for the same bit of code. The latter case is |
| 2142 |
* transformed into a case label and a contained if-statement. |
| 2143 |
* |
| 2144 |
* This is split out of psql_completion() primarily to separate code that |
| 2145 |
* gen_tabcomplete.pl should process from code that it should not, although |
| 2146 |
* doing so also helps to avoid extra indentation of this code. |
| 2147 |
* |
| 2148 |
* Returns a matches list, or NULL if no match. |
| 2149 |
*/ |
| 2150 |
static char ** |
| 2151 |
match_previous_words(int pattern_id, |
| 2152 |
const char *text, int start, int end, |
| 2153 |
char **previous_words, int previous_words_count) |
| 2154 |
{ |
| 2155 |
/* This is the variable we'll return. */ |
| 2156 |
char **matches = NULL; |
| 2157 |
|
| 2158 |
/* Dummy statement, allowing all the match rules to look like "else if" */ |
| 2159 |
if (0) |
| 2160 |
{ |
| 2161 |
/* skip */ |
| 2162 |
} |
| 2163 |
|
| 2164 |
/* gen_tabcomplete.pl begins special processing here */ |
| 2165 |
/* BEGIN GEN_TABCOMPLETE */ |
| 2166 |
|
| 2167 |
/* CREATE */ |
| 2168 |
/* complete with something you can create */ |
| 2169 |
else if (TailMatches("CREATE")) |
| 2170 |
{ |
| 2171 |
/* only some object types can be created as part of CREATE SCHEMA */ |
| 2172 |
if (HeadMatches("CREATE", "SCHEMA")) |
| 2173 |
COMPLETE_WITH("TABLE", "VIEW", "INDEX", "SEQUENCE", "TRIGGER", |
| 2174 |
/* for INDEX and TABLE/SEQUENCE, respectively */ |
| 2175 |
"UNIQUE", "UNLOGGED"); |
| 2176 |
else |
| 2177 |
matches = rl_completion_matches(text, create_command_generator); |
| 2178 |
} |
| 2179 |
/* complete with something you can create or replace */ |
| 2180 |
else if (TailMatches("CREATE", "OR", "REPLACE")) |
| 2181 |
COMPLETE_WITH("FUNCTION", "PROCEDURE", "LANGUAGE", "RULE", "VIEW", |
| 2182 |
"AGGREGATE", "TRANSFORM", "TRIGGER"); |
| 2183 |
|
| 2184 |
/* DROP, but not DROP embedded in other commands */ |
| 2185 |
/* complete with something you can drop */ |
| 2186 |
else if (Matches("DROP")) |
| 2187 |
matches = rl_completion_matches(text, drop_command_generator); |
| 2188 |
|
| 2189 |
/* ALTER */ |
| 2190 |
|
| 2191 |
/* ALTER TABLE */ |
| 2192 |
else if (Matches("ALTER", "TABLE")) |
| 2193 |
COMPLETE_WITH_SCHEMA_QUERY_PLUS(Query_for_list_of_tables, |
| 2194 |
"ALL IN TABLESPACE"); |
| 2195 |
|
| 2196 |
/* ALTER something */ |
| 2197 |
else if (Matches("ALTER")) |
| 2198 |
matches = rl_completion_matches(text, alter_command_generator); |
| 2199 |
/* ALTER TABLE,INDEX,MATERIALIZED VIEW ALL IN TABLESPACE xxx */ |
| 2200 |
else if (TailMatches("ALL", "IN", "TABLESPACE", MatchAny)) |
| 2201 |
COMPLETE_WITH("SET TABLESPACE", "OWNED BY"); |
| 2202 |
/* ALTER TABLE,INDEX,MATERIALIZED VIEW ALL IN TABLESPACE xxx OWNED BY */ |
| 2203 |
else if (TailMatches("ALL", "IN", "TABLESPACE", MatchAny, "OWNED", "BY")) |
| 2204 |
COMPLETE_WITH_QUERY(Query_for_list_of_roles); |
| 2205 |
/* ALTER TABLE,INDEX,MATERIALIZED VIEW ALL IN TABLESPACE xxx OWNED BY xxx */ |
| 2206 |
else if (TailMatches("ALL", "IN", "TABLESPACE", MatchAny, "OWNED", "BY", MatchAny)) |
| 2207 |
COMPLETE_WITH("SET TABLESPACE"); |
| 2208 |
/* ALTER AGGREGATE,FUNCTION,PROCEDURE,ROUTINE <name> */ |
| 2209 |
else if (Matches("ALTER", "AGGREGATE|FUNCTION|PROCEDURE|ROUTINE", MatchAny)) |
| 2210 |
COMPLETE_WITH("("); |
| 2211 |
/* ALTER AGGREGATE <name> (...) */ |
| 2212 |
else if (Matches("ALTER", "AGGREGATE", MatchAny, MatchAny)) |
| 2213 |
{ |
| 2214 |
if (ends_with(prev_wd, ')')) |
| 2215 |
COMPLETE_WITH("OWNER TO", "RENAME TO", "SET SCHEMA"); |
| 2216 |
else |
| 2217 |
COMPLETE_WITH_FUNCTION_ARG(prev2_wd); |
| 2218 |
} |
| 2219 |
/* ALTER FUNCTION <name> (...) */ |
| 2220 |
else if (Matches("ALTER", "FUNCTION", MatchAny, MatchAny)) |
| 2221 |
{ |
| 2222 |
if (ends_with(prev_wd, ')')) |
| 2223 |
COMPLETE_WITH(Alter_function_options); |
| 2224 |
else |
| 2225 |
COMPLETE_WITH_FUNCTION_ARG(prev2_wd); |
| 2226 |
} |
| 2227 |
/* ALTER PROCEDURE <name> (...) */ |
| 2228 |
else if (Matches("ALTER", "PROCEDURE", MatchAny, MatchAny)) |
| 2229 |
{ |
| 2230 |
if (ends_with(prev_wd, ')')) |
| 2231 |
COMPLETE_WITH(Alter_procedure_options); |
| 2232 |
else |
| 2233 |
COMPLETE_WITH_FUNCTION_ARG(prev2_wd); |
| 2234 |
} |
| 2235 |
/* ALTER ROUTINE <name> (...) */ |
| 2236 |
else if (Matches("ALTER", "ROUTINE", MatchAny, MatchAny)) |
| 2237 |
{ |
| 2238 |
if (ends_with(prev_wd, ')')) |
| 2239 |
COMPLETE_WITH(Alter_routine_options); |
| 2240 |
else |
| 2241 |
COMPLETE_WITH_FUNCTION_ARG(prev2_wd); |
| 2242 |
} |
| 2243 |
/* ALTER FUNCTION|ROUTINE <name> (...) PARALLEL */ |
| 2244 |
else if (Matches("ALTER", "FUNCTION|ROUTINE", MatchAny, MatchAny, "PARALLEL")) |
| 2245 |
COMPLETE_WITH("RESTRICTED", "SAFE", "UNSAFE"); |
| 2246 |
/* ALTER FUNCTION|PROCEDURE|ROUTINE <name> (...) [EXTERNAL] SECURITY */ |
| 2247 |
else if (Matches("ALTER", "FUNCTION|PROCEDURE|ROUTINE", MatchAny, MatchAny, "SECURITY") || |
| 2248 |
Matches("ALTER", "FUNCTION|PROCEDURE|ROUTINE", MatchAny, MatchAny, "EXTERNAL", "SECURITY")) |
| 2249 |
COMPLETE_WITH("DEFINER", "INVOKER"); |
| 2250 |
/* ALTER FUNCTION|PROCEDURE|ROUTINE <name> (...) RESET */ |
| 2251 |
else if (Matches("ALTER", "FUNCTION|PROCEDURE|ROUTINE", MatchAny, MatchAny, "RESET")) |
| 2252 |
COMPLETE_WITH_QUERY_VERBATIM_PLUS(Query_for_list_of_set_vars, |
| 2253 |
"ALL"); |
| 2254 |
/* ALTER FUNCTION|PROCEDURE|ROUTINE <name> (...) SET */ |
| 2255 |
else if (Matches("ALTER", "FUNCTION|PROCEDURE|ROUTINE", MatchAny, MatchAny, "SET")) |
| 2256 |
COMPLETE_WITH_QUERY_VERBATIM_PLUS(Query_for_list_of_set_vars, |
| 2257 |
"SCHEMA"); |
| 2258 |
|
| 2259 |
/* ALTER PUBLICATION <name> */ |
| 2260 |
else if (Matches("ALTER", "PUBLICATION", MatchAny)) |
| 2261 |
COMPLETE_WITH("ADD", "DROP", "OWNER TO", "RENAME TO", "SET"); |
| 2262 |
/* ALTER PUBLICATION <name> ADD */ |
| 2263 |
else if (Matches("ALTER", "PUBLICATION", MatchAny, "ADD")) |
| 2264 |
COMPLETE_WITH("TABLES IN SCHEMA", "TABLE"); |
| 2265 |
else if (Matches("ALTER", "PUBLICATION", MatchAny, "ADD|SET", "TABLE")) |
| 2266 |
COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_tables); |
| 2267 |
else if (HeadMatches("ALTER", "PUBLICATION", MatchAny, "ADD|SET", "TABLE") && |
| 2268 |
ends_with(prev_wd, ',')) |
| 2269 |
COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_tables); |
| 2270 |
|
| 2271 |
/* |
| 2272 |
* "ALTER PUBLICATION <name> SET TABLE <name> WHERE (" - complete with |
| 2273 |
* table attributes |
| 2274 |
* |
| 2275 |
* "ALTER PUBLICATION <name> ADD TABLE <name> WHERE (" - complete with |
| 2276 |
* table attributes |
| 2277 |
*/ |
| 2278 |
else if (Matches("ALTER", "PUBLICATION", MatchAny, MatchAnyN, "WHERE")) |
| 2279 |
COMPLETE_WITH("("); |
| 2280 |
else if (Matches("ALTER", "PUBLICATION", MatchAny, MatchAnyN, "WHERE", "(")) |
| 2281 |
COMPLETE_WITH_ATTR(prev3_wd); |
| 2282 |
else if (HeadMatches("ALTER", "PUBLICATION", MatchAny, "ADD|SET", "TABLE") && |
| 2283 |
!TailMatches("WHERE", "(*)")) |
| 2284 |
COMPLETE_WITH(",", "WHERE ("); |
| 2285 |
else if (HeadMatches("ALTER", "PUBLICATION", MatchAny, "ADD|SET", "TABLE")) |
| 2286 |
COMPLETE_WITH(","); |
| 2287 |
/* ALTER PUBLICATION <name> DROP */ |
| 2288 |
else if (Matches("ALTER", "PUBLICATION", MatchAny, "DROP")) |
| 2289 |
COMPLETE_WITH("TABLES IN SCHEMA", "TABLE"); |
| 2290 |
/* ALTER PUBLICATION <name> SET */ |
| 2291 |
else if (Matches("ALTER", "PUBLICATION", MatchAny, "SET")) |
| 2292 |
COMPLETE_WITH("(", "TABLES IN SCHEMA", "TABLE"); |
| 2293 |
else if (Matches("ALTER", "PUBLICATION", MatchAny, "ADD|DROP|SET", "TABLES", "IN", "SCHEMA")) |
| 2294 |
COMPLETE_WITH_QUERY_PLUS(Query_for_list_of_schemas |
| 2295 |
" AND nspname NOT LIKE E'pg\\\\_%%'", |
| 2296 |
"CURRENT_SCHEMA"); |
| 2297 |
/* ALTER PUBLICATION <name> SET ( */ |
| 2298 |
else if (Matches("ALTER", "PUBLICATION", MatchAny, MatchAnyN, "SET", "(")) |
| 2299 |
COMPLETE_WITH("publish", "publish_generated_columns", "publish_via_partition_root"); |
| 2300 |
/* ALTER SUBSCRIPTION <name> */ |
| 2301 |
else if (Matches("ALTER", "SUBSCRIPTION", MatchAny)) |
| 2302 |
COMPLETE_WITH("CONNECTION", "ENABLE", "DISABLE", "OWNER TO", |
| 2303 |
"RENAME TO", "REFRESH PUBLICATION", "SET", "SKIP (", |
| 2304 |
"ADD PUBLICATION", "DROP PUBLICATION"); |
| 2305 |
/* ALTER SUBSCRIPTION <name> REFRESH PUBLICATION */ |
| 2306 |
else if (Matches("ALTER", "SUBSCRIPTION", MatchAny, MatchAnyN, "REFRESH", "PUBLICATION")) |
| 2307 |
COMPLETE_WITH("WITH ("); |
| 2308 |
/* ALTER SUBSCRIPTION <name> REFRESH PUBLICATION WITH ( */ |
| 2309 |
else if (Matches("ALTER", "SUBSCRIPTION", MatchAny, MatchAnyN, "REFRESH", "PUBLICATION", "WITH", "(")) |
| 2310 |
COMPLETE_WITH("copy_data"); |
| 2311 |
/* ALTER SUBSCRIPTION <name> SET */ |
| 2312 |
else if (Matches("ALTER", "SUBSCRIPTION", MatchAny, "SET")) |
| 2313 |
COMPLETE_WITH("(", "PUBLICATION"); |
| 2314 |
/* ALTER SUBSCRIPTION <name> SET ( */ |
| 2315 |
else if (Matches("ALTER", "SUBSCRIPTION", MatchAny, MatchAnyN, "SET", "(")) |
| 2316 |
COMPLETE_WITH("binary", "disable_on_error", "failover", "origin", |
| 2317 |
"password_required", "run_as_owner", "slot_name", |
| 2318 |
"streaming", "synchronous_commit", "two_phase"); |
| 2319 |
/* ALTER SUBSCRIPTION <name> SKIP ( */ |
| 2320 |
else if (Matches("ALTER", "SUBSCRIPTION", MatchAny, MatchAnyN, "SKIP", "(")) |
| 2321 |
COMPLETE_WITH("lsn"); |
| 2322 |
/* ALTER SUBSCRIPTION <name> SET PUBLICATION */ |
| 2323 |
else if (Matches("ALTER", "SUBSCRIPTION", MatchAny, MatchAnyN, "SET", "PUBLICATION")) |
| 2324 |
{ |
| 2325 |
/* complete with nothing here as this refers to remote publications */ |
| 2326 |
} |
| 2327 |
/* ALTER SUBSCRIPTION <name> ADD|DROP|SET PUBLICATION <name> */ |
| 2328 |
else if (Matches("ALTER", "SUBSCRIPTION", MatchAny, MatchAnyN, |
| 2329 |
"ADD|DROP|SET", "PUBLICATION", MatchAny)) |
| 2330 |
COMPLETE_WITH("WITH ("); |
| 2331 |
/* ALTER SUBSCRIPTION <name> ADD|DROP|SET PUBLICATION <name> WITH ( */ |
| 2332 |
else if (Matches("ALTER", "SUBSCRIPTION", MatchAny, MatchAnyN, |
| 2333 |
"ADD|DROP|SET", "PUBLICATION", MatchAny, "WITH", "(")) |
| 2334 |
COMPLETE_WITH("copy_data", "refresh"); |
| 2335 |
|
| 2336 |
/* ALTER SCHEMA <name> */ |
| 2337 |
else if (Matches("ALTER", "SCHEMA", MatchAny)) |
| 2338 |
COMPLETE_WITH("OWNER TO", "RENAME TO"); |
| 2339 |
|
| 2340 |
/* ALTER COLLATION <name> */ |
| 2341 |
else if (Matches("ALTER", "COLLATION", MatchAny)) |
| 2342 |
COMPLETE_WITH("OWNER TO", "REFRESH VERSION", "RENAME TO", "SET SCHEMA"); |
| 2343 |
|
| 2344 |
/* ALTER CONVERSION <name> */ |
| 2345 |
else if (Matches("ALTER", "CONVERSION", MatchAny)) |
| 2346 |
COMPLETE_WITH("OWNER TO", "RENAME TO", "SET SCHEMA"); |
| 2347 |
|
| 2348 |
/* ALTER DATABASE <name> */ |
| 2349 |
else if (Matches("ALTER", "DATABASE", MatchAny)) |
| 2350 |
COMPLETE_WITH("RESET", "SET", "OWNER TO", "REFRESH COLLATION VERSION", "RENAME TO", |
| 2351 |
"IS_TEMPLATE", "ALLOW_CONNECTIONS", |
| 2352 |
"CONNECTION LIMIT"); |
| 2353 |
|
| 2354 |
/* ALTER DATABASE <name> RESET */ |
| 2355 |
else if (Matches("ALTER", "DATABASE", MatchAny, "RESET")) |
| 2356 |
{ |
| 2357 |
set_completion_reference(prev2_wd); |
| 2358 |
COMPLETE_WITH_QUERY_PLUS(Query_for_list_of_database_vars, "ALL"); |
| 2359 |
} |
| 2360 |
|
| 2361 |
/* ALTER DATABASE <name> SET TABLESPACE */ |
| 2362 |
else if (Matches("ALTER", "DATABASE", MatchAny, "SET", "TABLESPACE")) |
| 2363 |
COMPLETE_WITH_QUERY(Query_for_list_of_tablespaces); |
| 2364 |
|
| 2365 |
/* ALTER EVENT TRIGGER */ |
| 2366 |
else if (Matches("ALTER", "EVENT", "TRIGGER")) |
| 2367 |
COMPLETE_WITH_QUERY(Query_for_list_of_event_triggers); |
| 2368 |
|
| 2369 |
/* ALTER EVENT TRIGGER <name> */ |
| 2370 |
else if (Matches("ALTER", "EVENT", "TRIGGER", MatchAny)) |
| 2371 |
COMPLETE_WITH("DISABLE", "ENABLE", "OWNER TO", "RENAME TO"); |
| 2372 |
|
| 2373 |
/* ALTER EVENT TRIGGER <name> ENABLE */ |
| 2374 |
else if (Matches("ALTER", "EVENT", "TRIGGER", MatchAny, "ENABLE")) |
| 2375 |
COMPLETE_WITH("REPLICA", "ALWAYS"); |
| 2376 |
|
| 2377 |
/* ALTER EXTENSION <name> */ |
| 2378 |
else if (Matches("ALTER", "EXTENSION", MatchAny)) |
| 2379 |
COMPLETE_WITH("ADD", "DROP", "UPDATE", "SET SCHEMA"); |
| 2380 |
|
| 2381 |
/* ALTER EXTENSION <name> ADD|DROP */ |
| 2382 |
else if (Matches("ALTER", "EXTENSION", MatchAny, "ADD|DROP")) |
| 2383 |
COMPLETE_WITH("ACCESS METHOD", "AGGREGATE", "CAST", "COLLATION", |
| 2384 |
"CONVERSION", "DOMAIN", "EVENT TRIGGER", "FOREIGN", |
| 2385 |
"FUNCTION", "MATERIALIZED VIEW", "OPERATOR", |
| 2386 |
"LANGUAGE", "PROCEDURE", "ROUTINE", "SCHEMA", |
| 2387 |
"SEQUENCE", "SERVER", "TABLE", "TEXT SEARCH", |
| 2388 |
"TRANSFORM FOR", "TYPE", "VIEW"); |
| 2389 |
|
| 2390 |
/* ALTER EXTENSION <name> ADD|DROP FOREIGN */ |
| 2391 |
else if (Matches("ALTER", "EXTENSION", MatchAny, "ADD|DROP", "FOREIGN")) |
| 2392 |
COMPLETE_WITH("DATA WRAPPER", "TABLE"); |
| 2393 |
|
| 2394 |
/* ALTER EXTENSION <name> ADD|DROP OPERATOR */ |
| 2395 |
else if (Matches("ALTER", "EXTENSION", MatchAny, "ADD|DROP", "OPERATOR")) |
| 2396 |
COMPLETE_WITH("CLASS", "FAMILY"); |
| 2397 |
|
| 2398 |
/* ALTER EXTENSION <name> ADD|DROP TEXT SEARCH */ |
| 2399 |
else if (Matches("ALTER", "EXTENSION", MatchAny, "ADD|DROP", "TEXT", "SEARCH")) |
| 2400 |
COMPLETE_WITH("CONFIGURATION", "DICTIONARY", "PARSER", "TEMPLATE"); |
| 2401 |
|
| 2402 |
/* ALTER EXTENSION <name> UPDATE */ |
| 2403 |
else if (Matches("ALTER", "EXTENSION", MatchAny, "UPDATE")) |
| 2404 |
COMPLETE_WITH("TO"); |
| 2405 |
|
| 2406 |
/* ALTER EXTENSION <name> UPDATE TO */ |
| 2407 |
else if (Matches("ALTER", "EXTENSION", MatchAny, "UPDATE", "TO")) |
| 2408 |
{ |
| 2409 |
set_completion_reference(prev3_wd); |
| 2410 |
COMPLETE_WITH_QUERY(Query_for_list_of_available_extension_versions); |
| 2411 |
} |
| 2412 |
|
| 2413 |
/* ALTER FOREIGN */ |
| 2414 |
else if (Matches("ALTER", "FOREIGN")) |
| 2415 |
COMPLETE_WITH("DATA WRAPPER", "TABLE"); |
| 2416 |
|
| 2417 |
/* ALTER FOREIGN DATA WRAPPER <name> */ |
| 2418 |
else if (Matches("ALTER", "FOREIGN", "DATA", "WRAPPER", MatchAny)) |
| 2419 |
COMPLETE_WITH("HANDLER", "VALIDATOR", "NO", |
| 2420 |
"OPTIONS", "OWNER TO", "RENAME TO"); |
| 2421 |
else if (Matches("ALTER", "FOREIGN", "DATA", "WRAPPER", MatchAny, "NO")) |
| 2422 |
COMPLETE_WITH("HANDLER", "VALIDATOR"); |
| 2423 |
|
| 2424 |
/* ALTER FOREIGN TABLE <name> */ |
| 2425 |
else if (Matches("ALTER", "FOREIGN", "TABLE", MatchAny)) |
| 2426 |
COMPLETE_WITH("ADD", "ALTER", "DISABLE TRIGGER", "DROP", "ENABLE", |
| 2427 |
"INHERIT", "NO INHERIT", "OPTIONS", "OWNER TO", |
| 2428 |
"RENAME", "SET", "VALIDATE CONSTRAINT"); |
| 2429 |
|
| 2430 |
/* ALTER INDEX */ |
| 2431 |
else if (Matches("ALTER", "INDEX")) |
| 2432 |
COMPLETE_WITH_SCHEMA_QUERY_PLUS(Query_for_list_of_indexes, |
| 2433 |
"ALL IN TABLESPACE"); |
| 2434 |
/* ALTER INDEX <name> */ |
| 2435 |
else if (Matches("ALTER", "INDEX", MatchAny)) |
| 2436 |
COMPLETE_WITH("ALTER COLUMN", "OWNER TO", "RENAME TO", "SET", |
| 2437 |
"RESET", "ATTACH PARTITION", |
| 2438 |
"DEPENDS ON EXTENSION", "NO DEPENDS ON EXTENSION"); |
| 2439 |
else if (Matches("ALTER", "INDEX", MatchAny, "ATTACH")) |
| 2440 |
COMPLETE_WITH("PARTITION"); |
| 2441 |
else if (Matches("ALTER", "INDEX", MatchAny, "ATTACH", "PARTITION")) |
| 2442 |
COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_indexes); |
| 2443 |
/* ALTER INDEX <name> ALTER */ |
| 2444 |
else if (Matches("ALTER", "INDEX", MatchAny, "ALTER")) |
| 2445 |
COMPLETE_WITH("COLUMN"); |
| 2446 |
/* ALTER INDEX <name> ALTER COLUMN */ |
| 2447 |
else if (Matches("ALTER", "INDEX", MatchAny, "ALTER", "COLUMN")) |
| 2448 |
{ |
| 2449 |
set_completion_reference(prev3_wd); |
| 2450 |
COMPLETE_WITH_SCHEMA_QUERY_VERBATIM(Query_for_list_of_attribute_numbers); |
| 2451 |
} |
| 2452 |
/* ALTER INDEX <name> ALTER COLUMN <colnum> */ |
| 2453 |
else if (Matches("ALTER", "INDEX", MatchAny, "ALTER", "COLUMN", MatchAny)) |
| 2454 |
COMPLETE_WITH("SET STATISTICS"); |
| 2455 |
/* ALTER INDEX <name> ALTER COLUMN <colnum> SET */ |
| 2456 |
else if (Matches("ALTER", "INDEX", MatchAny, "ALTER", "COLUMN", MatchAny, "SET")) |
| 2457 |
COMPLETE_WITH("STATISTICS"); |
| 2458 |
/* ALTER INDEX <name> ALTER COLUMN <colnum> SET STATISTICS */ |
| 2459 |
else if (Matches("ALTER", "INDEX", MatchAny, "ALTER", "COLUMN", MatchAny, "SET", "STATISTICS")) |
| 2460 |
{ |
| 2461 |
/* Enforce no completion here, as an integer has to be specified */ |
| 2462 |
} |
| 2463 |
/* ALTER INDEX <name> SET */ |
| 2464 |
else if (Matches("ALTER", "INDEX", MatchAny, "SET")) |
| 2465 |
COMPLETE_WITH("(", "TABLESPACE"); |
| 2466 |
/* ALTER INDEX <name> RESET */ |
| 2467 |
else if (Matches("ALTER", "INDEX", MatchAny, "RESET")) |
| 2468 |
COMPLETE_WITH("("); |
| 2469 |
/* ALTER INDEX <foo> SET|RESET ( */ |
| 2470 |
else if (Matches("ALTER", "INDEX", MatchAny, "RESET", "(")) |
| 2471 |
COMPLETE_WITH("fillfactor", |
| 2472 |
"deduplicate_items", /* BTREE */ |
| 2473 |
"fastupdate", "gin_pending_list_limit", /* GIN */ |
| 2474 |
"buffering", /* GiST */ |
| 2475 |
"pages_per_range", "autosummarize" /* BRIN */ |
| 2476 |
); |
| 2477 |
else if (Matches("ALTER", "INDEX", MatchAny, "SET", "(")) |
| 2478 |
COMPLETE_WITH("fillfactor =", |
| 2479 |
"deduplicate_items =", /* BTREE */ |
| 2480 |
"fastupdate =", "gin_pending_list_limit =", /* GIN */ |
| 2481 |
"buffering =", /* GiST */ |
| 2482 |
"pages_per_range =", "autosummarize =" /* BRIN */ |
| 2483 |
); |
| 2484 |
else if (Matches("ALTER", "INDEX", MatchAny, "NO", "DEPENDS")) |
| 2485 |
COMPLETE_WITH("ON EXTENSION"); |
| 2486 |
else if (Matches("ALTER", "INDEX", MatchAny, "DEPENDS")) |
| 2487 |
COMPLETE_WITH("ON EXTENSION"); |
| 2488 |
|
| 2489 |
/* ALTER LANGUAGE <name> */ |
| 2490 |
else if (Matches("ALTER", "LANGUAGE", MatchAny)) |
| 2491 |
COMPLETE_WITH("OWNER TO", "RENAME TO"); |
| 2492 |
|
| 2493 |
/* ALTER LARGE OBJECT <oid> */ |
| 2494 |
else if (Matches("ALTER", "LARGE", "OBJECT", MatchAny)) |
| 2495 |
COMPLETE_WITH("OWNER TO"); |
| 2496 |
|
| 2497 |
/* ALTER MATERIALIZED VIEW */ |
| 2498 |
else if (Matches("ALTER", "MATERIALIZED", "VIEW")) |
| 2499 |
COMPLETE_WITH_SCHEMA_QUERY_PLUS(Query_for_list_of_matviews, |
| 2500 |
"ALL IN TABLESPACE"); |
| 2501 |
|
| 2502 |
/* ALTER USER,ROLE <name> */ |
| 2503 |
else if (Matches("ALTER", "USER|ROLE", MatchAny) && |
| 2504 |
!TailMatches("USER", "MAPPING")) |
| 2505 |
COMPLETE_WITH("BYPASSRLS", "CONNECTION LIMIT", "CREATEDB", "CREATEROLE", |
| 2506 |
"ENCRYPTED PASSWORD", "INHERIT", "LOGIN", "NOBYPASSRLS", |
| 2507 |
"NOCREATEDB", "NOCREATEROLE", "NOINHERIT", |
| 2508 |
"NOLOGIN", "NOREPLICATION", "NOSUPERUSER", "PASSWORD", |
| 2509 |
"RENAME TO", "REPLICATION", "RESET", "SET", "SUPERUSER", |
| 2510 |
"VALID UNTIL", "WITH"); |
| 2511 |
|
| 2512 |
/* ALTER USER,ROLE <name> RESET */ |
| 2513 |
else if (Matches("ALTER", "USER|ROLE", MatchAny, "RESET")) |
| 2514 |
{ |
| 2515 |
set_completion_reference(prev2_wd); |
| 2516 |
COMPLETE_WITH_QUERY_PLUS(Query_for_list_of_user_vars, "ALL"); |
| 2517 |
} |
| 2518 |
|
| 2519 |
/* ALTER USER,ROLE <name> WITH */ |
| 2520 |
else if (Matches("ALTER", "USER|ROLE", MatchAny, "WITH")) |
| 2521 |
/* Similar to the above, but don't complete "WITH" again. */ |
| 2522 |
COMPLETE_WITH("BYPASSRLS", "CONNECTION LIMIT", "CREATEDB", "CREATEROLE", |
| 2523 |
"ENCRYPTED PASSWORD", "INHERIT", "LOGIN", "NOBYPASSRLS", |
| 2524 |
"NOCREATEDB", "NOCREATEROLE", "NOINHERIT", |
| 2525 |
"NOLOGIN", "NOREPLICATION", "NOSUPERUSER", "PASSWORD", |
| 2526 |
"RENAME TO", "REPLICATION", "RESET", "SET", "SUPERUSER", |
| 2527 |
"VALID UNTIL"); |
| 2528 |
|
| 2529 |
/* ALTER DEFAULT PRIVILEGES */ |
| 2530 |
else if (Matches("ALTER", "DEFAULT", "PRIVILEGES")) |
| 2531 |
COMPLETE_WITH("FOR", "GRANT", "IN SCHEMA", "REVOKE"); |
| 2532 |
/* ALTER DEFAULT PRIVILEGES FOR */ |
| 2533 |
else if (Matches("ALTER", "DEFAULT", "PRIVILEGES", "FOR")) |
| 2534 |
COMPLETE_WITH("ROLE"); |
| 2535 |
/* ALTER DEFAULT PRIVILEGES IN */ |
| 2536 |
else if (Matches("ALTER", "DEFAULT", "PRIVILEGES", "IN")) |
| 2537 |
COMPLETE_WITH("SCHEMA"); |
| 2538 |
/* ALTER DEFAULT PRIVILEGES FOR ROLE|USER ... */ |
| 2539 |
else if (Matches("ALTER", "DEFAULT", "PRIVILEGES", "FOR", "ROLE|USER", |
| 2540 |
MatchAny)) |
| 2541 |
COMPLETE_WITH("GRANT", "REVOKE", "IN SCHEMA"); |
| 2542 |
/* ALTER DEFAULT PRIVILEGES IN SCHEMA ... */ |
| 2543 |
else if (Matches("ALTER", "DEFAULT", "PRIVILEGES", "IN", "SCHEMA", |
| 2544 |
MatchAny)) |
| 2545 |
COMPLETE_WITH("GRANT", "REVOKE", "FOR ROLE"); |
| 2546 |
/* ALTER DEFAULT PRIVILEGES IN SCHEMA ... FOR */ |
| 2547 |
else if (Matches("ALTER", "DEFAULT", "PRIVILEGES", "IN", "SCHEMA", |
| 2548 |
MatchAny, "FOR")) |
| 2549 |
COMPLETE_WITH("ROLE"); |
| 2550 |
/* ALTER DEFAULT PRIVILEGES FOR ROLE|USER ... IN SCHEMA ... */ |
| 2551 |
/* ALTER DEFAULT PRIVILEGES IN SCHEMA ... FOR ROLE|USER ... */ |
| 2552 |
else if (Matches("ALTER", "DEFAULT", "PRIVILEGES", "FOR", "ROLE|USER", |
| 2553 |
MatchAny, "IN", "SCHEMA", MatchAny) || |
| 2554 |
Matches("ALTER", "DEFAULT", "PRIVILEGES", "IN", "SCHEMA", |
| 2555 |
MatchAny, "FOR", "ROLE|USER", MatchAny)) |
| 2556 |
COMPLETE_WITH("GRANT", "REVOKE"); |
| 2557 |
/* ALTER DOMAIN <name> */ |
| 2558 |
else if (Matches("ALTER", "DOMAIN", MatchAny)) |
| 2559 |
COMPLETE_WITH("ADD", "DROP", "OWNER TO", "RENAME", "SET", |
| 2560 |
"VALIDATE CONSTRAINT"); |
| 2561 |
/* ALTER DOMAIN <sth> ADD */ |
| 2562 |
else if (Matches("ALTER", "DOMAIN", MatchAny, "ADD")) |
| 2563 |
COMPLETE_WITH("CONSTRAINT", "NOT NULL", "CHECK ("); |
| 2564 |
/* ALTER DOMAIN <sth> ADD CONSTRAINT <sth> */ |
| 2565 |
else if (Matches("ALTER", "DOMAIN", MatchAny, "ADD", "CONSTRAINT", MatchAny)) |
| 2566 |
COMPLETE_WITH("NOT NULL", "CHECK ("); |
| 2567 |
/* ALTER DOMAIN <sth> DROP */ |
| 2568 |
else if (Matches("ALTER", "DOMAIN", MatchAny, "DROP")) |
| 2569 |
COMPLETE_WITH("CONSTRAINT", "DEFAULT", "NOT NULL"); |
| 2570 |
/* ALTER DOMAIN <sth> DROP|RENAME|VALIDATE CONSTRAINT */ |
| 2571 |
else if (Matches("ALTER", "DOMAIN", MatchAny, "DROP|RENAME|VALIDATE", "CONSTRAINT")) |
| 2572 |
{ |
| 2573 |
set_completion_reference(prev3_wd); |
| 2574 |
COMPLETE_WITH_SCHEMA_QUERY(Query_for_constraint_of_type); |
| 2575 |
} |
| 2576 |
/* ALTER DOMAIN <sth> RENAME */ |
| 2577 |
else if (Matches("ALTER", "DOMAIN", MatchAny, "RENAME")) |
| 2578 |
COMPLETE_WITH("CONSTRAINT", "TO"); |
| 2579 |
/* ALTER DOMAIN <sth> RENAME CONSTRAINT <sth> */ |
| 2580 |
else if (Matches("ALTER", "DOMAIN", MatchAny, "RENAME", "CONSTRAINT", MatchAny)) |
| 2581 |
COMPLETE_WITH("TO"); |
| 2582 |
|
| 2583 |
/* ALTER DOMAIN <sth> SET */ |
| 2584 |
else if (Matches("ALTER", "DOMAIN", MatchAny, "SET")) |
| 2585 |
COMPLETE_WITH("DEFAULT", "NOT NULL", "SCHEMA"); |
| 2586 |
/* ALTER SEQUENCE <name> */ |
| 2587 |
else if (Matches("ALTER", "SEQUENCE", MatchAny)) |
| 2588 |
COMPLETE_WITH("AS", "INCREMENT", "MINVALUE", "MAXVALUE", "RESTART", |
| 2589 |
"START", "NO", "CACHE", "CYCLE", "SET", "OWNED BY", |
| 2590 |
"OWNER TO", "RENAME TO"); |
| 2591 |
/* ALTER SEQUENCE <name> AS */ |
| 2592 |
else if (TailMatches("ALTER", "SEQUENCE", MatchAny, "AS")) |
| 2593 |
COMPLETE_WITH_CS("smallint", "integer", "bigint"); |
| 2594 |
/* ALTER SEQUENCE <name> NO */ |
| 2595 |
else if (Matches("ALTER", "SEQUENCE", MatchAny, "NO")) |
| 2596 |
COMPLETE_WITH("MINVALUE", "MAXVALUE", "CYCLE"); |
| 2597 |
/* ALTER SEQUENCE <name> SET */ |
| 2598 |
else if (Matches("ALTER", "SEQUENCE", MatchAny, "SET")) |
| 2599 |
COMPLETE_WITH("SCHEMA", "LOGGED", "UNLOGGED"); |
| 2600 |
/* ALTER SERVER <name> */ |
| 2601 |
else if (Matches("ALTER", "SERVER", MatchAny)) |
| 2602 |
COMPLETE_WITH("VERSION", "OPTIONS", "OWNER TO", "RENAME TO"); |
| 2603 |
/* ALTER SERVER <name> VERSION <version> */ |
| 2604 |
else if (Matches("ALTER", "SERVER", MatchAny, "VERSION", MatchAny)) |
| 2605 |
COMPLETE_WITH("OPTIONS"); |
| 2606 |
/* ALTER SYSTEM SET, RESET, RESET ALL */ |
| 2607 |
else if (Matches("ALTER", "SYSTEM")) |
| 2608 |
COMPLETE_WITH("SET", "RESET"); |
| 2609 |
else if (Matches("ALTER", "SYSTEM", "SET|RESET")) |
| 2610 |
COMPLETE_WITH_QUERY_VERBATIM_PLUS(Query_for_list_of_alter_system_set_vars, |
| 2611 |
"ALL"); |
| 2612 |
else if (Matches("ALTER", "SYSTEM", "SET", MatchAny)) |
| 2613 |
COMPLETE_WITH("TO"); |
| 2614 |
/* ALTER VIEW <name> */ |
| 2615 |
else if (Matches("ALTER", "VIEW", MatchAny)) |
| 2616 |
COMPLETE_WITH("ALTER COLUMN", "OWNER TO", "RENAME", "RESET", "SET"); |
| 2617 |
/* ALTER VIEW xxx RENAME */ |
| 2618 |
else if (Matches("ALTER", "VIEW", MatchAny, "RENAME")) |
| 2619 |
COMPLETE_WITH_ATTR_PLUS(prev2_wd, "COLUMN", "TO"); |
| 2620 |
else if (Matches("ALTER", "VIEW", MatchAny, "ALTER|RENAME", "COLUMN")) |
| 2621 |
COMPLETE_WITH_ATTR(prev3_wd); |
| 2622 |
/* ALTER VIEW xxx ALTER [ COLUMN ] yyy */ |
| 2623 |
else if (Matches("ALTER", "VIEW", MatchAny, "ALTER", MatchAny) || |
| 2624 |
Matches("ALTER", "VIEW", MatchAny, "ALTER", "COLUMN", MatchAny)) |
| 2625 |
COMPLETE_WITH("SET DEFAULT", "DROP DEFAULT"); |
| 2626 |
/* ALTER VIEW xxx RENAME yyy */ |
| 2627 |
else if (Matches("ALTER", "VIEW", MatchAny, "RENAME", MatchAnyExcept("TO"))) |
| 2628 |
COMPLETE_WITH("TO"); |
| 2629 |
/* ALTER VIEW xxx RENAME COLUMN yyy */ |
| 2630 |
else if (Matches("ALTER", "VIEW", MatchAny, "RENAME", "COLUMN", MatchAnyExcept("TO"))) |
| 2631 |
COMPLETE_WITH("TO"); |
| 2632 |
/* ALTER VIEW xxx RESET ( */ |
| 2633 |
else if (Matches("ALTER", "VIEW", MatchAny, "RESET")) |
| 2634 |
COMPLETE_WITH("("); |
| 2635 |
/* Complete ALTER VIEW xxx SET with "(" or "SCHEMA" */ |
| 2636 |
else if (Matches("ALTER", "VIEW", MatchAny, "SET")) |
| 2637 |
COMPLETE_WITH("(", "SCHEMA"); |
| 2638 |
/* ALTER VIEW xxx SET|RESET ( yyy [= zzz] ) */ |
| 2639 |
else if (Matches("ALTER", "VIEW", MatchAny, "SET|RESET", "(")) |
| 2640 |
COMPLETE_WITH_LIST(view_optional_parameters); |
| 2641 |
else if (Matches("ALTER", "VIEW", MatchAny, "SET", "(", MatchAny)) |
| 2642 |
COMPLETE_WITH("="); |
| 2643 |
else if (Matches("ALTER", "VIEW", MatchAny, "SET", "(", "check_option", "=")) |
| 2644 |
COMPLETE_WITH("local", "cascaded"); |
| 2645 |
else if (Matches("ALTER", "VIEW", MatchAny, "SET", "(", "security_barrier|security_invoker", "=")) |
| 2646 |
COMPLETE_WITH("true", "false"); |
| 2647 |
|
| 2648 |
/* ALTER MATERIALIZED VIEW <name> */ |
| 2649 |
else if (Matches("ALTER", "MATERIALIZED", "VIEW", MatchAny)) |
| 2650 |
COMPLETE_WITH("ALTER COLUMN", "CLUSTER ON", "DEPENDS ON EXTENSION", |
| 2651 |
"NO DEPENDS ON EXTENSION", "OWNER TO", "RENAME", |
| 2652 |
"RESET (", "SET"); |
| 2653 |
/* ALTER MATERIALIZED VIEW xxx RENAME */ |
| 2654 |
else if (Matches("ALTER", "MATERIALIZED", "VIEW", MatchAny, "RENAME")) |
| 2655 |
COMPLETE_WITH_ATTR_PLUS(prev2_wd, "COLUMN", "TO"); |
| 2656 |
else if (Matches("ALTER", "MATERIALIZED", "VIEW", MatchAny, "ALTER|RENAME", "COLUMN")) |
| 2657 |
COMPLETE_WITH_ATTR(prev3_wd); |
| 2658 |
/* ALTER MATERIALIZED VIEW xxx RENAME yyy */ |
| 2659 |
else if (Matches("ALTER", "MATERIALIZED", "VIEW", MatchAny, "RENAME", MatchAnyExcept("TO"))) |
| 2660 |
COMPLETE_WITH("TO"); |
| 2661 |
/* ALTER MATERIALIZED VIEW xxx RENAME COLUMN yyy */ |
| 2662 |
else if (Matches("ALTER", "MATERIALIZED", "VIEW", MatchAny, "RENAME", "COLUMN", MatchAnyExcept("TO"))) |
| 2663 |
COMPLETE_WITH("TO"); |
| 2664 |
/* ALTER MATERIALIZED VIEW xxx SET */ |
| 2665 |
else if (Matches("ALTER", "MATERIALIZED", "VIEW", MatchAny, "SET")) |
| 2666 |
COMPLETE_WITH("(", "ACCESS METHOD", "SCHEMA", "TABLESPACE", "WITHOUT CLUSTER"); |
| 2667 |
/* ALTER MATERIALIZED VIEW xxx SET ACCESS METHOD */ |
| 2668 |
else if (Matches("ALTER", "MATERIALIZED", "VIEW", MatchAny, "SET", "ACCESS", "METHOD")) |
| 2669 |
COMPLETE_WITH_QUERY(Query_for_list_of_table_access_methods); |
| 2670 |
|
| 2671 |
/* ALTER POLICY <name> */ |
| 2672 |
else if (Matches("ALTER", "POLICY")) |
| 2673 |
COMPLETE_WITH_QUERY(Query_for_list_of_policies); |
| 2674 |
/* ALTER POLICY <name> ON */ |
| 2675 |
else if (Matches("ALTER", "POLICY", MatchAny)) |
| 2676 |
COMPLETE_WITH("ON"); |
| 2677 |
/* ALTER POLICY <name> ON <table> */ |
| 2678 |
else if (Matches("ALTER", "POLICY", MatchAny, "ON")) |
| 2679 |
{ |
| 2680 |
set_completion_reference(prev2_wd); |
| 2681 |
COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_tables_for_policy); |
| 2682 |
} |
| 2683 |
/* ALTER POLICY <name> ON <table> - show options */ |
| 2684 |
else if (Matches("ALTER", "POLICY", MatchAny, "ON", MatchAny)) |
| 2685 |
COMPLETE_WITH("RENAME TO", "TO", "USING (", "WITH CHECK ("); |
| 2686 |
/* ALTER POLICY <name> ON <table> TO <role> */ |
| 2687 |
else if (Matches("ALTER", "POLICY", MatchAny, "ON", MatchAny, "TO")) |
| 2688 |
COMPLETE_WITH_QUERY_PLUS(Query_for_list_of_roles, |
| 2689 |
Keywords_for_list_of_grant_roles); |
| 2690 |
/* ALTER POLICY <name> ON <table> USING ( */ |
| 2691 |
else if (Matches("ALTER", "POLICY", MatchAny, "ON", MatchAny, "USING")) |
| 2692 |
COMPLETE_WITH("("); |
| 2693 |
/* ALTER POLICY <name> ON <table> WITH CHECK ( */ |
| 2694 |
else if (Matches("ALTER", "POLICY", MatchAny, "ON", MatchAny, "WITH", "CHECK")) |
| 2695 |
COMPLETE_WITH("("); |
| 2696 |
|
| 2697 |
/* ALTER RULE <name>, add ON */ |
| 2698 |
else if (Matches("ALTER", "RULE", MatchAny)) |
| 2699 |
COMPLETE_WITH("ON"); |
| 2700 |
|
| 2701 |
/* If we have ALTER RULE <name> ON, then add the correct tablename */ |
| 2702 |
else if (Matches("ALTER", "RULE", MatchAny, "ON")) |
| 2703 |
{ |
| 2704 |
set_completion_reference(prev2_wd); |
| 2705 |
COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_tables_for_rule); |
| 2706 |
} |
| 2707 |
|
| 2708 |
/* ALTER RULE <name> ON <name> */ |
| 2709 |
else if (Matches("ALTER", "RULE", MatchAny, "ON", MatchAny)) |
| 2710 |
COMPLETE_WITH("RENAME TO"); |
| 2711 |
|
| 2712 |
/* ALTER STATISTICS <name> */ |
| 2713 |
else if (Matches("ALTER", "STATISTICS", MatchAny)) |
| 2714 |
COMPLETE_WITH("OWNER TO", "RENAME TO", "SET SCHEMA", "SET STATISTICS"); |
| 2715 |
/* ALTER STATISTICS <name> SET */ |
| 2716 |
else if (Matches("ALTER", "STATISTICS", MatchAny, "SET")) |
| 2717 |
COMPLETE_WITH("SCHEMA", "STATISTICS"); |
| 2718 |
|
| 2719 |
/* ALTER TRIGGER <name>, add ON */ |
| 2720 |
else if (Matches("ALTER", "TRIGGER", MatchAny)) |
| 2721 |
COMPLETE_WITH("ON"); |
| 2722 |
|
| 2723 |
else if (Matches("ALTER", "TRIGGER", MatchAny, "ON")) |
| 2724 |
{ |
| 2725 |
set_completion_reference(prev2_wd); |
| 2726 |
COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_tables_for_trigger); |
| 2727 |
} |
| 2728 |
|
| 2729 |
/* ALTER TRIGGER <name> ON <name> */ |
| 2730 |
else if (Matches("ALTER", "TRIGGER", MatchAny, "ON", MatchAny)) |
| 2731 |
COMPLETE_WITH("RENAME TO", "DEPENDS ON EXTENSION", |
| 2732 |
"NO DEPENDS ON EXTENSION"); |
| 2733 |
|
| 2734 |
/* |
| 2735 |
* If we detect ALTER TABLE <name>, suggest sub commands |
| 2736 |
*/ |
| 2737 |
else if (Matches("ALTER", "TABLE", MatchAny)) |
| 2738 |
COMPLETE_WITH("ADD", "ALTER", "CLUSTER ON", "DISABLE", "DROP", |
| 2739 |
"ENABLE", "INHERIT", "NO", "RENAME", "RESET", |
| 2740 |
"OWNER TO", "SET", "VALIDATE CONSTRAINT", |
| 2741 |
"REPLICA IDENTITY", "ATTACH PARTITION", |
| 2742 |
"DETACH PARTITION", "FORCE ROW LEVEL SECURITY", |
| 2743 |
"OF", "NOT OF"); |
| 2744 |
/* ALTER TABLE xxx ADD */ |
| 2745 |
else if (Matches("ALTER", "TABLE", MatchAny, "ADD")) |
| 2746 |
{ |
| 2747 |
/* make sure to keep this list and the !Matches() below in sync */ |
| 2748 |
COMPLETE_WITH("COLUMN", "CONSTRAINT", "CHECK", "UNIQUE", "PRIMARY KEY", |
| 2749 |
"EXCLUDE", "FOREIGN KEY"); |
| 2750 |
} |
| 2751 |
/* ALTER TABLE xxx ADD [COLUMN] yyy */ |
| 2752 |
else if (Matches("ALTER", "TABLE", MatchAny, "ADD", "COLUMN", MatchAny) || |
| 2753 |
Matches("ALTER", "TABLE", MatchAny, "ADD", MatchAnyExcept("COLUMN|CONSTRAINT|CHECK|UNIQUE|PRIMARY|EXCLUDE|FOREIGN"))) |
| 2754 |
COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_datatypes); |
| 2755 |
/* ALTER TABLE xxx ADD CONSTRAINT yyy */ |
| 2756 |
else if (Matches("ALTER", "TABLE", MatchAny, "ADD", "CONSTRAINT", MatchAny)) |
| 2757 |
COMPLETE_WITH("CHECK", "UNIQUE", "PRIMARY KEY", "EXCLUDE", "FOREIGN KEY"); |
| 2758 |
/* ALTER TABLE xxx ADD [CONSTRAINT yyy] (PRIMARY KEY|UNIQUE) */ |
| 2759 |
else if (Matches("ALTER", "TABLE", MatchAny, "ADD", "PRIMARY", "KEY") || |
| 2760 |
Matches("ALTER", "TABLE", MatchAny, "ADD", "UNIQUE") || |
| 2761 |
Matches("ALTER", "TABLE", MatchAny, "ADD", "CONSTRAINT", MatchAny, "PRIMARY", "KEY") || |
| 2762 |
Matches("ALTER", "TABLE", MatchAny, "ADD", "CONSTRAINT", MatchAny, "UNIQUE")) |
| 2763 |
COMPLETE_WITH("(", "USING INDEX"); |
| 2764 |
/* ALTER TABLE xxx ADD PRIMARY KEY USING INDEX */ |
| 2765 |
else if (Matches("ALTER", "TABLE", MatchAny, "ADD", "PRIMARY", "KEY", "USING", "INDEX")) |
| 2766 |
{ |
| 2767 |
set_completion_reference(prev6_wd); |
| 2768 |
COMPLETE_WITH_SCHEMA_QUERY(Query_for_unique_index_of_table); |
| 2769 |
} |
| 2770 |
/* ALTER TABLE xxx ADD UNIQUE USING INDEX */ |
| 2771 |
else if (Matches("ALTER", "TABLE", MatchAny, "ADD", "UNIQUE", "USING", "INDEX")) |
| 2772 |
{ |
| 2773 |
set_completion_reference(prev5_wd); |
| 2774 |
COMPLETE_WITH_SCHEMA_QUERY(Query_for_unique_index_of_table); |
| 2775 |
} |
| 2776 |
/* ALTER TABLE xxx ADD CONSTRAINT yyy PRIMARY KEY USING INDEX */ |
| 2777 |
else if (Matches("ALTER", "TABLE", MatchAny, "ADD", "CONSTRAINT", MatchAny, |
| 2778 |
"PRIMARY", "KEY", "USING", "INDEX")) |
| 2779 |
{ |
| 2780 |
set_completion_reference(prev8_wd); |
| 2781 |
COMPLETE_WITH_SCHEMA_QUERY(Query_for_unique_index_of_table); |
| 2782 |
} |
| 2783 |
/* ALTER TABLE xxx ADD CONSTRAINT yyy UNIQUE USING INDEX */ |
| 2784 |
else if (Matches("ALTER", "TABLE", MatchAny, "ADD", "CONSTRAINT", MatchAny, |
| 2785 |
"UNIQUE", "USING", "INDEX")) |
| 2786 |
{ |
| 2787 |
set_completion_reference(prev7_wd); |
| 2788 |
COMPLETE_WITH_SCHEMA_QUERY(Query_for_unique_index_of_table); |
| 2789 |
} |
| 2790 |
/* ALTER TABLE xxx ENABLE */ |
| 2791 |
else if (Matches("ALTER", "TABLE", MatchAny, "ENABLE")) |
| 2792 |
COMPLETE_WITH("ALWAYS", "REPLICA", "ROW LEVEL SECURITY", "RULE", |
| 2793 |
"TRIGGER"); |
| 2794 |
else if (Matches("ALTER", "TABLE", MatchAny, "ENABLE", "REPLICA|ALWAYS")) |
| 2795 |
COMPLETE_WITH("RULE", "TRIGGER"); |
| 2796 |
else if (Matches("ALTER", "TABLE", MatchAny, "ENABLE", "RULE")) |
| 2797 |
{ |
| 2798 |
set_completion_reference(prev3_wd); |
| 2799 |
COMPLETE_WITH_SCHEMA_QUERY(Query_for_rule_of_table); |
| 2800 |
} |
| 2801 |
else if (Matches("ALTER", "TABLE", MatchAny, "ENABLE", MatchAny, "RULE")) |
| 2802 |
{ |
| 2803 |
set_completion_reference(prev4_wd); |
| 2804 |
COMPLETE_WITH_SCHEMA_QUERY(Query_for_rule_of_table); |
| 2805 |
} |
| 2806 |
else if (Matches("ALTER", "TABLE", MatchAny, "ENABLE", "TRIGGER")) |
| 2807 |
{ |
| 2808 |
set_completion_reference(prev3_wd); |
| 2809 |
COMPLETE_WITH_SCHEMA_QUERY(Query_for_trigger_of_table); |
| 2810 |
} |
| 2811 |
else if (Matches("ALTER", "TABLE", MatchAny, "ENABLE", MatchAny, "TRIGGER")) |
| 2812 |
{ |
| 2813 |
set_completion_reference(prev4_wd); |
| 2814 |
COMPLETE_WITH_SCHEMA_QUERY(Query_for_trigger_of_table); |
| 2815 |
} |
| 2816 |
/* ALTER TABLE xxx INHERIT */ |
| 2817 |
else if (Matches("ALTER", "TABLE", MatchAny, "INHERIT")) |
| 2818 |
COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_tables); |
| 2819 |
/* ALTER TABLE xxx NO */ |
| 2820 |
else if (Matches("ALTER", "TABLE", MatchAny, "NO")) |
| 2821 |
COMPLETE_WITH("FORCE ROW LEVEL SECURITY", "INHERIT"); |
| 2822 |
/* ALTER TABLE xxx NO INHERIT */ |
| 2823 |
else if (Matches("ALTER", "TABLE", MatchAny, "NO", "INHERIT")) |
| 2824 |
COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_tables); |
| 2825 |
/* ALTER TABLE xxx DISABLE */ |
| 2826 |
else if (Matches("ALTER", "TABLE", MatchAny, "DISABLE")) |
| 2827 |
COMPLETE_WITH("ROW LEVEL SECURITY", "RULE", "TRIGGER"); |
| 2828 |
else if (Matches("ALTER", "TABLE", MatchAny, "DISABLE", "RULE")) |
| 2829 |
{ |
| 2830 |
set_completion_reference(prev3_wd); |
| 2831 |
COMPLETE_WITH_SCHEMA_QUERY(Query_for_rule_of_table); |
| 2832 |
} |
| 2833 |
else if (Matches("ALTER", "TABLE", MatchAny, "DISABLE", "TRIGGER")) |
| 2834 |
{ |
| 2835 |
set_completion_reference(prev3_wd); |
| 2836 |
COMPLETE_WITH_SCHEMA_QUERY(Query_for_trigger_of_table); |
| 2837 |
} |
| 2838 |
|
| 2839 |
/* ALTER TABLE xxx ALTER */ |
| 2840 |
else if (Matches("ALTER", "TABLE", MatchAny, "ALTER")) |
| 2841 |
COMPLETE_WITH_ATTR_PLUS(prev2_wd, "COLUMN", "CONSTRAINT"); |
| 2842 |
|
| 2843 |
/* ALTER TABLE xxx RENAME */ |
| 2844 |
else if (Matches("ALTER", "TABLE", MatchAny, "RENAME")) |
| 2845 |
COMPLETE_WITH_ATTR_PLUS(prev2_wd, "COLUMN", "CONSTRAINT", "TO"); |
| 2846 |
else if (Matches("ALTER", "TABLE", MatchAny, "ALTER|RENAME", "COLUMN")) |
| 2847 |
COMPLETE_WITH_ATTR(prev3_wd); |
| 2848 |
|
| 2849 |
/* ALTER TABLE xxx RENAME yyy */ |
| 2850 |
else if (Matches("ALTER", "TABLE", MatchAny, "RENAME", MatchAnyExcept("CONSTRAINT|TO"))) |
| 2851 |
COMPLETE_WITH("TO"); |
| 2852 |
|
| 2853 |
/* ALTER TABLE xxx RENAME COLUMN/CONSTRAINT yyy */ |
| 2854 |
else if (Matches("ALTER", "TABLE", MatchAny, "RENAME", "COLUMN|CONSTRAINT", MatchAnyExcept("TO"))) |
| 2855 |
COMPLETE_WITH("TO"); |
| 2856 |
|
| 2857 |
/* If we have ALTER TABLE <sth> DROP, provide COLUMN or CONSTRAINT */ |
| 2858 |
else if (Matches("ALTER", "TABLE", MatchAny, "DROP")) |
| 2859 |
COMPLETE_WITH("COLUMN", "CONSTRAINT"); |
| 2860 |
/* If we have ALTER TABLE <sth> DROP COLUMN, provide list of columns */ |
| 2861 |
else if (Matches("ALTER", "TABLE", MatchAny, "DROP", "COLUMN")) |
| 2862 |
COMPLETE_WITH_ATTR(prev3_wd); |
| 2863 |
/* ALTER TABLE <sth> ALTER|DROP|RENAME CONSTRAINT <constraint> */ |
| 2864 |
else if (Matches("ALTER", "TABLE", MatchAny, "ALTER|DROP|RENAME", "CONSTRAINT")) |
| 2865 |
{ |
| 2866 |
set_completion_reference(prev3_wd); |
| 2867 |
COMPLETE_WITH_SCHEMA_QUERY(Query_for_constraint_of_table); |
| 2868 |
} |
| 2869 |
/* ALTER TABLE <sth> VALIDATE CONSTRAINT <non-validated constraint> */ |
| 2870 |
else if (Matches("ALTER", "TABLE", MatchAny, "VALIDATE", "CONSTRAINT")) |
| 2871 |
{ |
| 2872 |
set_completion_reference(prev3_wd); |
| 2873 |
COMPLETE_WITH_SCHEMA_QUERY(Query_for_constraint_of_table_not_validated); |
| 2874 |
} |
| 2875 |
/* ALTER TABLE ALTER [COLUMN] <foo> */ |
| 2876 |
else if (Matches("ALTER", "TABLE", MatchAny, "ALTER", "COLUMN", MatchAny) || |
| 2877 |
Matches("ALTER", "TABLE", MatchAny, "ALTER", MatchAny)) |
| 2878 |
COMPLETE_WITH("TYPE", "SET", "RESET", "RESTART", "ADD", "DROP"); |
| 2879 |
/* ALTER TABLE ALTER [COLUMN] <foo> ADD */ |
| 2880 |
else if (Matches("ALTER", "TABLE", MatchAny, "ALTER", "COLUMN", MatchAny, "ADD") || |
| 2881 |
Matches("ALTER", "TABLE", MatchAny, "ALTER", MatchAny, "ADD")) |
| 2882 |
COMPLETE_WITH("GENERATED"); |
| 2883 |
/* ALTER TABLE ALTER [COLUMN] <foo> ADD GENERATED */ |
| 2884 |
else if (Matches("ALTER", "TABLE", MatchAny, "ALTER", "COLUMN", MatchAny, "ADD", "GENERATED") || |
| 2885 |
Matches("ALTER", "TABLE", MatchAny, "ALTER", MatchAny, "ADD", "GENERATED")) |
| 2886 |
COMPLETE_WITH("ALWAYS", "BY DEFAULT"); |
| 2887 |
/* ALTER TABLE ALTER [COLUMN] <foo> ADD GENERATED */ |
| 2888 |
else if (Matches("ALTER", "TABLE", MatchAny, "ALTER", "COLUMN", MatchAny, "ADD", "GENERATED", "ALWAYS") || |
| 2889 |
Matches("ALTER", "TABLE", MatchAny, "ALTER", MatchAny, "ADD", "GENERATED", "ALWAYS") || |
| 2890 |
Matches("ALTER", "TABLE", MatchAny, "ALTER", "COLUMN", MatchAny, "ADD", "GENERATED", "BY", "DEFAULT") || |
| 2891 |
Matches("ALTER", "TABLE", MatchAny, "ALTER", MatchAny, "ADD", "GENERATED", "BY", "DEFAULT")) |
| 2892 |
COMPLETE_WITH("AS IDENTITY"); |
| 2893 |
/* ALTER TABLE ALTER [COLUMN] <foo> SET */ |
| 2894 |
else if (Matches("ALTER", "TABLE", MatchAny, "ALTER", "COLUMN", MatchAny, "SET") || |
| 2895 |
Matches("ALTER", "TABLE", MatchAny, "ALTER", MatchAny, "SET")) |
| 2896 |
COMPLETE_WITH("(", "COMPRESSION", "DATA TYPE", "DEFAULT", "EXPRESSION", "GENERATED", "NOT NULL", |
| 2897 |
"STATISTICS", "STORAGE", |
| 2898 |
/* a subset of ALTER SEQUENCE options */ |
| 2899 |
"INCREMENT", "MINVALUE", "MAXVALUE", "START", "NO", "CACHE", "CYCLE"); |
| 2900 |
/* ALTER TABLE ALTER [COLUMN] <foo> SET ( */ |
| 2901 |
else if (Matches("ALTER", "TABLE", MatchAny, "ALTER", "COLUMN", MatchAny, "SET", "(") || |
| 2902 |
Matches("ALTER", "TABLE", MatchAny, "ALTER", MatchAny, "SET", "(")) |
| 2903 |
COMPLETE_WITH("n_distinct", "n_distinct_inherited"); |
| 2904 |
/* ALTER TABLE ALTER [COLUMN] <foo> SET COMPRESSION */ |
| 2905 |
else if (Matches("ALTER", "TABLE", MatchAny, "ALTER", "COLUMN", MatchAny, "SET", "COMPRESSION") || |
| 2906 |
Matches("ALTER", "TABLE", MatchAny, "ALTER", MatchAny, "SET", "COMPRESSION")) |
| 2907 |
COMPLETE_WITH("DEFAULT", "PGLZ", "LZ4"); |
| 2908 |
/* ALTER TABLE ALTER [COLUMN] <foo> SET EXPRESSION */ |
| 2909 |
else if (Matches("ALTER", "TABLE", MatchAny, "ALTER", "COLUMN", MatchAny, "SET", "EXPRESSION") || |
| 2910 |
Matches("ALTER", "TABLE", MatchAny, "ALTER", MatchAny, "SET", "EXPRESSION")) |
| 2911 |
COMPLETE_WITH("AS"); |
| 2912 |
/* ALTER TABLE ALTER [COLUMN] <foo> SET EXPRESSION AS */ |
| 2913 |
else if (Matches("ALTER", "TABLE", MatchAny, "ALTER", "COLUMN", MatchAny, "SET", "EXPRESSION", "AS") || |
| 2914 |
Matches("ALTER", "TABLE", MatchAny, "ALTER", MatchAny, "SET", "EXPRESSION", "AS")) |
| 2915 |
COMPLETE_WITH("("); |
| 2916 |
/* ALTER TABLE ALTER [COLUMN] <foo> SET GENERATED */ |
| 2917 |
else if (Matches("ALTER", "TABLE", MatchAny, "ALTER", "COLUMN", MatchAny, "SET", "GENERATED") || |
| 2918 |
Matches("ALTER", "TABLE", MatchAny, "ALTER", MatchAny, "SET", "GENERATED")) |
| 2919 |
COMPLETE_WITH("ALWAYS", "BY DEFAULT"); |
| 2920 |
/* ALTER TABLE ALTER [COLUMN] <foo> SET NO */ |
| 2921 |
else if (Matches("ALTER", "TABLE", MatchAny, "ALTER", "COLUMN", MatchAny, "SET", "NO") || |
| 2922 |
Matches("ALTER", "TABLE", MatchAny, "ALTER", MatchAny, "SET", "NO")) |
| 2923 |
COMPLETE_WITH("MINVALUE", "MAXVALUE", "CYCLE"); |
| 2924 |
/* ALTER TABLE ALTER [COLUMN] <foo> SET STORAGE */ |
| 2925 |
else if (Matches("ALTER", "TABLE", MatchAny, "ALTER", "COLUMN", MatchAny, "SET", "STORAGE") || |
| 2926 |
Matches("ALTER", "TABLE", MatchAny, "ALTER", MatchAny, "SET", "STORAGE")) |
| 2927 |
COMPLETE_WITH("DEFAULT", "PLAIN", "EXTERNAL", "EXTENDED", "MAIN"); |
| 2928 |
/* ALTER TABLE ALTER [COLUMN] <foo> SET STATISTICS */ |
| 2929 |
else if (Matches("ALTER", "TABLE", MatchAny, "ALTER", "COLUMN", MatchAny, "SET", "STATISTICS") || |
| 2930 |
Matches("ALTER", "TABLE", MatchAny, "ALTER", MatchAny, "SET", "STATISTICS")) |
| 2931 |
{ |
| 2932 |
/* Enforce no completion here, as an integer has to be specified */ |
| 2933 |
} |
| 2934 |
/* ALTER TABLE ALTER [COLUMN] <foo> DROP */ |
| 2935 |
else if (Matches("ALTER", "TABLE", MatchAny, "ALTER", "COLUMN", MatchAny, "DROP") || |
| 2936 |
Matches("ALTER", "TABLE", MatchAny, "ALTER", MatchAny, "DROP")) |
| 2937 |
COMPLETE_WITH("DEFAULT", "EXPRESSION", "IDENTITY", "NOT NULL"); |
| 2938 |
else if (Matches("ALTER", "TABLE", MatchAny, "CLUSTER")) |
| 2939 |
COMPLETE_WITH("ON"); |
| 2940 |
else if (Matches("ALTER", "TABLE", MatchAny, "CLUSTER", "ON")) |
| 2941 |
{ |
| 2942 |
set_completion_reference(prev3_wd); |
| 2943 |
COMPLETE_WITH_SCHEMA_QUERY(Query_for_index_of_table); |
| 2944 |
} |
| 2945 |
/* If we have ALTER TABLE <sth> SET, provide list of attributes and '(' */ |
| 2946 |
else if (Matches("ALTER", "TABLE", MatchAny, "SET")) |
| 2947 |
COMPLETE_WITH("(", "ACCESS METHOD", "LOGGED", "SCHEMA", |
| 2948 |
"TABLESPACE", "UNLOGGED", "WITH", "WITHOUT"); |
| 2949 |
|
| 2950 |
/* |
| 2951 |
* If we have ALTER TABLE <sth> SET ACCESS METHOD provide a list of table |
| 2952 |
* AMs. |
| 2953 |
*/ |
| 2954 |
else if (Matches("ALTER", "TABLE", MatchAny, "SET", "ACCESS", "METHOD")) |
| 2955 |
COMPLETE_WITH_QUERY_PLUS(Query_for_list_of_table_access_methods, |
| 2956 |
"DEFAULT"); |
| 2957 |
|
| 2958 |
/* |
| 2959 |
* If we have ALTER TABLE <sth> SET TABLESPACE provide a list of |
| 2960 |
* tablespaces |
| 2961 |
*/ |
| 2962 |
else if (Matches("ALTER", "TABLE", MatchAny, "SET", "TABLESPACE")) |
| 2963 |
COMPLETE_WITH_QUERY(Query_for_list_of_tablespaces); |
| 2964 |
/* If we have ALTER TABLE <sth> SET WITHOUT provide CLUSTER or OIDS */ |
| 2965 |
else if (Matches("ALTER", "TABLE", MatchAny, "SET", "WITHOUT")) |
| 2966 |
COMPLETE_WITH("CLUSTER", "OIDS"); |
| 2967 |
/* ALTER TABLE <foo> RESET */ |
| 2968 |
else if (Matches("ALTER", "TABLE", MatchAny, "RESET")) |
| 2969 |
COMPLETE_WITH("("); |
| 2970 |
/* ALTER TABLE <foo> SET|RESET ( */ |
| 2971 |
else if (Matches("ALTER", "TABLE", MatchAny, "SET|RESET", "(")) |
| 2972 |
COMPLETE_WITH_LIST(table_storage_parameters); |
| 2973 |
else if (Matches("ALTER", "TABLE", MatchAny, "REPLICA", "IDENTITY", "USING", "INDEX")) |
| 2974 |
{ |
| 2975 |
set_completion_reference(prev5_wd); |
| 2976 |
COMPLETE_WITH_SCHEMA_QUERY(Query_for_index_of_table); |
| 2977 |
} |
| 2978 |
else if (Matches("ALTER", "TABLE", MatchAny, "REPLICA", "IDENTITY", "USING")) |
| 2979 |
COMPLETE_WITH("INDEX"); |
| 2980 |
else if (Matches("ALTER", "TABLE", MatchAny, "REPLICA", "IDENTITY")) |
| 2981 |
COMPLETE_WITH("FULL", "NOTHING", "DEFAULT", "USING"); |
| 2982 |
else if (Matches("ALTER", "TABLE", MatchAny, "REPLICA")) |
| 2983 |
COMPLETE_WITH("IDENTITY"); |
| 2984 |
|
| 2985 |
/* |
| 2986 |
* If we have ALTER TABLE <foo> ATTACH PARTITION, provide a list of |
| 2987 |
* tables. |
| 2988 |
*/ |
| 2989 |
else if (Matches("ALTER", "TABLE", MatchAny, "ATTACH", "PARTITION")) |
| 2990 |
COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_tables); |
| 2991 |
/* Limited completion support for partition bound specification */ |
| 2992 |
else if (TailMatches("ATTACH", "PARTITION", MatchAny)) |
| 2993 |
COMPLETE_WITH("FOR VALUES", "DEFAULT"); |
| 2994 |
else if (TailMatches("FOR", "VALUES")) |
| 2995 |
COMPLETE_WITH("FROM (", "IN (", "WITH ("); |
| 2996 |
|
| 2997 |
/* |
| 2998 |
* If we have ALTER TABLE <foo> DETACH PARTITION, provide a list of |
| 2999 |
* partitions of <foo>. |
| 3000 |
*/ |
| 3001 |
else if (Matches("ALTER", "TABLE", MatchAny, "DETACH", "PARTITION")) |
| 3002 |
{ |
| 3003 |
set_completion_reference(prev3_wd); |
| 3004 |
COMPLETE_WITH_SCHEMA_QUERY(Query_for_partition_of_table); |
| 3005 |
} |
| 3006 |
else if (Matches("ALTER", "TABLE", MatchAny, "DETACH", "PARTITION", MatchAny)) |
| 3007 |
COMPLETE_WITH("CONCURRENTLY", "FINALIZE"); |
| 3008 |
|
| 3009 |
/* ALTER TABLE <name> OF */ |
| 3010 |
else if (Matches("ALTER", "TABLE", MatchAny, "OF")) |
| 3011 |
COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_composite_datatypes); |
| 3012 |
|
| 3013 |
/* ALTER TABLESPACE <foo> with RENAME TO, OWNER TO, SET, RESET */ |
| 3014 |
else if (Matches("ALTER", "TABLESPACE", MatchAny)) |
| 3015 |
COMPLETE_WITH("RENAME TO", "OWNER TO", "SET", "RESET"); |
| 3016 |
/* ALTER TABLESPACE <foo> SET|RESET */ |
| 3017 |
else if (Matches("ALTER", "TABLESPACE", MatchAny, "SET|RESET")) |
| 3018 |
COMPLETE_WITH("("); |
| 3019 |
/* ALTER TABLESPACE <foo> SET|RESET ( */ |
| 3020 |
else if (Matches("ALTER", "TABLESPACE", MatchAny, "SET|RESET", "(")) |
| 3021 |
COMPLETE_WITH("seq_page_cost", "random_page_cost", |
| 3022 |
"effective_io_concurrency", "maintenance_io_concurrency"); |
| 3023 |
|
| 3024 |
/* ALTER TEXT SEARCH */ |
| 3025 |
else if (Matches("ALTER", "TEXT", "SEARCH")) |
| 3026 |
COMPLETE_WITH("CONFIGURATION", "DICTIONARY", "PARSER", "TEMPLATE"); |
| 3027 |
else if (Matches("ALTER", "TEXT", "SEARCH", "TEMPLATE|PARSER", MatchAny)) |
| 3028 |
COMPLETE_WITH("RENAME TO", "SET SCHEMA"); |
| 3029 |
else if (Matches("ALTER", "TEXT", "SEARCH", "DICTIONARY", MatchAny)) |
| 3030 |
COMPLETE_WITH("(", "OWNER TO", "RENAME TO", "SET SCHEMA"); |
| 3031 |
else if (Matches("ALTER", "TEXT", "SEARCH", "CONFIGURATION", MatchAny)) |
| 3032 |
COMPLETE_WITH("ADD MAPPING FOR", "ALTER MAPPING", |
| 3033 |
"DROP MAPPING FOR", |
| 3034 |
"OWNER TO", "RENAME TO", "SET SCHEMA"); |
| 3035 |
|
| 3036 |
/* complete ALTER TYPE <foo> with actions */ |
| 3037 |
else if (Matches("ALTER", "TYPE", MatchAny)) |
| 3038 |
COMPLETE_WITH("ADD ATTRIBUTE", "ADD VALUE", "ALTER ATTRIBUTE", |
| 3039 |
"DROP ATTRIBUTE", |
| 3040 |
"OWNER TO", "RENAME", "SET SCHEMA", "SET ("); |
| 3041 |
/* complete ALTER TYPE <foo> ADD with actions */ |
| 3042 |
else if (Matches("ALTER", "TYPE", MatchAny, "ADD")) |
| 3043 |
COMPLETE_WITH("ATTRIBUTE", "VALUE"); |
| 3044 |
/* ALTER TYPE <foo> RENAME */ |
| 3045 |
else if (Matches("ALTER", "TYPE", MatchAny, "RENAME")) |
| 3046 |
COMPLETE_WITH("ATTRIBUTE", "TO", "VALUE"); |
| 3047 |
/* ALTER TYPE xxx RENAME (ATTRIBUTE|VALUE) yyy */ |
| 3048 |
else if (Matches("ALTER", "TYPE", MatchAny, "RENAME", "ATTRIBUTE|VALUE", MatchAny)) |
| 3049 |
COMPLETE_WITH("TO"); |
| 3050 |
/* ALTER TYPE xxx RENAME ATTRIBUTE yyy TO zzz */ |
| 3051 |
else if (Matches("ALTER", "TYPE", MatchAny, "RENAME", "ATTRIBUTE", MatchAny, "TO", MatchAny)) |
| 3052 |
COMPLETE_WITH("CASCADE", "RESTRICT"); |
| 3053 |
|
| 3054 |
/* |
| 3055 |
* If we have ALTER TYPE <sth> ALTER/DROP/RENAME ATTRIBUTE, provide list |
| 3056 |
* of attributes |
| 3057 |
*/ |
| 3058 |
else if (Matches("ALTER", "TYPE", MatchAny, "ALTER|DROP|RENAME", "ATTRIBUTE")) |
| 3059 |
COMPLETE_WITH_ATTR(prev3_wd); |
| 3060 |
/* complete ALTER TYPE ADD ATTRIBUTE <foo> with list of types */ |
| 3061 |
else if (Matches("ALTER", "TYPE", MatchAny, "ADD", "ATTRIBUTE", MatchAny)) |
| 3062 |
COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_datatypes); |
| 3063 |
/* complete ALTER TYPE ADD ATTRIBUTE <foo> <footype> with CASCADE/RESTRICT */ |
| 3064 |
else if (Matches("ALTER", "TYPE", MatchAny, "ADD", "ATTRIBUTE", MatchAny, MatchAny)) |
| 3065 |
COMPLETE_WITH("CASCADE", "RESTRICT"); |
| 3066 |
/* complete ALTER TYPE DROP ATTRIBUTE <foo> with CASCADE/RESTRICT */ |
| 3067 |
else if (Matches("ALTER", "TYPE", MatchAny, "DROP", "ATTRIBUTE", MatchAny)) |
| 3068 |
COMPLETE_WITH("CASCADE", "RESTRICT"); |
| 3069 |
/* ALTER TYPE ALTER ATTRIBUTE <foo> */ |
| 3070 |
else if (Matches("ALTER", "TYPE", MatchAny, "ALTER", "ATTRIBUTE", MatchAny)) |
| 3071 |
COMPLETE_WITH("TYPE"); |
| 3072 |
/* ALTER TYPE ALTER ATTRIBUTE <foo> TYPE <footype> */ |
| 3073 |
else if (Matches("ALTER", "TYPE", MatchAny, "ALTER", "ATTRIBUTE", MatchAny, "TYPE", MatchAny)) |
| 3074 |
COMPLETE_WITH("CASCADE", "RESTRICT"); |
| 3075 |
/* complete ALTER TYPE <sth> RENAME VALUE with list of enum values */ |
| 3076 |
else if (Matches("ALTER", "TYPE", MatchAny, "RENAME", "VALUE")) |
| 3077 |
COMPLETE_WITH_ENUM_VALUE(prev3_wd); |
| 3078 |
/* ALTER TYPE <foo> SET */ |
| 3079 |
else if (Matches("ALTER", "TYPE", MatchAny, "SET")) |
| 3080 |
COMPLETE_WITH("(", "SCHEMA"); |
| 3081 |
/* complete ALTER TYPE <foo> SET ( with settable properties */ |
| 3082 |
else if (Matches("ALTER", "TYPE", MatchAny, "SET", "(")) |
| 3083 |
COMPLETE_WITH("ANALYZE", "RECEIVE", "SEND", "STORAGE", "SUBSCRIPT", |
| 3084 |
"TYPMOD_IN", "TYPMOD_OUT"); |
| 3085 |
|
| 3086 |
/* complete ALTER GROUP <foo> */ |
| 3087 |
else if (Matches("ALTER", "GROUP", MatchAny)) |
| 3088 |
COMPLETE_WITH("ADD USER", "DROP USER", "RENAME TO"); |
| 3089 |
/* complete ALTER GROUP <foo> ADD|DROP with USER */ |
| 3090 |
else if (Matches("ALTER", "GROUP", MatchAny, "ADD|DROP")) |
| 3091 |
COMPLETE_WITH("USER"); |
| 3092 |
/* complete ALTER GROUP <foo> ADD|DROP USER with a user name */ |
| 3093 |
else if (Matches("ALTER", "GROUP", MatchAny, "ADD|DROP", "USER")) |
| 3094 |
COMPLETE_WITH_QUERY(Query_for_list_of_roles); |
| 3095 |
|
| 3096 |
/* |
| 3097 |
* ANALYZE [ ( option [, ...] ) ] [ [ ONLY ] table_and_columns [, ...] ] |
| 3098 |
* ANALYZE [ VERBOSE ] [ [ ONLY ] table_and_columns [, ...] ] |
| 3099 |
*/ |
| 3100 |
else if (Matches("ANALYZE")) |
| 3101 |
COMPLETE_WITH_SCHEMA_QUERY_PLUS(Query_for_list_of_analyzables, |
| 3102 |
"(", "VERBOSE", "ONLY"); |
| 3103 |
else if (Matches("ANALYZE", "VERBOSE")) |
| 3104 |
COMPLETE_WITH_SCHEMA_QUERY_PLUS(Query_for_list_of_analyzables, |
| 3105 |
"ONLY"); |
| 3106 |
else if (HeadMatches("ANALYZE", "(*") && |
| 3107 |
!HeadMatches("ANALYZE", "(*)")) |
| 3108 |
{ |
| 3109 |
/* |
| 3110 |
* This fires if we're in an unfinished parenthesized option list. |
| 3111 |
* get_previous_words treats a completed parenthesized option list as |
| 3112 |
* one word, so the above test is correct. |
| 3113 |
*/ |
| 3114 |
if (ends_with(prev_wd, '(') || ends_with(prev_wd, ',')) |
| 3115 |
COMPLETE_WITH("VERBOSE", "SKIP_LOCKED", "BUFFER_USAGE_LIMIT"); |
| 3116 |
else if (TailMatches("VERBOSE|SKIP_LOCKED")) |
| 3117 |
COMPLETE_WITH("ON", "OFF"); |
| 3118 |
} |
| 3119 |
else if (Matches("ANALYZE", "(*)")) |
| 3120 |
COMPLETE_WITH_SCHEMA_QUERY_PLUS(Query_for_list_of_analyzables, |
| 3121 |
"ONLY"); |
| 3122 |
else if (Matches("ANALYZE", MatchAnyN, "(")) |
| 3123 |
/* "ANALYZE (" should be caught above, so assume we want columns */ |
| 3124 |
COMPLETE_WITH_ATTR(prev2_wd); |
| 3125 |
else if (HeadMatches("ANALYZE")) |
| 3126 |
COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_analyzables); |
| 3127 |
|
| 3128 |
/* BEGIN */ |
| 3129 |
else if (Matches("BEGIN")) |
| 3130 |
COMPLETE_WITH("WORK", "TRANSACTION", "ISOLATION LEVEL", "READ", "DEFERRABLE", "NOT DEFERRABLE"); |
| 3131 |
/* END, ABORT */ |
| 3132 |
else if (Matches("END|ABORT")) |
| 3133 |
COMPLETE_WITH("AND", "WORK", "TRANSACTION"); |
| 3134 |
/* COMMIT */ |
| 3135 |
else if (Matches("COMMIT")) |
| 3136 |
COMPLETE_WITH("AND", "WORK", "TRANSACTION", "PREPARED"); |
| 3137 |
/* RELEASE SAVEPOINT */ |
| 3138 |
else if (Matches("RELEASE")) |
| 3139 |
COMPLETE_WITH("SAVEPOINT"); |
| 3140 |
/* ROLLBACK */ |
| 3141 |
else if (Matches("ROLLBACK")) |
| 3142 |
COMPLETE_WITH("AND", "WORK", "TRANSACTION", "TO SAVEPOINT", "PREPARED"); |
| 3143 |
else if (Matches("ABORT|END|COMMIT|ROLLBACK", "AND")) |
| 3144 |
COMPLETE_WITH("CHAIN"); |
| 3145 |
/* CALL */ |
| 3146 |
else if (Matches("CALL")) |
| 3147 |
COMPLETE_WITH_VERSIONED_SCHEMA_QUERY(Query_for_list_of_procedures); |
| 3148 |
else if (Matches("CALL", MatchAny)) |
| 3149 |
COMPLETE_WITH("("); |
| 3150 |
/* CLOSE */ |
| 3151 |
else if (Matches("CLOSE")) |
| 3152 |
COMPLETE_WITH_QUERY_PLUS(Query_for_list_of_cursors, |
| 3153 |
"ALL"); |
| 3154 |
/* CLUSTER */ |
| 3155 |
else if (Matches("CLUSTER")) |
| 3156 |
COMPLETE_WITH_SCHEMA_QUERY_PLUS(Query_for_list_of_clusterables, |
| 3157 |
"VERBOSE"); |
| 3158 |
else if (Matches("CLUSTER", "VERBOSE") || |
| 3159 |
Matches("CLUSTER", "(*)")) |
| 3160 |
COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_clusterables); |
| 3161 |
/* If we have CLUSTER <sth>, then add "USING" */ |
| 3162 |
else if (Matches("CLUSTER", MatchAnyExcept("VERBOSE|ON|(|(*)"))) |
| 3163 |
COMPLETE_WITH("USING"); |
| 3164 |
/* If we have CLUSTER VERBOSE <sth>, then add "USING" */ |
| 3165 |
else if (Matches("CLUSTER", "VERBOSE|(*)", MatchAny)) |
| 3166 |
COMPLETE_WITH("USING"); |
| 3167 |
/* If we have CLUSTER <sth> USING, then add the index as well */ |
| 3168 |
else if (Matches("CLUSTER", MatchAny, "USING") || |
| 3169 |
Matches("CLUSTER", "VERBOSE|(*)", MatchAny, "USING")) |
| 3170 |
{ |
| 3171 |
set_completion_reference(prev2_wd); |
| 3172 |
COMPLETE_WITH_SCHEMA_QUERY(Query_for_index_of_table); |
| 3173 |
} |
| 3174 |
else if (HeadMatches("CLUSTER", "(*") && |
| 3175 |
!HeadMatches("CLUSTER", "(*)")) |
| 3176 |
{ |
| 3177 |
/* |
| 3178 |
* This fires if we're in an unfinished parenthesized option list. |
| 3179 |
* get_previous_words treats a completed parenthesized option list as |
| 3180 |
* one word, so the above test is correct. |
| 3181 |
*/ |
| 3182 |
if (ends_with(prev_wd, '(') || ends_with(prev_wd, ',')) |
| 3183 |
COMPLETE_WITH("VERBOSE"); |
| 3184 |
} |
| 3185 |
|
| 3186 |
/* COMMENT */ |
| 3187 |
else if (Matches("COMMENT")) |
| 3188 |
COMPLETE_WITH("ON"); |
| 3189 |
else if (Matches("COMMENT", "ON")) |
| 3190 |
COMPLETE_WITH("ACCESS METHOD", "AGGREGATE", "CAST", "COLLATION", |
| 3191 |
"COLUMN", "CONSTRAINT", "CONVERSION", "DATABASE", |
| 3192 |
"DOMAIN", "EXTENSION", "EVENT TRIGGER", |
| 3193 |
"FOREIGN DATA WRAPPER", "FOREIGN TABLE", |
| 3194 |
"FUNCTION", "INDEX", "LANGUAGE", "LARGE OBJECT", |
| 3195 |
"MATERIALIZED VIEW", "OPERATOR", "POLICY", |
| 3196 |
"PROCEDURE", "PROCEDURAL LANGUAGE", "PUBLICATION", "ROLE", |
| 3197 |
"ROUTINE", "RULE", "SCHEMA", "SEQUENCE", "SERVER", |
| 3198 |
"STATISTICS", "SUBSCRIPTION", "TABLE", |
| 3199 |
"TABLESPACE", "TEXT SEARCH", "TRANSFORM FOR", |
| 3200 |
"TRIGGER", "TYPE", "VIEW"); |
| 3201 |
else if (Matches("COMMENT", "ON", "ACCESS", "METHOD")) |
| 3202 |
COMPLETE_WITH_QUERY(Query_for_list_of_access_methods); |
| 3203 |
else if (Matches("COMMENT", "ON", "CONSTRAINT")) |
| 3204 |
COMPLETE_WITH_QUERY(Query_for_all_table_constraints); |
| 3205 |
else if (Matches("COMMENT", "ON", "CONSTRAINT", MatchAny)) |
| 3206 |
COMPLETE_WITH("ON"); |
| 3207 |
else if (Matches("COMMENT", "ON", "CONSTRAINT", MatchAny, "ON")) |
| 3208 |
{ |
| 3209 |
set_completion_reference(prev2_wd); |
| 3210 |
COMPLETE_WITH_SCHEMA_QUERY_PLUS(Query_for_list_of_tables_for_constraint, |
| 3211 |
"DOMAIN"); |
| 3212 |
} |
| 3213 |
else if (Matches("COMMENT", "ON", "CONSTRAINT", MatchAny, "ON", "DOMAIN")) |
| 3214 |
COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_domains); |
| 3215 |
else if (Matches("COMMENT", "ON", "EVENT", "TRIGGER")) |
| 3216 |
COMPLETE_WITH_QUERY(Query_for_list_of_event_triggers); |
| 3217 |
else if (Matches("COMMENT", "ON", "FOREIGN")) |
| 3218 |
COMPLETE_WITH("DATA WRAPPER", "TABLE"); |
| 3219 |
else if (Matches("COMMENT", "ON", "FOREIGN", "TABLE")) |
| 3220 |
COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_foreign_tables); |
| 3221 |
else if (Matches("COMMENT", "ON", "MATERIALIZED", "VIEW")) |
| 3222 |
COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_matviews); |
| 3223 |
else if (Matches("COMMENT", "ON", "POLICY")) |
| 3224 |
COMPLETE_WITH_QUERY(Query_for_list_of_policies); |
| 3225 |
else if (Matches("COMMENT", "ON", "POLICY", MatchAny)) |
| 3226 |
COMPLETE_WITH("ON"); |
| 3227 |
else if (Matches("COMMENT", "ON", "POLICY", MatchAny, "ON")) |
| 3228 |
{ |
| 3229 |
set_completion_reference(prev2_wd); |
| 3230 |
COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_tables_for_policy); |
| 3231 |
} |
| 3232 |
else if (Matches("COMMENT", "ON", "PROCEDURAL", "LANGUAGE")) |
| 3233 |
COMPLETE_WITH_QUERY(Query_for_list_of_languages); |
| 3234 |
else if (Matches("COMMENT", "ON", "RULE", MatchAny)) |
| 3235 |
COMPLETE_WITH("ON"); |
| 3236 |
else if (Matches("COMMENT", "ON", "RULE", MatchAny, "ON")) |
| 3237 |
{ |
| 3238 |
set_completion_reference(prev2_wd); |
| 3239 |
COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_tables_for_rule); |
| 3240 |
} |
| 3241 |
else if (Matches("COMMENT", "ON", "TEXT", "SEARCH")) |
| 3242 |
COMPLETE_WITH("CONFIGURATION", "DICTIONARY", "PARSER", "TEMPLATE"); |
| 3243 |
else if (Matches("COMMENT", "ON", "TEXT", "SEARCH", "CONFIGURATION")) |
| 3244 |
COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_ts_configurations); |
| 3245 |
else if (Matches("COMMENT", "ON", "TEXT", "SEARCH", "DICTIONARY")) |
| 3246 |
COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_ts_dictionaries); |
| 3247 |
else if (Matches("COMMENT", "ON", "TEXT", "SEARCH", "PARSER")) |
| 3248 |
COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_ts_parsers); |
| 3249 |
else if (Matches("COMMENT", "ON", "TEXT", "SEARCH", "TEMPLATE")) |
| 3250 |
COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_ts_templates); |
| 3251 |
else if (Matches("COMMENT", "ON", "TRANSFORM", "FOR")) |
| 3252 |
COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_datatypes); |
| 3253 |
else if (Matches("COMMENT", "ON", "TRANSFORM", "FOR", MatchAny)) |
| 3254 |
COMPLETE_WITH("LANGUAGE"); |
| 3255 |
else if (Matches("COMMENT", "ON", "TRANSFORM", "FOR", MatchAny, "LANGUAGE")) |
| 3256 |
{ |
| 3257 |
set_completion_reference(prev2_wd); |
| 3258 |
COMPLETE_WITH_QUERY(Query_for_list_of_languages); |
| 3259 |
} |
| 3260 |
else if (Matches("COMMENT", "ON", "TRIGGER", MatchAny)) |
| 3261 |
COMPLETE_WITH("ON"); |
| 3262 |
else if (Matches("COMMENT", "ON", "TRIGGER", MatchAny, "ON")) |
| 3263 |
{ |
| 3264 |
set_completion_reference(prev2_wd); |
| 3265 |
COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_tables_for_trigger); |
| 3266 |
} |
| 3267 |
else if (Matches("COMMENT", "ON", MatchAny, MatchAnyExcept("IS")) || |
| 3268 |
Matches("COMMENT", "ON", MatchAny, MatchAny, MatchAnyExcept("IS")) || |
| 3269 |
Matches("COMMENT", "ON", MatchAny, MatchAny, MatchAny, MatchAnyExcept("IS")) || |
| 3270 |
Matches("COMMENT", "ON", MatchAny, MatchAny, MatchAny, MatchAny, MatchAnyExcept("IS"))) |
| 3271 |
COMPLETE_WITH("IS"); |
| 3272 |
|
| 3273 |
/* COPY */ |
| 3274 |
|
| 3275 |
/* |
| 3276 |
* If we have COPY, offer list of tables or "(" (Also cover the analogous |
| 3277 |
* backslash command). |
| 3278 |
*/ |
| 3279 |
else if (Matches("COPY|\\copy")) |
| 3280 |
COMPLETE_WITH_SCHEMA_QUERY_PLUS(Query_for_list_of_tables, "("); |
| 3281 |
/* Complete COPY ( with legal query commands */ |
| 3282 |
else if (Matches("COPY|\\copy", "(")) |
| 3283 |
COMPLETE_WITH("SELECT", "TABLE", "VALUES", "INSERT INTO", "UPDATE", "DELETE FROM", "MERGE INTO", "WITH"); |
| 3284 |
/* Complete COPY <sth> */ |
| 3285 |
else if (Matches("COPY|\\copy", MatchAny)) |
| 3286 |
COMPLETE_WITH("FROM", "TO"); |
| 3287 |
/* Complete COPY <sth> FROM|TO with filename */ |
| 3288 |
else if (Matches("COPY", MatchAny, "FROM|TO")) |
| 3289 |
{ |
| 3290 |
completion_charp = ""; |
| 3291 |
completion_force_quote = true; /* COPY requires quoted filename */ |
| 3292 |
matches = rl_completion_matches(text, complete_from_files); |
| 3293 |
} |
| 3294 |
else if (Matches("\\copy", MatchAny, "FROM|TO")) |
| 3295 |
{ |
| 3296 |
completion_charp = ""; |
| 3297 |
completion_force_quote = false; |
| 3298 |
matches = rl_completion_matches(text, complete_from_files); |
| 3299 |
} |
| 3300 |
|
| 3301 |
/* Complete COPY <sth> TO <sth> */ |
| 3302 |
else if (Matches("COPY|\\copy", MatchAny, "TO", MatchAny)) |
| 3303 |
COMPLETE_WITH("WITH ("); |
| 3304 |
|
| 3305 |
/* Complete COPY <sth> FROM <sth> */ |
| 3306 |
else if (Matches("COPY|\\copy", MatchAny, "FROM", MatchAny)) |
| 3307 |
COMPLETE_WITH("WITH (", "WHERE"); |
| 3308 |
|
| 3309 |
/* Complete COPY <sth> FROM filename WITH ( */ |
| 3310 |
else if (Matches("COPY|\\copy", MatchAny, "FROM", MatchAny, "WITH", "(")) |
| 3311 |
COMPLETE_WITH(Copy_from_options); |
| 3312 |
|
| 3313 |
/* Complete COPY <sth> TO filename WITH ( */ |
| 3314 |
else if (Matches("COPY|\\copy", MatchAny, "TO", MatchAny, "WITH", "(")) |
| 3315 |
COMPLETE_WITH(Copy_to_options); |
| 3316 |
|
| 3317 |
/* Complete COPY <sth> FROM|TO filename WITH (FORMAT */ |
| 3318 |
else if (Matches("COPY|\\copy", MatchAny, "FROM|TO", MatchAny, "WITH", "(", "FORMAT")) |
| 3319 |
COMPLETE_WITH("binary", "csv", "text"); |
| 3320 |
|
| 3321 |
/* Complete COPY <sth> FROM filename WITH (ON_ERROR */ |
| 3322 |
else if (Matches("COPY|\\copy", MatchAny, "FROM", MatchAny, "WITH", "(", "ON_ERROR")) |
| 3323 |
COMPLETE_WITH("stop", "ignore"); |
| 3324 |
|
| 3325 |
/* Complete COPY <sth> FROM filename WITH (LOG_VERBOSITY */ |
| 3326 |
else if (Matches("COPY|\\copy", MatchAny, "FROM", MatchAny, "WITH", "(", "LOG_VERBOSITY")) |
| 3327 |
COMPLETE_WITH("silent", "default", "verbose"); |
| 3328 |
|
| 3329 |
/* Complete COPY <sth> FROM <sth> WITH (<options>) */ |
| 3330 |
else if (Matches("COPY|\\copy", MatchAny, "FROM", MatchAny, "WITH", MatchAny)) |
| 3331 |
COMPLETE_WITH("WHERE"); |
| 3332 |
|
| 3333 |
/* CREATE ACCESS METHOD */ |
| 3334 |
/* Complete "CREATE ACCESS METHOD <name>" */ |
| 3335 |
else if (Matches("CREATE", "ACCESS", "METHOD", MatchAny)) |
| 3336 |
COMPLETE_WITH("TYPE"); |
| 3337 |
/* Complete "CREATE ACCESS METHOD <name> TYPE" */ |
| 3338 |
else if (Matches("CREATE", "ACCESS", "METHOD", MatchAny, "TYPE")) |
| 3339 |
COMPLETE_WITH("INDEX", "TABLE"); |
| 3340 |
/* Complete "CREATE ACCESS METHOD <name> TYPE <type>" */ |
| 3341 |
else if (Matches("CREATE", "ACCESS", "METHOD", MatchAny, "TYPE", MatchAny)) |
| 3342 |
COMPLETE_WITH("HANDLER"); |
| 3343 |
|
| 3344 |
/* CREATE COLLATION */ |
| 3345 |
else if (Matches("CREATE", "COLLATION", MatchAny)) |
| 3346 |
COMPLETE_WITH("(", "FROM"); |
| 3347 |
else if (Matches("CREATE", "COLLATION", MatchAny, "FROM")) |
| 3348 |
COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_collations); |
| 3349 |
else if (HeadMatches("CREATE", "COLLATION", MatchAny, "(*")) |
| 3350 |
{ |
| 3351 |
if (TailMatches("(|*,")) |
| 3352 |
COMPLETE_WITH("LOCALE =", "LC_COLLATE =", "LC_CTYPE =", |
| 3353 |
"PROVIDER =", "DETERMINISTIC ="); |
| 3354 |
else if (TailMatches("PROVIDER", "=")) |
| 3355 |
COMPLETE_WITH("libc", "icu"); |
| 3356 |
else if (TailMatches("DETERMINISTIC", "=")) |
| 3357 |
COMPLETE_WITH("true", "false"); |
| 3358 |
} |
| 3359 |
|
| 3360 |
/* CREATE DATABASE */ |
| 3361 |
else if (Matches("CREATE", "DATABASE", MatchAny)) |
| 3362 |
COMPLETE_WITH("OWNER", "TEMPLATE", "ENCODING", "TABLESPACE", |
| 3363 |
"IS_TEMPLATE", "STRATEGY", |
| 3364 |
"ALLOW_CONNECTIONS", "CONNECTION LIMIT", |
| 3365 |
"LC_COLLATE", "LC_CTYPE", "LOCALE", "OID", |
| 3366 |
"LOCALE_PROVIDER", "ICU_LOCALE"); |
| 3367 |
|
| 3368 |
else if (Matches("CREATE", "DATABASE", MatchAny, "TEMPLATE")) |
| 3369 |
COMPLETE_WITH_QUERY(Query_for_list_of_template_databases); |
| 3370 |
else if (Matches("CREATE", "DATABASE", MatchAny, "STRATEGY")) |
| 3371 |
COMPLETE_WITH("WAL_LOG", "FILE_COPY"); |
| 3372 |
|
| 3373 |
/* CREATE DOMAIN */ |
| 3374 |
else if (Matches("CREATE", "DOMAIN", MatchAny)) |
| 3375 |
COMPLETE_WITH("AS"); |
| 3376 |
else if (Matches("CREATE", "DOMAIN", MatchAny, "AS")) |
| 3377 |
COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_datatypes); |
| 3378 |
else if (Matches("CREATE", "DOMAIN", MatchAny, "AS", MatchAny)) |
| 3379 |
COMPLETE_WITH("COLLATE", "DEFAULT", "CONSTRAINT", |
| 3380 |
"NOT NULL", "NULL", "CHECK ("); |
| 3381 |
else if (Matches("CREATE", "DOMAIN", MatchAny, "COLLATE")) |
| 3382 |
COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_collations); |
| 3383 |
|
| 3384 |
/* CREATE EXTENSION */ |
| 3385 |
/* Complete with available extensions rather than installed ones. */ |
| 3386 |
else if (Matches("CREATE", "EXTENSION")) |
| 3387 |
COMPLETE_WITH_QUERY(Query_for_list_of_available_extensions); |
| 3388 |
/* CREATE EXTENSION <name> */ |
| 3389 |
else if (Matches("CREATE", "EXTENSION", MatchAny)) |
| 3390 |
COMPLETE_WITH("WITH SCHEMA", "CASCADE", "VERSION"); |
| 3391 |
/* CREATE EXTENSION <name> VERSION */ |
| 3392 |
else if (Matches("CREATE", "EXTENSION", MatchAny, "VERSION")) |
| 3393 |
{ |
| 3394 |
set_completion_reference(prev2_wd); |
| 3395 |
COMPLETE_WITH_QUERY(Query_for_list_of_available_extension_versions); |
| 3396 |
} |
| 3397 |
|
| 3398 |
/* CREATE FOREIGN */ |
| 3399 |
else if (Matches("CREATE", "FOREIGN")) |
| 3400 |
COMPLETE_WITH("DATA WRAPPER", "TABLE"); |
| 3401 |
|
| 3402 |
/* CREATE FOREIGN DATA WRAPPER */ |
| 3403 |
else if (Matches("CREATE", "FOREIGN", "DATA", "WRAPPER", MatchAny)) |
| 3404 |
COMPLETE_WITH("HANDLER", "VALIDATOR", "OPTIONS"); |
| 3405 |
|
| 3406 |
/* CREATE FOREIGN TABLE */ |
| 3407 |
else if (Matches("CREATE", "FOREIGN", "TABLE", MatchAny)) |
| 3408 |
COMPLETE_WITH("(", "PARTITION OF"); |
| 3409 |
|
| 3410 |
/* CREATE INDEX --- is allowed inside CREATE SCHEMA, so use TailMatches */ |
| 3411 |
/* First off we complete CREATE UNIQUE with "INDEX" */ |
| 3412 |
else if (TailMatches("CREATE", "UNIQUE")) |
| 3413 |
COMPLETE_WITH("INDEX"); |
| 3414 |
|
| 3415 |
/* |
| 3416 |
* If we have CREATE|UNIQUE INDEX, then add "ON", "CONCURRENTLY", and |
| 3417 |
* existing indexes |
| 3418 |
*/ |
| 3419 |
else if (TailMatches("CREATE|UNIQUE", "INDEX")) |
| 3420 |
COMPLETE_WITH_SCHEMA_QUERY_PLUS(Query_for_list_of_indexes, |
| 3421 |
"ON", "CONCURRENTLY"); |
| 3422 |
|
| 3423 |
/* |
| 3424 |
* Complete ... INDEX|CONCURRENTLY [<name>] ON with a list of relations |
| 3425 |
* that indexes can be created on |
| 3426 |
*/ |
| 3427 |
else if (TailMatches("INDEX|CONCURRENTLY", MatchAny, "ON") || |
| 3428 |
TailMatches("INDEX|CONCURRENTLY", "ON")) |
| 3429 |
COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_indexables); |
| 3430 |
|
| 3431 |
/* |
| 3432 |
* Complete CREATE|UNIQUE INDEX CONCURRENTLY with "ON" and existing |
| 3433 |
* indexes |
| 3434 |
*/ |
| 3435 |
else if (TailMatches("CREATE|UNIQUE", "INDEX", "CONCURRENTLY")) |
| 3436 |
COMPLETE_WITH_SCHEMA_QUERY_PLUS(Query_for_list_of_indexes, |
| 3437 |
"ON"); |
| 3438 |
/* Complete CREATE|UNIQUE INDEX [CONCURRENTLY] <sth> with "ON" */ |
| 3439 |
else if (TailMatches("CREATE|UNIQUE", "INDEX", MatchAny) || |
| 3440 |
TailMatches("CREATE|UNIQUE", "INDEX", "CONCURRENTLY", MatchAny)) |
| 3441 |
COMPLETE_WITH("ON"); |
| 3442 |
|
| 3443 |
/* |
| 3444 |
* Complete INDEX <name> ON <table> with a list of table columns (which |
| 3445 |
* should really be in parens) |
| 3446 |
*/ |
| 3447 |
else if (TailMatches("INDEX", MatchAny, "ON", MatchAny) || |
| 3448 |
TailMatches("INDEX|CONCURRENTLY", "ON", MatchAny)) |
| 3449 |
COMPLETE_WITH("(", "USING"); |
| 3450 |
else if (TailMatches("INDEX", MatchAny, "ON", MatchAny, "(") || |
| 3451 |
TailMatches("INDEX|CONCURRENTLY", "ON", MatchAny, "(")) |
| 3452 |
COMPLETE_WITH_ATTR(prev2_wd); |
| 3453 |
/* same if you put in USING */ |
| 3454 |
else if (TailMatches("ON", MatchAny, "USING", MatchAny, "(")) |
| 3455 |
COMPLETE_WITH_ATTR(prev4_wd); |
| 3456 |
/* Complete USING with an index method */ |
| 3457 |
else if (TailMatches("INDEX", MatchAny, MatchAny, "ON", MatchAny, "USING") || |
| 3458 |
TailMatches("INDEX", MatchAny, "ON", MatchAny, "USING") || |
| 3459 |
TailMatches("INDEX", "ON", MatchAny, "USING")) |
| 3460 |
COMPLETE_WITH_QUERY(Query_for_list_of_index_access_methods); |
| 3461 |
else if (TailMatches("ON", MatchAny, "USING", MatchAny) && |
| 3462 |
!TailMatches("POLICY", MatchAny, MatchAny, MatchAny, MatchAny, MatchAny) && |
| 3463 |
!TailMatches("FOR", MatchAny, MatchAny, MatchAny)) |
| 3464 |
COMPLETE_WITH("("); |
| 3465 |
|
| 3466 |
/* CREATE OR REPLACE */ |
| 3467 |
else if (Matches("CREATE", "OR")) |
| 3468 |
COMPLETE_WITH("REPLACE"); |
| 3469 |
|
| 3470 |
/* CREATE POLICY */ |
| 3471 |
/* Complete "CREATE POLICY <name> ON" */ |
| 3472 |
else if (Matches("CREATE", "POLICY", MatchAny)) |
| 3473 |
COMPLETE_WITH("ON"); |
| 3474 |
/* Complete "CREATE POLICY <name> ON <table>" */ |
| 3475 |
else if (Matches("CREATE", "POLICY", MatchAny, "ON")) |
| 3476 |
COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_tables); |
| 3477 |
/* Complete "CREATE POLICY <name> ON <table> AS|FOR|TO|USING|WITH CHECK" */ |
| 3478 |
else if (Matches("CREATE", "POLICY", MatchAny, "ON", MatchAny)) |
| 3479 |
COMPLETE_WITH("AS", "FOR", "TO", "USING (", "WITH CHECK ("); |
| 3480 |
/* CREATE POLICY <name> ON <table> AS PERMISSIVE|RESTRICTIVE */ |
| 3481 |
else if (Matches("CREATE", "POLICY", MatchAny, "ON", MatchAny, "AS")) |
| 3482 |
COMPLETE_WITH("PERMISSIVE", "RESTRICTIVE"); |
| 3483 |
|
| 3484 |
/* |
| 3485 |
* CREATE POLICY <name> ON <table> AS PERMISSIVE|RESTRICTIVE |
| 3486 |
* FOR|TO|USING|WITH CHECK |
| 3487 |
*/ |
| 3488 |
else if (Matches("CREATE", "POLICY", MatchAny, "ON", MatchAny, "AS", MatchAny)) |
| 3489 |
COMPLETE_WITH("FOR", "TO", "USING", "WITH CHECK"); |
| 3490 |
/* CREATE POLICY <name> ON <table> FOR ALL|SELECT|INSERT|UPDATE|DELETE */ |
| 3491 |
else if (Matches("CREATE", "POLICY", MatchAny, "ON", MatchAny, "FOR")) |
| 3492 |
COMPLETE_WITH("ALL", "SELECT", "INSERT", "UPDATE", "DELETE"); |
| 3493 |
/* Complete "CREATE POLICY <name> ON <table> FOR INSERT TO|WITH CHECK" */ |
| 3494 |
else if (Matches("CREATE", "POLICY", MatchAny, "ON", MatchAny, "FOR", "INSERT")) |
| 3495 |
COMPLETE_WITH("TO", "WITH CHECK ("); |
| 3496 |
/* Complete "CREATE POLICY <name> ON <table> FOR SELECT|DELETE TO|USING" */ |
| 3497 |
else if (Matches("CREATE", "POLICY", MatchAny, "ON", MatchAny, "FOR", "SELECT|DELETE")) |
| 3498 |
COMPLETE_WITH("TO", "USING ("); |
| 3499 |
/* CREATE POLICY <name> ON <table> FOR ALL|UPDATE TO|USING|WITH CHECK */ |
| 3500 |
else if (Matches("CREATE", "POLICY", MatchAny, "ON", MatchAny, "FOR", "ALL|UPDATE")) |
| 3501 |
COMPLETE_WITH("TO", "USING (", "WITH CHECK ("); |
| 3502 |
/* Complete "CREATE POLICY <name> ON <table> TO <role>" */ |
| 3503 |
else if (Matches("CREATE", "POLICY", MatchAny, "ON", MatchAny, "TO")) |
| 3504 |
COMPLETE_WITH_QUERY_PLUS(Query_for_list_of_roles, |
| 3505 |
Keywords_for_list_of_grant_roles); |
| 3506 |
/* Complete "CREATE POLICY <name> ON <table> USING (" */ |
| 3507 |
else if (Matches("CREATE", "POLICY", MatchAny, "ON", MatchAny, "USING")) |
| 3508 |
COMPLETE_WITH("("); |
| 3509 |
|
| 3510 |
/* |
| 3511 |
* CREATE POLICY <name> ON <table> AS PERMISSIVE|RESTRICTIVE FOR |
| 3512 |
* ALL|SELECT|INSERT|UPDATE|DELETE |
| 3513 |
*/ |
| 3514 |
else if (Matches("CREATE", "POLICY", MatchAny, "ON", MatchAny, "AS", MatchAny, "FOR")) |
| 3515 |
COMPLETE_WITH("ALL", "SELECT", "INSERT", "UPDATE", "DELETE"); |
| 3516 |
|
| 3517 |
/* |
| 3518 |
* Complete "CREATE POLICY <name> ON <table> AS PERMISSIVE|RESTRICTIVE FOR |
| 3519 |
* INSERT TO|WITH CHECK" |
| 3520 |
*/ |
| 3521 |
else if (Matches("CREATE", "POLICY", MatchAny, "ON", MatchAny, "AS", MatchAny, "FOR", "INSERT")) |
| 3522 |
COMPLETE_WITH("TO", "WITH CHECK ("); |
| 3523 |
|
| 3524 |
/* |
| 3525 |
* Complete "CREATE POLICY <name> ON <table> AS PERMISSIVE|RESTRICTIVE FOR |
| 3526 |
* SELECT|DELETE TO|USING" |
| 3527 |
*/ |
| 3528 |
else if (Matches("CREATE", "POLICY", MatchAny, "ON", MatchAny, "AS", MatchAny, "FOR", "SELECT|DELETE")) |
| 3529 |
COMPLETE_WITH("TO", "USING ("); |
| 3530 |
|
| 3531 |
/* |
| 3532 |
* CREATE POLICY <name> ON <table> AS PERMISSIVE|RESTRICTIVE FOR |
| 3533 |
* ALL|UPDATE TO|USING|WITH CHECK |
| 3534 |
*/ |
| 3535 |
else if (Matches("CREATE", "POLICY", MatchAny, "ON", MatchAny, "AS", MatchAny, "FOR", "ALL|UPDATE")) |
| 3536 |
COMPLETE_WITH("TO", "USING (", "WITH CHECK ("); |
| 3537 |
|
| 3538 |
/* |
| 3539 |
* Complete "CREATE POLICY <name> ON <table> AS PERMISSIVE|RESTRICTIVE TO |
| 3540 |
* <role>" |
| 3541 |
*/ |
| 3542 |
else if (Matches("CREATE", "POLICY", MatchAny, "ON", MatchAny, "AS", MatchAny, "TO")) |
| 3543 |
COMPLETE_WITH_QUERY_PLUS(Query_for_list_of_roles, |
| 3544 |
Keywords_for_list_of_grant_roles); |
| 3545 |
|
| 3546 |
/* |
| 3547 |
* Complete "CREATE POLICY <name> ON <table> AS PERMISSIVE|RESTRICTIVE |
| 3548 |
* USING (" |
| 3549 |
*/ |
| 3550 |
else if (Matches("CREATE", "POLICY", MatchAny, "ON", MatchAny, "AS", MatchAny, "USING")) |
| 3551 |
COMPLETE_WITH("("); |
| 3552 |
|
| 3553 |
|
| 3554 |
/* CREATE PUBLICATION */ |
| 3555 |
else if (Matches("CREATE", "PUBLICATION", MatchAny)) |
| 3556 |
COMPLETE_WITH("FOR TABLE", "FOR ALL TABLES", "FOR TABLES IN SCHEMA", "WITH ("); |
| 3557 |
else if (Matches("CREATE", "PUBLICATION", MatchAny, "FOR")) |
| 3558 |
COMPLETE_WITH("TABLE", "ALL TABLES", "TABLES IN SCHEMA"); |
| 3559 |
else if (Matches("CREATE", "PUBLICATION", MatchAny, "FOR", "ALL")) |
| 3560 |
COMPLETE_WITH("TABLES"); |
| 3561 |
else if (Matches("CREATE", "PUBLICATION", MatchAny, "FOR", "ALL", "TABLES")) |
| 3562 |
COMPLETE_WITH("WITH ("); |
| 3563 |
else if (Matches("CREATE", "PUBLICATION", MatchAny, "FOR", "TABLES")) |
| 3564 |
COMPLETE_WITH("IN SCHEMA"); |
| 3565 |
else if (Matches("CREATE", "PUBLICATION", MatchAny, "FOR", "TABLE", MatchAny) && !ends_with(prev_wd, ',')) |
| 3566 |
COMPLETE_WITH("WHERE (", "WITH ("); |
| 3567 |
/* Complete "CREATE PUBLICATION <name> FOR TABLE" with "<table>, ..." */ |
| 3568 |
else if (Matches("CREATE", "PUBLICATION", MatchAny, "FOR", "TABLE")) |
| 3569 |
COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_tables); |
| 3570 |
|
| 3571 |
/* |
| 3572 |
* "CREATE PUBLICATION <name> FOR TABLE <name> WHERE (" - complete with |
| 3573 |
* table attributes |
| 3574 |
*/ |
| 3575 |
else if (Matches("CREATE", "PUBLICATION", MatchAny, MatchAnyN, "WHERE")) |
| 3576 |
COMPLETE_WITH("("); |
| 3577 |
else if (Matches("CREATE", "PUBLICATION", MatchAny, MatchAnyN, "WHERE", "(")) |
| 3578 |
COMPLETE_WITH_ATTR(prev3_wd); |
| 3579 |
else if (Matches("CREATE", "PUBLICATION", MatchAny, MatchAnyN, "WHERE", "(*)")) |
| 3580 |
COMPLETE_WITH(" WITH ("); |
| 3581 |
|
| 3582 |
/* |
| 3583 |
* Complete "CREATE PUBLICATION <name> FOR TABLES IN SCHEMA <schema>, ..." |
| 3584 |
*/ |
| 3585 |
else if (Matches("CREATE", "PUBLICATION", MatchAny, "FOR", "TABLES", "IN", "SCHEMA")) |
| 3586 |
COMPLETE_WITH_QUERY_PLUS(Query_for_list_of_schemas |
| 3587 |
" AND nspname NOT LIKE E'pg\\\\_%%'", |
| 3588 |
"CURRENT_SCHEMA"); |
| 3589 |
else if (Matches("CREATE", "PUBLICATION", MatchAny, "FOR", "TABLES", "IN", "SCHEMA", MatchAny) && (!ends_with(prev_wd, ','))) |
| 3590 |
COMPLETE_WITH("WITH ("); |
| 3591 |
/* Complete "CREATE PUBLICATION <name> [...] WITH" */ |
| 3592 |
else if (Matches("CREATE", "PUBLICATION", MatchAnyN, "WITH", "(")) |
| 3593 |
COMPLETE_WITH("publish", "publish_generated_columns", "publish_via_partition_root"); |
| 3594 |
|
| 3595 |
/* CREATE RULE */ |
| 3596 |
/* Complete "CREATE [ OR REPLACE ] RULE <sth>" with "AS ON" */ |
| 3597 |
else if (Matches("CREATE", "RULE", MatchAny) || |
| 3598 |
Matches("CREATE", "OR", "REPLACE", "RULE", MatchAny)) |
| 3599 |
COMPLETE_WITH("AS ON"); |
| 3600 |
/* Complete "CREATE [ OR REPLACE ] RULE <sth> AS" with "ON" */ |
| 3601 |
else if (Matches("CREATE", "RULE", MatchAny, "AS") || |
| 3602 |
Matches("CREATE", "OR", "REPLACE", "RULE", MatchAny, "AS")) |
| 3603 |
COMPLETE_WITH("ON"); |
| 3604 |
|
| 3605 |
/* |
| 3606 |
* Complete "CREATE [ OR REPLACE ] RULE <sth> AS ON" with |
| 3607 |
* SELECT|UPDATE|INSERT|DELETE |
| 3608 |
*/ |
| 3609 |
else if (Matches("CREATE", "RULE", MatchAny, "AS", "ON") || |
| 3610 |
Matches("CREATE", "OR", "REPLACE", "RULE", MatchAny, "AS", "ON")) |
| 3611 |
COMPLETE_WITH("SELECT", "UPDATE", "INSERT", "DELETE"); |
| 3612 |
/* Complete "AS ON SELECT|UPDATE|INSERT|DELETE" with a "TO" */ |
| 3613 |
else if (TailMatches("AS", "ON", "SELECT|UPDATE|INSERT|DELETE")) |
| 3614 |
COMPLETE_WITH("TO"); |
| 3615 |
/* Complete "AS ON <sth> TO" with a table name */ |
| 3616 |
else if (TailMatches("AS", "ON", "SELECT|UPDATE|INSERT|DELETE", "TO")) |
| 3617 |
COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_tables); |
| 3618 |
|
| 3619 |
/* CREATE SCHEMA [ <name> ] [ AUTHORIZATION ] */ |
| 3620 |
else if (Matches("CREATE", "SCHEMA")) |
| 3621 |
COMPLETE_WITH_QUERY_PLUS(Query_for_list_of_schemas, |
| 3622 |
"AUTHORIZATION"); |
| 3623 |
else if (Matches("CREATE", "SCHEMA", "AUTHORIZATION") || |
| 3624 |
Matches("CREATE", "SCHEMA", MatchAny, "AUTHORIZATION")) |
| 3625 |
COMPLETE_WITH_QUERY_PLUS(Query_for_list_of_roles, |
| 3626 |
Keywords_for_list_of_owner_roles); |
| 3627 |
else if (Matches("CREATE", "SCHEMA", "AUTHORIZATION", MatchAny) || |
| 3628 |
Matches("CREATE", "SCHEMA", MatchAny, "AUTHORIZATION", MatchAny)) |
| 3629 |
COMPLETE_WITH("CREATE", "GRANT"); |
| 3630 |
else if (Matches("CREATE", "SCHEMA", MatchAny)) |
| 3631 |
COMPLETE_WITH("AUTHORIZATION", "CREATE", "GRANT"); |
| 3632 |
|
| 3633 |
/* CREATE SEQUENCE --- is allowed inside CREATE SCHEMA, so use TailMatches */ |
| 3634 |
else if (TailMatches("CREATE", "SEQUENCE", MatchAny) || |
| 3635 |
TailMatches("CREATE", "TEMP|TEMPORARY", "SEQUENCE", MatchAny)) |
| 3636 |
COMPLETE_WITH("AS", "INCREMENT BY", "MINVALUE", "MAXVALUE", "NO", |
| 3637 |
"CACHE", "CYCLE", "OWNED BY", "START WITH"); |
| 3638 |
else if (TailMatches("CREATE", "SEQUENCE", MatchAny, "AS") || |
| 3639 |
TailMatches("CREATE", "TEMP|TEMPORARY", "SEQUENCE", MatchAny, "AS")) |
| 3640 |
COMPLETE_WITH_CS("smallint", "integer", "bigint"); |
| 3641 |
else if (TailMatches("CREATE", "SEQUENCE", MatchAny, "NO") || |
| 3642 |
TailMatches("CREATE", "TEMP|TEMPORARY", "SEQUENCE", MatchAny, "NO")) |
| 3643 |
COMPLETE_WITH("MINVALUE", "MAXVALUE", "CYCLE"); |
| 3644 |
|
| 3645 |
/* CREATE SERVER <name> */ |
| 3646 |
else if (Matches("CREATE", "SERVER", MatchAny)) |
| 3647 |
COMPLETE_WITH("TYPE", "VERSION", "FOREIGN DATA WRAPPER"); |
| 3648 |
|
| 3649 |
/* CREATE STATISTICS <name> */ |
| 3650 |
else if (Matches("CREATE", "STATISTICS", MatchAny)) |
| 3651 |
COMPLETE_WITH("(", "ON"); |
| 3652 |
else if (Matches("CREATE", "STATISTICS", MatchAny, "(")) |
| 3653 |
COMPLETE_WITH("ndistinct", "dependencies", "mcv"); |
| 3654 |
else if (Matches("CREATE", "STATISTICS", MatchAny, "(*)")) |
| 3655 |
COMPLETE_WITH("ON"); |
| 3656 |
else if (Matches("CREATE", "STATISTICS", MatchAny, MatchAnyN, "FROM")) |
| 3657 |
COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_tables); |
| 3658 |
|
| 3659 |
/* CREATE TABLE --- is allowed inside CREATE SCHEMA, so use TailMatches */ |
| 3660 |
/* Complete "CREATE TEMP/TEMPORARY" with the possible temp objects */ |
| 3661 |
else if (TailMatches("CREATE", "TEMP|TEMPORARY")) |
| 3662 |
COMPLETE_WITH("SEQUENCE", "TABLE", "VIEW"); |
| 3663 |
/* Complete "CREATE UNLOGGED" with TABLE or SEQUENCE */ |
| 3664 |
else if (TailMatches("CREATE", "UNLOGGED")) |
| 3665 |
COMPLETE_WITH("TABLE", "SEQUENCE"); |
| 3666 |
/* Complete PARTITION BY with RANGE ( or LIST ( or ... */ |
| 3667 |
else if (TailMatches("PARTITION", "BY")) |
| 3668 |
COMPLETE_WITH("RANGE (", "LIST (", "HASH ("); |
| 3669 |
/* If we have xxx PARTITION OF, provide a list of partitioned tables */ |
| 3670 |
else if (TailMatches("PARTITION", "OF")) |
| 3671 |
COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_partitioned_tables); |
| 3672 |
/* Limited completion support for partition bound specification */ |
| 3673 |
else if (TailMatches("PARTITION", "OF", MatchAny)) |
| 3674 |
COMPLETE_WITH("FOR VALUES", "DEFAULT"); |
| 3675 |
/* Complete CREATE TABLE <name> with '(', AS, OF or PARTITION OF */ |
| 3676 |
else if (TailMatches("CREATE", "TABLE", MatchAny) || |
| 3677 |
TailMatches("CREATE", "TEMP|TEMPORARY|UNLOGGED", "TABLE", MatchAny)) |
| 3678 |
COMPLETE_WITH("(", "AS", "OF", "PARTITION OF"); |
| 3679 |
/* Complete CREATE TABLE <name> OF with list of composite types */ |
| 3680 |
else if (TailMatches("CREATE", "TABLE", MatchAny, "OF") || |
| 3681 |
TailMatches("CREATE", "TEMP|TEMPORARY|UNLOGGED", "TABLE", MatchAny, "OF")) |
| 3682 |
COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_composite_datatypes); |
| 3683 |
/* Complete CREATE TABLE <name> [ (...) ] AS with list of keywords */ |
| 3684 |
else if (TailMatches("CREATE", "TABLE", MatchAny, "AS") || |
| 3685 |
TailMatches("CREATE", "TABLE", MatchAny, "(*)", "AS") || |
| 3686 |
TailMatches("CREATE", "TEMP|TEMPORARY|UNLOGGED", "TABLE", MatchAny, "AS") || |
| 3687 |
TailMatches("CREATE", "TEMP|TEMPORARY|UNLOGGED", "TABLE", MatchAny, "(*)", "AS")) |
| 3688 |
COMPLETE_WITH("EXECUTE", "SELECT", "TABLE", "VALUES", "WITH"); |
| 3689 |
/* Complete CREATE TABLE name (...) with supported options */ |
| 3690 |
else if (TailMatches("CREATE", "TABLE", MatchAny, "(*)")) |
| 3691 |
COMPLETE_WITH("AS", "INHERITS (", "PARTITION BY", "USING", "TABLESPACE", "WITH ("); |
| 3692 |
else if (TailMatches("CREATE", "UNLOGGED", "TABLE", MatchAny, "(*)")) |
| 3693 |
COMPLETE_WITH("AS", "INHERITS (", "USING", "TABLESPACE", "WITH ("); |
| 3694 |
else if (TailMatches("CREATE", "TEMP|TEMPORARY", "TABLE", MatchAny, "(*)")) |
| 3695 |
COMPLETE_WITH("AS", "INHERITS (", "ON COMMIT", "PARTITION BY", "USING", |
| 3696 |
"TABLESPACE", "WITH ("); |
| 3697 |
/* Complete CREATE TABLE (...) USING with table access methods */ |
| 3698 |
else if (TailMatches("CREATE", "TABLE", MatchAny, "(*)", "USING") || |
| 3699 |
TailMatches("CREATE", "TEMP|TEMPORARY|UNLOGGED", "TABLE", MatchAny, "(*)", "USING")) |
| 3700 |
COMPLETE_WITH_QUERY(Query_for_list_of_table_access_methods); |
| 3701 |
/* Complete CREATE TABLE (...) WITH with storage parameters */ |
| 3702 |
else if (TailMatches("CREATE", "TABLE", MatchAny, "(*)", "WITH", "(") || |
| 3703 |
TailMatches("CREATE", "TEMP|TEMPORARY|UNLOGGED", "TABLE", MatchAny, "(*)", "WITH", "(")) |
| 3704 |
COMPLETE_WITH_LIST(table_storage_parameters); |
| 3705 |
/* Complete CREATE TABLE ON COMMIT with actions */ |
| 3706 |
else if (TailMatches("CREATE", "TEMP|TEMPORARY", "TABLE", MatchAny, "(*)", "ON", "COMMIT")) |
| 3707 |
COMPLETE_WITH("DELETE ROWS", "DROP", "PRESERVE ROWS"); |
| 3708 |
|
| 3709 |
/* CREATE TABLESPACE */ |
| 3710 |
else if (Matches("CREATE", "TABLESPACE", MatchAny)) |
| 3711 |
COMPLETE_WITH("OWNER", "LOCATION"); |
| 3712 |
/* Complete CREATE TABLESPACE name OWNER name with "LOCATION" */ |
| 3713 |
else if (Matches("CREATE", "TABLESPACE", MatchAny, "OWNER", MatchAny)) |
| 3714 |
COMPLETE_WITH("LOCATION"); |
| 3715 |
|
| 3716 |
/* CREATE TEXT SEARCH */ |
| 3717 |
else if (Matches("CREATE", "TEXT", "SEARCH")) |
| 3718 |
COMPLETE_WITH("CONFIGURATION", "DICTIONARY", "PARSER", "TEMPLATE"); |
| 3719 |
else if (Matches("CREATE", "TEXT", "SEARCH", "CONFIGURATION|DICTIONARY|PARSER|TEMPLATE", MatchAny)) |
| 3720 |
COMPLETE_WITH("("); |
| 3721 |
|
| 3722 |
/* CREATE TRANSFORM */ |
| 3723 |
else if (Matches("CREATE", "TRANSFORM") || |
| 3724 |
Matches("CREATE", "OR", "REPLACE", "TRANSFORM")) |
| 3725 |
COMPLETE_WITH("FOR"); |
| 3726 |
else if (Matches("CREATE", "TRANSFORM", "FOR") || |
| 3727 |
Matches("CREATE", "OR", "REPLACE", "TRANSFORM", "FOR")) |
| 3728 |
COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_datatypes); |
| 3729 |
else if (Matches("CREATE", "TRANSFORM", "FOR", MatchAny) || |
| 3730 |
Matches("CREATE", "OR", "REPLACE", "TRANSFORM", "FOR", MatchAny)) |
| 3731 |
COMPLETE_WITH("LANGUAGE"); |
| 3732 |
else if (Matches("CREATE", "TRANSFORM", "FOR", MatchAny, "LANGUAGE") || |
| 3733 |
Matches("CREATE", "OR", "REPLACE", "TRANSFORM", "FOR", MatchAny, "LANGUAGE")) |
| 3734 |
{ |
| 3735 |
set_completion_reference(prev2_wd); |
| 3736 |
COMPLETE_WITH_QUERY(Query_for_list_of_languages); |
| 3737 |
} |
| 3738 |
|
| 3739 |
/* CREATE SUBSCRIPTION */ |
| 3740 |
else if (Matches("CREATE", "SUBSCRIPTION", MatchAny)) |
| 3741 |
COMPLETE_WITH("CONNECTION"); |
| 3742 |
else if (Matches("CREATE", "SUBSCRIPTION", MatchAny, "CONNECTION", MatchAny)) |
| 3743 |
COMPLETE_WITH("PUBLICATION"); |
| 3744 |
else if (Matches("CREATE", "SUBSCRIPTION", MatchAny, "CONNECTION", |
| 3745 |
MatchAny, "PUBLICATION")) |
| 3746 |
{ |
| 3747 |
/* complete with nothing here as this refers to remote publications */ |
| 3748 |
} |
| 3749 |
else if (Matches("CREATE", "SUBSCRIPTION", MatchAnyN, "PUBLICATION", MatchAny)) |
| 3750 |
COMPLETE_WITH("WITH ("); |
| 3751 |
/* Complete "CREATE SUBSCRIPTION <name> ... WITH ( <opt>" */ |
| 3752 |
else if (Matches("CREATE", "SUBSCRIPTION", MatchAnyN, "WITH", "(")) |
| 3753 |
COMPLETE_WITH("binary", "connect", "copy_data", "create_slot", |
| 3754 |
"disable_on_error", "enabled", "failover", "origin", |
| 3755 |
"password_required", "run_as_owner", "slot_name", |
| 3756 |
"streaming", "synchronous_commit", "two_phase"); |
| 3757 |
|
| 3758 |
/* CREATE TRIGGER --- is allowed inside CREATE SCHEMA, so use TailMatches */ |
| 3759 |
|
| 3760 |
/* |
| 3761 |
* Complete CREATE [ OR REPLACE ] TRIGGER <name> with BEFORE|AFTER|INSTEAD |
| 3762 |
* OF. |
| 3763 |
*/ |
| 3764 |
else if (TailMatches("CREATE", "TRIGGER", MatchAny) || |
| 3765 |
TailMatches("CREATE", "OR", "REPLACE", "TRIGGER", MatchAny)) |
| 3766 |
COMPLETE_WITH("BEFORE", "AFTER", "INSTEAD OF"); |
| 3767 |
|
| 3768 |
/* |
| 3769 |
* Complete CREATE [ OR REPLACE ] TRIGGER <name> BEFORE,AFTER with an |
| 3770 |
* event. |
| 3771 |
*/ |
| 3772 |
else if (TailMatches("CREATE", "TRIGGER", MatchAny, "BEFORE|AFTER") || |
| 3773 |
TailMatches("CREATE", "OR", "REPLACE", "TRIGGER", MatchAny, "BEFORE|AFTER")) |
| 3774 |
COMPLETE_WITH("INSERT", "DELETE", "UPDATE", "TRUNCATE"); |
| 3775 |
/* Complete CREATE [ OR REPLACE ] TRIGGER <name> INSTEAD OF with an event */ |
| 3776 |
else if (TailMatches("CREATE", "TRIGGER", MatchAny, "INSTEAD", "OF") || |
| 3777 |
TailMatches("CREATE", "OR", "REPLACE", "TRIGGER", MatchAny, "INSTEAD", "OF")) |
| 3778 |
COMPLETE_WITH("INSERT", "DELETE", "UPDATE"); |
| 3779 |
|
| 3780 |
/* |
| 3781 |
* Complete CREATE [ OR REPLACE ] TRIGGER <name> BEFORE,AFTER sth with |
| 3782 |
* OR|ON. |
| 3783 |
*/ |
| 3784 |
else if (TailMatches("CREATE", "TRIGGER", MatchAny, "BEFORE|AFTER", MatchAny) || |
| 3785 |
TailMatches("CREATE", "OR", "REPLACE", "TRIGGER", MatchAny, "BEFORE|AFTER", MatchAny) || |
| 3786 |
TailMatches("CREATE", "TRIGGER", MatchAny, "INSTEAD", "OF", MatchAny) || |
| 3787 |
TailMatches("CREATE", "OR", "REPLACE", "TRIGGER", MatchAny, "INSTEAD", "OF", MatchAny)) |
| 3788 |
COMPLETE_WITH("ON", "OR"); |
| 3789 |
|
| 3790 |
/* |
| 3791 |
* Complete CREATE [ OR REPLACE ] TRIGGER <name> BEFORE,AFTER event ON |
| 3792 |
* with a list of tables. EXECUTE FUNCTION is the recommended grammar |
| 3793 |
* instead of EXECUTE PROCEDURE in version 11 and upwards. |
| 3794 |
*/ |
| 3795 |
else if (TailMatches("CREATE", "TRIGGER", MatchAny, "BEFORE|AFTER", MatchAny, "ON") || |
| 3796 |
TailMatches("CREATE", "OR", "REPLACE", "TRIGGER", MatchAny, "BEFORE|AFTER", MatchAny, "ON")) |
| 3797 |
COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_tables); |
| 3798 |
|
| 3799 |
/* |
| 3800 |
* Complete CREATE [ OR REPLACE ] TRIGGER ... INSTEAD OF event ON with a |
| 3801 |
* list of views. |
| 3802 |
*/ |
| 3803 |
else if (TailMatches("CREATE", "TRIGGER", MatchAny, "INSTEAD", "OF", MatchAny, "ON") || |
| 3804 |
TailMatches("CREATE", "OR", "REPLACE", "TRIGGER", MatchAny, "INSTEAD", "OF", MatchAny, "ON")) |
| 3805 |
COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_views); |
| 3806 |
else if (Matches("CREATE", "TRIGGER", MatchAnyN, |
| 3807 |
"ON", MatchAny) || |
| 3808 |
Matches("CREATE", "OR", "REPLACE", "TRIGGER", MatchAnyN, |
| 3809 |
"ON", MatchAny)) |
| 3810 |
{ |
| 3811 |
if (pset.sversion >= 110000) |
| 3812 |
COMPLETE_WITH("NOT DEFERRABLE", "DEFERRABLE", "INITIALLY", |
| 3813 |
"REFERENCING", "FOR", "WHEN (", "EXECUTE FUNCTION"); |
| 3814 |
else |
| 3815 |
COMPLETE_WITH("NOT DEFERRABLE", "DEFERRABLE", "INITIALLY", |
| 3816 |
"REFERENCING", "FOR", "WHEN (", "EXECUTE PROCEDURE"); |
| 3817 |
} |
| 3818 |
else if (Matches("CREATE", "TRIGGER", MatchAnyN, |
| 3819 |
"DEFERRABLE") || |
| 3820 |
Matches("CREATE", "OR", "REPLACE", "TRIGGER", MatchAnyN, |
| 3821 |
"DEFERRABLE") || |
| 3822 |
Matches("CREATE", "TRIGGER", MatchAnyN, |
| 3823 |
"INITIALLY", "IMMEDIATE|DEFERRED") || |
| 3824 |
Matches("CREATE", "OR", "REPLACE", "TRIGGER", MatchAnyN, |
| 3825 |
"INITIALLY", "IMMEDIATE|DEFERRED")) |
| 3826 |
{ |
| 3827 |
if (pset.sversion >= 110000) |
| 3828 |
COMPLETE_WITH("REFERENCING", "FOR", "WHEN (", "EXECUTE FUNCTION"); |
| 3829 |
else |
| 3830 |
COMPLETE_WITH("REFERENCING", "FOR", "WHEN (", "EXECUTE PROCEDURE"); |
| 3831 |
} |
| 3832 |
else if (Matches("CREATE", "TRIGGER", MatchAnyN, |
| 3833 |
"REFERENCING") || |
| 3834 |
Matches("CREATE", "OR", "REPLACE", "TRIGGER", MatchAnyN, |
| 3835 |
"REFERENCING")) |
| 3836 |
COMPLETE_WITH("OLD TABLE", "NEW TABLE"); |
| 3837 |
else if (Matches("CREATE", "TRIGGER", MatchAnyN, |
| 3838 |
"OLD|NEW", "TABLE") || |
| 3839 |
Matches("CREATE", "OR", "REPLACE", "TRIGGER", MatchAnyN, |
| 3840 |
"OLD|NEW", "TABLE")) |
| 3841 |
COMPLETE_WITH("AS"); |
| 3842 |
else if (Matches("CREATE", "TRIGGER", MatchAnyN, |
| 3843 |
"REFERENCING", "OLD", "TABLE", "AS", MatchAny) || |
| 3844 |
Matches("CREATE", "OR", "REPLACE", "TRIGGER", MatchAnyN, |
| 3845 |
"REFERENCING", "OLD", "TABLE", "AS", MatchAny) || |
| 3846 |
Matches("CREATE", "TRIGGER", MatchAnyN, |
| 3847 |
"REFERENCING", "OLD", "TABLE", MatchAny) || |
| 3848 |
Matches("CREATE", "OR", "REPLACE", "TRIGGER", MatchAnyN, |
| 3849 |
"REFERENCING", "OLD", "TABLE", MatchAny)) |
| 3850 |
{ |
| 3851 |
if (pset.sversion >= 110000) |
| 3852 |
COMPLETE_WITH("NEW TABLE", "FOR", "WHEN (", "EXECUTE FUNCTION"); |
| 3853 |
else |
| 3854 |
COMPLETE_WITH("NEW TABLE", "FOR", "WHEN (", "EXECUTE PROCEDURE"); |
| 3855 |
} |
| 3856 |
else if (Matches("CREATE", "TRIGGER", MatchAnyN, |
| 3857 |
"REFERENCING", "NEW", "TABLE", "AS", MatchAny) || |
| 3858 |
Matches("CREATE", "OR", "REPLACE", "TRIGGER", MatchAnyN, |
| 3859 |
"REFERENCING", "NEW", "TABLE", "AS", MatchAny) || |
| 3860 |
Matches("CREATE", "TRIGGER", MatchAnyN, |
| 3861 |
"REFERENCING", "NEW", "TABLE", MatchAny) || |
| 3862 |
Matches("CREATE", "OR", "REPLACE", "TRIGGER", MatchAnyN, |
| 3863 |
"REFERENCING", "NEW", "TABLE", MatchAny)) |
| 3864 |
{ |
| 3865 |
if (pset.sversion >= 110000) |
| 3866 |
COMPLETE_WITH("OLD TABLE", "FOR", "WHEN (", "EXECUTE FUNCTION"); |
| 3867 |
else |
| 3868 |
COMPLETE_WITH("OLD TABLE", "FOR", "WHEN (", "EXECUTE PROCEDURE"); |
| 3869 |
} |
| 3870 |
else if (Matches("CREATE", "TRIGGER", MatchAnyN, |
| 3871 |
"REFERENCING", "OLD|NEW", "TABLE", "AS", MatchAny, "OLD|NEW", "TABLE", "AS", MatchAny) || |
| 3872 |
Matches("CREATE", "OR", "REPLACE", "TRIGGER", MatchAnyN, |
| 3873 |
"REFERENCING", "OLD|NEW", "TABLE", "AS", MatchAny, "OLD|NEW", "TABLE", "AS", MatchAny) || |
| 3874 |
Matches("CREATE", "TRIGGER", MatchAnyN, |
| 3875 |
"REFERENCING", "OLD|NEW", "TABLE", MatchAny, "OLD|NEW", "TABLE", "AS", MatchAny) || |
| 3876 |
Matches("CREATE", "OR", "REPLACE", "TRIGGER", MatchAnyN, |
| 3877 |
"REFERENCING", "OLD|NEW", "TABLE", MatchAny, "OLD|NEW", "TABLE", "AS", MatchAny) || |
| 3878 |
Matches("CREATE", "TRIGGER", MatchAnyN, |
| 3879 |
"REFERENCING", "OLD|NEW", "TABLE", "AS", MatchAny, "OLD|NEW", "TABLE", MatchAny) || |
| 3880 |
Matches("CREATE", "OR", "REPLACE", "TRIGGER", MatchAnyN, |
| 3881 |
"REFERENCING", "OLD|NEW", "TABLE", "AS", MatchAny, "OLD|NEW", "TABLE", MatchAny) || |
| 3882 |
Matches("CREATE", "TRIGGER", MatchAnyN, |
| 3883 |
"REFERENCING", "OLD|NEW", "TABLE", MatchAny, "OLD|NEW", "TABLE", MatchAny) || |
| 3884 |
Matches("CREATE", "OR", "REPLACE", "TRIGGER", MatchAnyN, |
| 3885 |
"REFERENCING", "OLD|NEW", "TABLE", MatchAny, "OLD|NEW", "TABLE", MatchAny)) |
| 3886 |
{ |
| 3887 |
if (pset.sversion >= 110000) |
| 3888 |
COMPLETE_WITH("FOR", "WHEN (", "EXECUTE FUNCTION"); |
| 3889 |
else |
| 3890 |
COMPLETE_WITH("FOR", "WHEN (", "EXECUTE PROCEDURE"); |
| 3891 |
} |
| 3892 |
else if (Matches("CREATE", "TRIGGER", MatchAnyN, |
| 3893 |
"FOR") || |
| 3894 |
Matches("CREATE", "OR", "REPLACE", "TRIGGER", MatchAnyN, |
| 3895 |
"FOR")) |
| 3896 |
COMPLETE_WITH("EACH", "ROW", "STATEMENT"); |
| 3897 |
else if (Matches("CREATE", "TRIGGER", MatchAnyN, |
| 3898 |
"FOR", "EACH") || |
| 3899 |
Matches("CREATE", "OR", "REPLACE", "TRIGGER", MatchAnyN, |
| 3900 |
"FOR", "EACH")) |
| 3901 |
COMPLETE_WITH("ROW", "STATEMENT"); |
| 3902 |
else if (Matches("CREATE", "TRIGGER", MatchAnyN, |
| 3903 |
"FOR", "EACH", "ROW|STATEMENT") || |
| 3904 |
Matches("CREATE", "OR", "REPLACE", "TRIGGER", MatchAnyN, |
| 3905 |
"FOR", "EACH", "ROW|STATEMENT") || |
| 3906 |
Matches("CREATE", "TRIGGER", MatchAnyN, |
| 3907 |
"FOR", "ROW|STATEMENT") || |
| 3908 |
Matches("CREATE", "OR", "REPLACE", "TRIGGER", MatchAnyN, |
| 3909 |
"FOR", "ROW|STATEMENT")) |
| 3910 |
{ |
| 3911 |
if (pset.sversion >= 110000) |
| 3912 |
COMPLETE_WITH("WHEN (", "EXECUTE FUNCTION"); |
| 3913 |
else |
| 3914 |
COMPLETE_WITH("WHEN (", "EXECUTE PROCEDURE"); |
| 3915 |
} |
| 3916 |
else if (Matches("CREATE", "TRIGGER", MatchAnyN, |
| 3917 |
"WHEN", "(*)") || |
| 3918 |
Matches("CREATE", "OR", "REPLACE", "TRIGGER", MatchAnyN, |
| 3919 |
"WHEN", "(*)")) |
| 3920 |
{ |
| 3921 |
if (pset.sversion >= 110000) |
| 3922 |
COMPLETE_WITH("EXECUTE FUNCTION"); |
| 3923 |
else |
| 3924 |
COMPLETE_WITH("EXECUTE PROCEDURE"); |
| 3925 |
} |
| 3926 |
|
| 3927 |
/* |
| 3928 |
* Complete CREATE [ OR REPLACE ] TRIGGER ... EXECUTE with |
| 3929 |
* PROCEDURE|FUNCTION. |
| 3930 |
*/ |
| 3931 |
else if (Matches("CREATE", "TRIGGER", MatchAnyN, |
| 3932 |
"EXECUTE") || |
| 3933 |
Matches("CREATE", "OR", "REPLACE", "TRIGGER", MatchAnyN, |
| 3934 |
"EXECUTE")) |
| 3935 |
{ |
| 3936 |
if (pset.sversion >= 110000) |
| 3937 |
COMPLETE_WITH("FUNCTION"); |
| 3938 |
else |
| 3939 |
COMPLETE_WITH("PROCEDURE"); |
| 3940 |
} |
| 3941 |
else if (Matches("CREATE", "TRIGGER", MatchAnyN, |
| 3942 |
"EXECUTE", "FUNCTION|PROCEDURE") || |
| 3943 |
Matches("CREATE", "OR", "REPLACE", "TRIGGER", MatchAnyN, |
| 3944 |
"EXECUTE", "FUNCTION|PROCEDURE")) |
| 3945 |
COMPLETE_WITH_VERSIONED_SCHEMA_QUERY(Query_for_list_of_functions); |
| 3946 |
|
| 3947 |
/* CREATE ROLE,USER,GROUP <name> */ |
| 3948 |
else if (Matches("CREATE", "ROLE|GROUP|USER", MatchAny) && |
| 3949 |
!TailMatches("USER", "MAPPING")) |
| 3950 |
COMPLETE_WITH("ADMIN", "BYPASSRLS", "CONNECTION LIMIT", "CREATEDB", |
| 3951 |
"CREATEROLE", "ENCRYPTED PASSWORD", "IN", "INHERIT", |
| 3952 |
"LOGIN", "NOBYPASSRLS", |
| 3953 |
"NOCREATEDB", "NOCREATEROLE", "NOINHERIT", |
| 3954 |
"NOLOGIN", "NOREPLICATION", "NOSUPERUSER", "PASSWORD", |
| 3955 |
"REPLICATION", "ROLE", "SUPERUSER", "SYSID", |
| 3956 |
"VALID UNTIL", "WITH"); |
| 3957 |
|
| 3958 |
/* CREATE ROLE,USER,GROUP <name> WITH */ |
| 3959 |
else if (Matches("CREATE", "ROLE|GROUP|USER", MatchAny, "WITH")) |
| 3960 |
/* Similar to the above, but don't complete "WITH" again. */ |
| 3961 |
COMPLETE_WITH("ADMIN", "BYPASSRLS", "CONNECTION LIMIT", "CREATEDB", |
| 3962 |
"CREATEROLE", "ENCRYPTED PASSWORD", "IN", "INHERIT", |
| 3963 |
"LOGIN", "NOBYPASSRLS", |
| 3964 |
"NOCREATEDB", "NOCREATEROLE", "NOINHERIT", |
| 3965 |
"NOLOGIN", "NOREPLICATION", "NOSUPERUSER", "PASSWORD", |
| 3966 |
"REPLICATION", "ROLE", "SUPERUSER", "SYSID", |
| 3967 |
"VALID UNTIL"); |
| 3968 |
|
| 3969 |
/* complete CREATE ROLE,USER,GROUP <name> IN with ROLE,GROUP */ |
| 3970 |
else if (Matches("CREATE", "ROLE|USER|GROUP", MatchAny, "IN")) |
| 3971 |
COMPLETE_WITH("GROUP", "ROLE"); |
| 3972 |
|
| 3973 |
/* CREATE TYPE */ |
| 3974 |
else if (Matches("CREATE", "TYPE", MatchAny)) |
| 3975 |
COMPLETE_WITH("(", "AS"); |
| 3976 |
else if (Matches("CREATE", "TYPE", MatchAny, "AS")) |
| 3977 |
COMPLETE_WITH("ENUM", "RANGE", "("); |
| 3978 |
else if (HeadMatches("CREATE", "TYPE", MatchAny, "AS", "(")) |
| 3979 |
{ |
| 3980 |
if (TailMatches("(|*,", MatchAny)) |
| 3981 |
COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_datatypes); |
| 3982 |
else if (TailMatches("(|*,", MatchAny, MatchAnyExcept("*)"))) |
| 3983 |
COMPLETE_WITH("COLLATE", ",", ")"); |
| 3984 |
} |
| 3985 |
else if (Matches("CREATE", "TYPE", MatchAny, "AS", "ENUM|RANGE")) |
| 3986 |
COMPLETE_WITH("("); |
| 3987 |
else if (HeadMatches("CREATE", "TYPE", MatchAny, "(")) |
| 3988 |
{ |
| 3989 |
if (TailMatches("(|*,")) |
| 3990 |
COMPLETE_WITH("INPUT", "OUTPUT", "RECEIVE", "SEND", |
| 3991 |
"TYPMOD_IN", "TYPMOD_OUT", "ANALYZE", "SUBSCRIPT", |
| 3992 |
"INTERNALLENGTH", "PASSEDBYVALUE", "ALIGNMENT", |
| 3993 |
"STORAGE", "LIKE", "CATEGORY", "PREFERRED", |
| 3994 |
"DEFAULT", "ELEMENT", "DELIMITER", |
| 3995 |
"COLLATABLE"); |
| 3996 |
else if (TailMatches("(*|*,", MatchAnyExcept("*="))) |
| 3997 |
COMPLETE_WITH("="); |
| 3998 |
else if (TailMatches("=", MatchAnyExcept("*)"))) |
| 3999 |
COMPLETE_WITH(",", ")"); |
| 4000 |
} |
| 4001 |
else if (HeadMatches("CREATE", "TYPE", MatchAny, "AS", "RANGE", "(")) |
| 4002 |
{ |
| 4003 |
if (TailMatches("(|*,")) |
| 4004 |
COMPLETE_WITH("SUBTYPE", "SUBTYPE_OPCLASS", "COLLATION", |
| 4005 |
"CANONICAL", "SUBTYPE_DIFF", |
| 4006 |
"MULTIRANGE_TYPE_NAME"); |
| 4007 |
else if (TailMatches("(*|*,", MatchAnyExcept("*="))) |
| 4008 |
COMPLETE_WITH("="); |
| 4009 |
else if (TailMatches("=", MatchAnyExcept("*)"))) |
| 4010 |
COMPLETE_WITH(",", ")"); |
| 4011 |
} |
| 4012 |
|
| 4013 |
/* CREATE VIEW --- is allowed inside CREATE SCHEMA, so use TailMatches */ |
| 4014 |
/* Complete CREATE [ OR REPLACE ] VIEW <name> with AS or WITH */ |
| 4015 |
else if (TailMatches("CREATE", "VIEW", MatchAny) || |
| 4016 |
TailMatches("CREATE", "OR", "REPLACE", "VIEW", MatchAny)) |
| 4017 |
COMPLETE_WITH("AS", "WITH"); |
| 4018 |
/* Complete "CREATE [ OR REPLACE ] VIEW <sth> AS with "SELECT" */ |
| 4019 |
else if (TailMatches("CREATE", "VIEW", MatchAny, "AS") || |
| 4020 |
TailMatches("CREATE", "OR", "REPLACE", "VIEW", MatchAny, "AS")) |
| 4021 |
COMPLETE_WITH("SELECT"); |
| 4022 |
/* CREATE [ OR REPLACE ] VIEW <name> WITH ( yyy [= zzz] ) */ |
| 4023 |
else if (TailMatches("CREATE", "VIEW", MatchAny, "WITH") || |
| 4024 |
TailMatches("CREATE", "OR", "REPLACE", "VIEW", MatchAny, "WITH")) |
| 4025 |
COMPLETE_WITH("("); |
| 4026 |
else if (TailMatches("CREATE", "VIEW", MatchAny, "WITH", "(") || |
| 4027 |
TailMatches("CREATE", "OR", "REPLACE", "VIEW", MatchAny, "WITH", "(")) |
| 4028 |
COMPLETE_WITH_LIST(view_optional_parameters); |
| 4029 |
else if (TailMatches("CREATE", "VIEW", MatchAny, "WITH", "(", "check_option") || |
| 4030 |
TailMatches("CREATE", "OR", "REPLACE", "VIEW", MatchAny, "WITH", "(", "check_option")) |
| 4031 |
COMPLETE_WITH("="); |
| 4032 |
else if (TailMatches("CREATE", "VIEW", MatchAny, "WITH", "(", "check_option", "=") || |
| 4033 |
TailMatches("CREATE", "OR", "REPLACE", "VIEW", MatchAny, "WITH", "(", "check_option", "=")) |
| 4034 |
COMPLETE_WITH("local", "cascaded"); |
| 4035 |
/* CREATE [ OR REPLACE ] VIEW <name> WITH ( ... ) AS */ |
| 4036 |
else if (TailMatches("CREATE", "VIEW", MatchAny, "WITH", "(*)") || |
| 4037 |
TailMatches("CREATE", "OR", "REPLACE", "VIEW", MatchAny, "WITH", "(*)")) |
| 4038 |
COMPLETE_WITH("AS"); |
| 4039 |
/* CREATE [ OR REPLACE ] VIEW <name> WITH ( ... ) AS SELECT */ |
| 4040 |
else if (TailMatches("CREATE", "VIEW", MatchAny, "WITH", "(*)", "AS") || |
| 4041 |
TailMatches("CREATE", "OR", "REPLACE", "VIEW", MatchAny, "WITH", "(*)", "AS")) |
| 4042 |
COMPLETE_WITH("SELECT"); |
| 4043 |
|
| 4044 |
/* CREATE MATERIALIZED VIEW */ |
| 4045 |
else if (Matches("CREATE", "MATERIALIZED")) |
| 4046 |
COMPLETE_WITH("VIEW"); |
| 4047 |
/* Complete CREATE MATERIALIZED VIEW <name> with AS or USING */ |
| 4048 |
else if (Matches("CREATE", "MATERIALIZED", "VIEW", MatchAny)) |
| 4049 |
COMPLETE_WITH("AS", "USING"); |
| 4050 |
|
| 4051 |
/* |
| 4052 |
* Complete CREATE MATERIALIZED VIEW <name> USING with list of access |
| 4053 |
* methods |
| 4054 |
*/ |
| 4055 |
else if (Matches("CREATE", "MATERIALIZED", "VIEW", MatchAny, "USING")) |
| 4056 |
COMPLETE_WITH_QUERY(Query_for_list_of_table_access_methods); |
| 4057 |
/* Complete CREATE MATERIALIZED VIEW <name> USING <access method> with AS */ |
| 4058 |
else if (Matches("CREATE", "MATERIALIZED", "VIEW", MatchAny, "USING", MatchAny)) |
| 4059 |
COMPLETE_WITH("AS"); |
| 4060 |
|
| 4061 |
/* |
| 4062 |
* Complete CREATE MATERIALIZED VIEW <name> [USING <access method> ] AS |
| 4063 |
* with "SELECT" |
| 4064 |
*/ |
| 4065 |
else if (Matches("CREATE", "MATERIALIZED", "VIEW", MatchAny, "AS") || |
| 4066 |
Matches("CREATE", "MATERIALIZED", "VIEW", MatchAny, "USING", MatchAny, "AS")) |
| 4067 |
COMPLETE_WITH("SELECT"); |
| 4068 |
|
| 4069 |
/* CREATE EVENT TRIGGER */ |
| 4070 |
else if (Matches("CREATE", "EVENT")) |
| 4071 |
COMPLETE_WITH("TRIGGER"); |
| 4072 |
/* Complete CREATE EVENT TRIGGER <name> with ON */ |
| 4073 |
else if (Matches("CREATE", "EVENT", "TRIGGER", MatchAny)) |
| 4074 |
COMPLETE_WITH("ON"); |
| 4075 |
/* Complete CREATE EVENT TRIGGER <name> ON with event_type */ |
| 4076 |
else if (Matches("CREATE", "EVENT", "TRIGGER", MatchAny, "ON")) |
| 4077 |
COMPLETE_WITH("ddl_command_start", "ddl_command_end", "login", |
| 4078 |
"sql_drop", "table_rewrite"); |
| 4079 |
|
| 4080 |
/* |
| 4081 |
* Complete CREATE EVENT TRIGGER <name> ON <event_type>. EXECUTE FUNCTION |
| 4082 |
* is the recommended grammar instead of EXECUTE PROCEDURE in version 11 |
| 4083 |
* and upwards. |
| 4084 |
*/ |
| 4085 |
else if (Matches("CREATE", "EVENT", "TRIGGER", MatchAny, "ON", MatchAny)) |
| 4086 |
{ |
| 4087 |
if (pset.sversion >= 110000) |
| 4088 |
COMPLETE_WITH("WHEN TAG IN (", "EXECUTE FUNCTION"); |
| 4089 |
else |
| 4090 |
COMPLETE_WITH("WHEN TAG IN (", "EXECUTE PROCEDURE"); |
| 4091 |
} |
| 4092 |
else if (Matches("CREATE", "EVENT", "TRIGGER", MatchAnyN, "WHEN|AND", MatchAny, "IN", "(*)")) |
| 4093 |
{ |
| 4094 |
if (pset.sversion >= 110000) |
| 4095 |
COMPLETE_WITH("EXECUTE FUNCTION"); |
| 4096 |
else |
| 4097 |
COMPLETE_WITH("EXECUTE PROCEDURE"); |
| 4098 |
} |
| 4099 |
else if (Matches("CREATE", "EVENT", "TRIGGER", MatchAnyN, "EXECUTE", "FUNCTION|PROCEDURE")) |
| 4100 |
COMPLETE_WITH_VERSIONED_SCHEMA_QUERY(Query_for_list_of_functions); |
| 4101 |
|
| 4102 |
/* DEALLOCATE */ |
| 4103 |
else if (Matches("DEALLOCATE")) |
| 4104 |
COMPLETE_WITH_QUERY_PLUS(Query_for_list_of_prepared_statements, |
| 4105 |
"ALL"); |
| 4106 |
|
| 4107 |
/* DECLARE */ |
| 4108 |
|
| 4109 |
/* |
| 4110 |
* Complete DECLARE <name> with one of BINARY, ASENSITIVE, INSENSITIVE, |
| 4111 |
* SCROLL, NO SCROLL, and CURSOR. |
| 4112 |
*/ |
| 4113 |
else if (Matches("DECLARE", MatchAny)) |
| 4114 |
COMPLETE_WITH("BINARY", "ASENSITIVE", "INSENSITIVE", "SCROLL", "NO SCROLL", |
| 4115 |
"CURSOR"); |
| 4116 |
|
| 4117 |
/* |
| 4118 |
* Complete DECLARE ... <option> with other options. The PostgreSQL parser |
| 4119 |
* allows DECLARE options to be specified in any order. But the |
| 4120 |
* tab-completion follows the ordering of them that the SQL standard |
| 4121 |
* provides, like the syntax of DECLARE command in the documentation |
| 4122 |
* indicates. |
| 4123 |
*/ |
| 4124 |
else if (Matches("DECLARE", MatchAnyN, "BINARY")) |
| 4125 |
COMPLETE_WITH("ASENSITIVE", "INSENSITIVE", "SCROLL", "NO SCROLL", "CURSOR"); |
| 4126 |
else if (Matches("DECLARE", MatchAnyN, "ASENSITIVE|INSENSITIVE")) |
| 4127 |
COMPLETE_WITH("SCROLL", "NO SCROLL", "CURSOR"); |
| 4128 |
else if (Matches("DECLARE", MatchAnyN, "SCROLL")) |
| 4129 |
COMPLETE_WITH("CURSOR"); |
| 4130 |
/* Complete DECLARE ... [options] NO with SCROLL */ |
| 4131 |
else if (Matches("DECLARE", MatchAnyN, "NO")) |
| 4132 |
COMPLETE_WITH("SCROLL"); |
| 4133 |
|
| 4134 |
/* |
| 4135 |
* Complete DECLARE ... CURSOR with one of WITH HOLD, WITHOUT HOLD, and |
| 4136 |
* FOR |
| 4137 |
*/ |
| 4138 |
else if (Matches("DECLARE", MatchAnyN, "CURSOR")) |
| 4139 |
COMPLETE_WITH("WITH HOLD", "WITHOUT HOLD", "FOR"); |
| 4140 |
/* Complete DECLARE ... CURSOR WITH|WITHOUT with HOLD */ |
| 4141 |
else if (Matches("DECLARE", MatchAnyN, "CURSOR", "WITH|WITHOUT")) |
| 4142 |
COMPLETE_WITH("HOLD"); |
| 4143 |
/* Complete DECLARE ... CURSOR WITH|WITHOUT HOLD with FOR */ |
| 4144 |
else if (Matches("DECLARE", MatchAnyN, "CURSOR", "WITH|WITHOUT", "HOLD")) |
| 4145 |
COMPLETE_WITH("FOR"); |
| 4146 |
|
| 4147 |
/* DELETE --- can be inside EXPLAIN, RULE, etc */ |
| 4148 |
/* Complete DELETE with "FROM" */ |
| 4149 |
else if (Matches("DELETE")) |
| 4150 |
COMPLETE_WITH("FROM"); |
| 4151 |
/* Complete DELETE FROM with a list of tables */ |
| 4152 |
else if (TailMatches("DELETE", "FROM")) |
| 4153 |
COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_updatables); |
| 4154 |
/* Complete DELETE FROM <table> */ |
| 4155 |
else if (TailMatches("DELETE", "FROM", MatchAny)) |
| 4156 |
COMPLETE_WITH("USING", "WHERE"); |
| 4157 |
/* XXX: implement tab completion for DELETE ... USING */ |
| 4158 |
|
| 4159 |
/* DISCARD */ |
| 4160 |
else if (Matches("DISCARD")) |
| 4161 |
COMPLETE_WITH("ALL", "PLANS", "SEQUENCES", "TEMP"); |
| 4162 |
|
| 4163 |
/* DO */ |
| 4164 |
else if (Matches("DO")) |
| 4165 |
COMPLETE_WITH("LANGUAGE"); |
| 4166 |
|
| 4167 |
/* DROP */ |
| 4168 |
/* Complete DROP object with CASCADE / RESTRICT */ |
| 4169 |
else if (Matches("DROP", |
| 4170 |
"COLLATION|CONVERSION|DOMAIN|EXTENSION|LANGUAGE|PUBLICATION|SCHEMA|SEQUENCE|SERVER|SUBSCRIPTION|STATISTICS|TABLE|TYPE|VIEW", |
| 4171 |
MatchAny) || |
| 4172 |
Matches("DROP", "ACCESS", "METHOD", MatchAny) || |
| 4173 |
Matches("DROP", "EVENT", "TRIGGER", MatchAny) || |
| 4174 |
Matches("DROP", "FOREIGN", "DATA", "WRAPPER", MatchAny) || |
| 4175 |
Matches("DROP", "FOREIGN", "TABLE", MatchAny) || |
| 4176 |
Matches("DROP", "TEXT", "SEARCH", "CONFIGURATION|DICTIONARY|PARSER|TEMPLATE", MatchAny)) |
| 4177 |
COMPLETE_WITH("CASCADE", "RESTRICT"); |
| 4178 |
else if (Matches("DROP", "AGGREGATE|FUNCTION|PROCEDURE|ROUTINE", MatchAny, MatchAny) && |
| 4179 |
ends_with(prev_wd, ')')) |
| 4180 |
COMPLETE_WITH("CASCADE", "RESTRICT"); |
| 4181 |
|
| 4182 |
/* help completing some of the variants */ |
| 4183 |
else if (Matches("DROP", "AGGREGATE|FUNCTION|PROCEDURE|ROUTINE", MatchAny)) |
| 4184 |
COMPLETE_WITH("("); |
| 4185 |
else if (Matches("DROP", "AGGREGATE|FUNCTION|PROCEDURE|ROUTINE", MatchAny, "(")) |
| 4186 |
COMPLETE_WITH_FUNCTION_ARG(prev2_wd); |
| 4187 |
else if (Matches("DROP", "FOREIGN")) |
| 4188 |
COMPLETE_WITH("DATA WRAPPER", "TABLE"); |
| 4189 |
else if (Matches("DROP", "DATABASE", MatchAny)) |
| 4190 |
COMPLETE_WITH("WITH ("); |
| 4191 |
else if (HeadMatches("DROP", "DATABASE") && (ends_with(prev_wd, '('))) |
| 4192 |
COMPLETE_WITH("FORCE"); |
| 4193 |
|
| 4194 |
/* DROP INDEX */ |
| 4195 |
else if (Matches("DROP", "INDEX")) |
| 4196 |
COMPLETE_WITH_SCHEMA_QUERY_PLUS(Query_for_list_of_indexes, |
| 4197 |
"CONCURRENTLY"); |
| 4198 |
else if (Matches("DROP", "INDEX", "CONCURRENTLY")) |
| 4199 |
COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_indexes); |
| 4200 |
else if (Matches("DROP", "INDEX", MatchAny)) |
| 4201 |
COMPLETE_WITH("CASCADE", "RESTRICT"); |
| 4202 |
else if (Matches("DROP", "INDEX", "CONCURRENTLY", MatchAny)) |
| 4203 |
COMPLETE_WITH("CASCADE", "RESTRICT"); |
| 4204 |
|
| 4205 |
/* DROP MATERIALIZED VIEW */ |
| 4206 |
else if (Matches("DROP", "MATERIALIZED")) |
| 4207 |
COMPLETE_WITH("VIEW"); |
| 4208 |
else if (Matches("DROP", "MATERIALIZED", "VIEW")) |
| 4209 |
COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_matviews); |
| 4210 |
else if (Matches("DROP", "MATERIALIZED", "VIEW", MatchAny)) |
| 4211 |
COMPLETE_WITH("CASCADE", "RESTRICT"); |
| 4212 |
|
| 4213 |
/* DROP OWNED BY */ |
| 4214 |
else if (Matches("DROP", "OWNED")) |
| 4215 |
COMPLETE_WITH("BY"); |
| 4216 |
else if (Matches("DROP", "OWNED", "BY")) |
| 4217 |
COMPLETE_WITH_QUERY(Query_for_list_of_roles); |
| 4218 |
else if (Matches("DROP", "OWNED", "BY", MatchAny)) |
| 4219 |
COMPLETE_WITH("CASCADE", "RESTRICT"); |
| 4220 |
|
| 4221 |
/* DROP TEXT SEARCH */ |
| 4222 |
else if (Matches("DROP", "TEXT", "SEARCH")) |
| 4223 |
COMPLETE_WITH("CONFIGURATION", "DICTIONARY", "PARSER", "TEMPLATE"); |
| 4224 |
|
| 4225 |
/* DROP TRIGGER */ |
| 4226 |
else if (Matches("DROP", "TRIGGER", MatchAny)) |
| 4227 |
COMPLETE_WITH("ON"); |
| 4228 |
else if (Matches("DROP", "TRIGGER", MatchAny, "ON")) |
| 4229 |
{ |
| 4230 |
set_completion_reference(prev2_wd); |
| 4231 |
COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_tables_for_trigger); |
| 4232 |
} |
| 4233 |
else if (Matches("DROP", "TRIGGER", MatchAny, "ON", MatchAny)) |
| 4234 |
COMPLETE_WITH("CASCADE", "RESTRICT"); |
| 4235 |
|
| 4236 |
/* DROP ACCESS METHOD */ |
| 4237 |
else if (Matches("DROP", "ACCESS")) |
| 4238 |
COMPLETE_WITH("METHOD"); |
| 4239 |
else if (Matches("DROP", "ACCESS", "METHOD")) |
| 4240 |
COMPLETE_WITH_QUERY(Query_for_list_of_access_methods); |
| 4241 |
|
| 4242 |
/* DROP EVENT TRIGGER */ |
| 4243 |
else if (Matches("DROP", "EVENT")) |
| 4244 |
COMPLETE_WITH("TRIGGER"); |
| 4245 |
else if (Matches("DROP", "EVENT", "TRIGGER")) |
| 4246 |
COMPLETE_WITH_QUERY(Query_for_list_of_event_triggers); |
| 4247 |
|
| 4248 |
/* DROP POLICY <name> */ |
| 4249 |
else if (Matches("DROP", "POLICY")) |
| 4250 |
COMPLETE_WITH_QUERY(Query_for_list_of_policies); |
| 4251 |
/* DROP POLICY <name> ON */ |
| 4252 |
else if (Matches("DROP", "POLICY", MatchAny)) |
| 4253 |
COMPLETE_WITH("ON"); |
| 4254 |
/* DROP POLICY <name> ON <table> */ |
| 4255 |
else if (Matches("DROP", "POLICY", MatchAny, "ON")) |
| 4256 |
{ |
| 4257 |
set_completion_reference(prev2_wd); |
| 4258 |
COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_tables_for_policy); |
| 4259 |
} |
| 4260 |
else if (Matches("DROP", "POLICY", MatchAny, "ON", MatchAny)) |
| 4261 |
COMPLETE_WITH("CASCADE", "RESTRICT"); |
| 4262 |
|
| 4263 |
/* DROP RULE */ |
| 4264 |
else if (Matches("DROP", "RULE", MatchAny)) |
| 4265 |
COMPLETE_WITH("ON"); |
| 4266 |
else if (Matches("DROP", "RULE", MatchAny, "ON")) |
| 4267 |
{ |
| 4268 |
set_completion_reference(prev2_wd); |
| 4269 |
COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_tables_for_rule); |
| 4270 |
} |
| 4271 |
else if (Matches("DROP", "RULE", MatchAny, "ON", MatchAny)) |
| 4272 |
COMPLETE_WITH("CASCADE", "RESTRICT"); |
| 4273 |
|
| 4274 |
/* DROP TRANSFORM */ |
| 4275 |
else if (Matches("DROP", "TRANSFORM")) |
| 4276 |
COMPLETE_WITH("FOR"); |
| 4277 |
else if (Matches("DROP", "TRANSFORM", "FOR")) |
| 4278 |
COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_datatypes); |
| 4279 |
else if (Matches("DROP", "TRANSFORM", "FOR", MatchAny)) |
| 4280 |
COMPLETE_WITH("LANGUAGE"); |
| 4281 |
else if (Matches("DROP", "TRANSFORM", "FOR", MatchAny, "LANGUAGE")) |
| 4282 |
{ |
| 4283 |
set_completion_reference(prev2_wd); |
| 4284 |
COMPLETE_WITH_QUERY(Query_for_list_of_languages); |
| 4285 |
} |
| 4286 |
else if (Matches("DROP", "TRANSFORM", "FOR", MatchAny, "LANGUAGE", MatchAny)) |
| 4287 |
COMPLETE_WITH("CASCADE", "RESTRICT"); |
| 4288 |
|
| 4289 |
/* EXECUTE */ |
| 4290 |
else if (Matches("EXECUTE")) |
| 4291 |
COMPLETE_WITH_QUERY(Query_for_list_of_prepared_statements); |
| 4292 |
|
| 4293 |
/* |
| 4294 |
* EXPLAIN [ ( option [, ...] ) ] statement |
| 4295 |
* EXPLAIN [ ANALYZE ] [ VERBOSE ] statement |
| 4296 |
*/ |
| 4297 |
else if (Matches("EXPLAIN")) |
| 4298 |
COMPLETE_WITH("SELECT", "INSERT INTO", "DELETE FROM", "UPDATE", "DECLARE", |
| 4299 |
"MERGE INTO", "EXECUTE", "ANALYZE", "VERBOSE"); |
| 4300 |
else if (HeadMatches("EXPLAIN", "(*") && |
| 4301 |
!HeadMatches("EXPLAIN", "(*)")) |
| 4302 |
{ |
| 4303 |
/* |
| 4304 |
* This fires if we're in an unfinished parenthesized option list. |
| 4305 |
* get_previous_words treats a completed parenthesized option list as |
| 4306 |
* one word, so the above test is correct. |
| 4307 |
*/ |
| 4308 |
if (ends_with(prev_wd, '(') || ends_with(prev_wd, ',')) |
| 4309 |
COMPLETE_WITH("ANALYZE", "VERBOSE", "COSTS", "SETTINGS", "GENERIC_PLAN", |
| 4310 |
"BUFFERS", "SERIALIZE", "WAL", "TIMING", "SUMMARY", |
| 4311 |
"MEMORY", "FORMAT"); |
| 4312 |
else if (TailMatches("ANALYZE|VERBOSE|COSTS|SETTINGS|GENERIC_PLAN|BUFFERS|WAL|TIMING|SUMMARY|MEMORY")) |
| 4313 |
COMPLETE_WITH("ON", "OFF"); |
| 4314 |
else if (TailMatches("SERIALIZE")) |
| 4315 |
COMPLETE_WITH("TEXT", "NONE", "BINARY"); |
| 4316 |
else if (TailMatches("FORMAT")) |
| 4317 |
COMPLETE_WITH("TEXT", "XML", "JSON", "YAML"); |
| 4318 |
} |
| 4319 |
else if (Matches("EXPLAIN", "ANALYZE")) |
| 4320 |
COMPLETE_WITH("SELECT", "INSERT INTO", "DELETE FROM", "UPDATE", "DECLARE", |
| 4321 |
"MERGE INTO", "EXECUTE", "VERBOSE"); |
| 4322 |
else if (Matches("EXPLAIN", "(*)") || |
| 4323 |
Matches("EXPLAIN", "VERBOSE") || |
| 4324 |
Matches("EXPLAIN", "ANALYZE", "VERBOSE")) |
| 4325 |
COMPLETE_WITH("SELECT", "INSERT INTO", "DELETE FROM", "UPDATE", "DECLARE", |
| 4326 |
"MERGE INTO", "EXECUTE"); |
| 4327 |
|
| 4328 |
/* FETCH && MOVE */ |
| 4329 |
|
| 4330 |
/* |
| 4331 |
* Complete FETCH with one of ABSOLUTE, BACKWARD, FORWARD, RELATIVE, ALL, |
| 4332 |
* NEXT, PRIOR, FIRST, LAST, FROM, IN, and a list of cursors |
| 4333 |
*/ |
| 4334 |
else if (Matches("FETCH|MOVE")) |
| 4335 |
COMPLETE_WITH_QUERY_PLUS(Query_for_list_of_cursors, |
| 4336 |
"ABSOLUTE", |
| 4337 |
"BACKWARD", |
| 4338 |
"FORWARD", |
| 4339 |
"RELATIVE", |
| 4340 |
"ALL", |
| 4341 |
"NEXT", |
| 4342 |
"PRIOR", |
| 4343 |
"FIRST", |
| 4344 |
"LAST", |
| 4345 |
"FROM", |
| 4346 |
"IN"); |
| 4347 |
|
| 4348 |
/* |
| 4349 |
* Complete FETCH BACKWARD or FORWARD with one of ALL, FROM, IN, and a |
| 4350 |
* list of cursors |
| 4351 |
*/ |
| 4352 |
else if (Matches("FETCH|MOVE", "BACKWARD|FORWARD")) |
| 4353 |
COMPLETE_WITH_QUERY_PLUS(Query_for_list_of_cursors, |
| 4354 |
"ALL", |
| 4355 |
"FROM", |
| 4356 |
"IN"); |
| 4357 |
|
| 4358 |
/* |
| 4359 |
* Complete FETCH <direction> with "FROM" or "IN". These are equivalent, |
| 4360 |
* but we may as well tab-complete both: perhaps some users prefer one |
| 4361 |
* variant or the other. |
| 4362 |
*/ |
| 4363 |
else if (Matches("FETCH|MOVE", "ABSOLUTE|BACKWARD|FORWARD|RELATIVE", |
| 4364 |
MatchAnyExcept("FROM|IN")) || |
| 4365 |
Matches("FETCH|MOVE", "ALL|NEXT|PRIOR|FIRST|LAST")) |
| 4366 |
COMPLETE_WITH_QUERY_PLUS(Query_for_list_of_cursors, |
| 4367 |
"FROM", |
| 4368 |
"IN"); |
| 4369 |
/* Complete FETCH <direction> "FROM" or "IN" with a list of cursors */ |
| 4370 |
else if (Matches("FETCH|MOVE", MatchAnyN, "FROM|IN")) |
| 4371 |
COMPLETE_WITH_QUERY(Query_for_list_of_cursors); |
| 4372 |
|
| 4373 |
/* FOREIGN DATA WRAPPER */ |
| 4374 |
/* applies in ALTER/DROP FDW and in CREATE SERVER */ |
| 4375 |
else if (TailMatches("FOREIGN", "DATA", "WRAPPER") && |
| 4376 |
!TailMatches("CREATE", MatchAny, MatchAny, MatchAny)) |
| 4377 |
COMPLETE_WITH_QUERY(Query_for_list_of_fdws); |
| 4378 |
/* applies in CREATE SERVER */ |
| 4379 |
else if (Matches("CREATE", "SERVER", MatchAnyN, "FOREIGN", "DATA", "WRAPPER", MatchAny)) |
| 4380 |
COMPLETE_WITH("OPTIONS"); |
| 4381 |
|
| 4382 |
/* FOREIGN TABLE */ |
| 4383 |
else if (TailMatches("FOREIGN", "TABLE") && |
| 4384 |
!TailMatches("CREATE", MatchAny, MatchAny)) |
| 4385 |
COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_foreign_tables); |
| 4386 |
|
| 4387 |
/* FOREIGN SERVER */ |
| 4388 |
else if (TailMatches("FOREIGN", "SERVER")) |
| 4389 |
COMPLETE_WITH_QUERY(Query_for_list_of_servers); |
| 4390 |
|
| 4391 |
/* |
| 4392 |
* GRANT and REVOKE are allowed inside CREATE SCHEMA and |
| 4393 |
* ALTER DEFAULT PRIVILEGES, so use TailMatches |
| 4394 |
*/ |
| 4395 |
/* Complete GRANT/REVOKE with a list of roles and privileges */ |
| 4396 |
else if (TailMatches("GRANT|REVOKE") || |
| 4397 |
TailMatches("REVOKE", "ADMIN|GRANT|INHERIT|SET", "OPTION", "FOR")) |
| 4398 |
{ |
| 4399 |
/* |
| 4400 |
* With ALTER DEFAULT PRIVILEGES, restrict completion to grantable |
| 4401 |
* privileges (can't grant roles) |
| 4402 |
*/ |
| 4403 |
if (HeadMatches("ALTER", "DEFAULT", "PRIVILEGES")) |
| 4404 |
{ |
| 4405 |
if (TailMatches("GRANT") || |
| 4406 |
TailMatches("REVOKE", "GRANT", "OPTION", "FOR")) |
| 4407 |
COMPLETE_WITH("SELECT", "INSERT", "UPDATE", |
| 4408 |
"DELETE", "TRUNCATE", "REFERENCES", "TRIGGER", |
| 4409 |
"CREATE", "EXECUTE", "USAGE", "MAINTAIN", "ALL"); |
| 4410 |
else if (TailMatches("REVOKE")) |
| 4411 |
COMPLETE_WITH("SELECT", "INSERT", "UPDATE", |
| 4412 |
"DELETE", "TRUNCATE", "REFERENCES", "TRIGGER", |
| 4413 |
"CREATE", "EXECUTE", "USAGE", "MAINTAIN", "ALL", |
| 4414 |
"GRANT OPTION FOR"); |
| 4415 |
} |
| 4416 |
else if (TailMatches("GRANT")) |
| 4417 |
COMPLETE_WITH_QUERY_PLUS(Query_for_list_of_roles, |
| 4418 |
Privilege_options_of_grant_and_revoke); |
| 4419 |
else if (TailMatches("REVOKE")) |
| 4420 |
COMPLETE_WITH_QUERY_PLUS(Query_for_list_of_roles, |
| 4421 |
Privilege_options_of_grant_and_revoke, |
| 4422 |
"GRANT OPTION FOR", |
| 4423 |
"ADMIN OPTION FOR", |
| 4424 |
"INHERIT OPTION FOR", |
| 4425 |
"SET OPTION FOR"); |
| 4426 |
else if (TailMatches("REVOKE", "GRANT", "OPTION", "FOR")) |
| 4427 |
COMPLETE_WITH(Privilege_options_of_grant_and_revoke); |
| 4428 |
else if (TailMatches("REVOKE", "ADMIN|INHERIT|SET", "OPTION", "FOR")) |
| 4429 |
COMPLETE_WITH_QUERY(Query_for_list_of_roles); |
| 4430 |
} |
| 4431 |
|
| 4432 |
else if (TailMatches("GRANT|REVOKE", "ALTER") || |
| 4433 |
TailMatches("REVOKE", "GRANT", "OPTION", "FOR", "ALTER")) |
| 4434 |
COMPLETE_WITH("SYSTEM"); |
| 4435 |
|
| 4436 |
else if (TailMatches("REVOKE", "SET")) |
| 4437 |
COMPLETE_WITH("ON PARAMETER", "OPTION FOR"); |
| 4438 |
else if (TailMatches("GRANT", "SET") || |
| 4439 |
TailMatches("REVOKE", "GRANT", "OPTION", "FOR", "SET") || |
| 4440 |
TailMatches("GRANT|REVOKE", "ALTER", "SYSTEM") || |
| 4441 |
TailMatches("REVOKE", "GRANT", "OPTION", "FOR", "ALTER", "SYSTEM")) |
| 4442 |
COMPLETE_WITH("ON PARAMETER"); |
| 4443 |
|
| 4444 |
else if (TailMatches("GRANT|REVOKE", MatchAny, "ON", "PARAMETER") || |
| 4445 |
TailMatches("GRANT|REVOKE", MatchAny, MatchAny, "ON", "PARAMETER") || |
| 4446 |
TailMatches("REVOKE", "GRANT", "OPTION", "FOR", MatchAny, "ON", "PARAMETER") || |
| 4447 |
TailMatches("REVOKE", "GRANT", "OPTION", "FOR", MatchAny, MatchAny, "ON", "PARAMETER")) |
| 4448 |
COMPLETE_WITH_QUERY_VERBATIM(Query_for_list_of_alter_system_set_vars); |
| 4449 |
|
| 4450 |
else if (TailMatches("GRANT", MatchAny, "ON", "PARAMETER", MatchAny) || |
| 4451 |
TailMatches("GRANT", MatchAny, MatchAny, "ON", "PARAMETER", MatchAny)) |
| 4452 |
COMPLETE_WITH("TO"); |
| 4453 |
|
| 4454 |
else if (TailMatches("REVOKE", MatchAny, "ON", "PARAMETER", MatchAny) || |
| 4455 |
TailMatches("REVOKE", MatchAny, MatchAny, "ON", "PARAMETER", MatchAny) || |
| 4456 |
TailMatches("REVOKE", "GRANT", "OPTION", "FOR", MatchAny, "ON", "PARAMETER", MatchAny) || |
| 4457 |
TailMatches("REVOKE", "GRANT", "OPTION", "FOR", MatchAny, MatchAny, "ON", "PARAMETER", MatchAny)) |
| 4458 |
COMPLETE_WITH("FROM"); |
| 4459 |
|
| 4460 |
/* |
| 4461 |
* Complete GRANT/REVOKE <privilege> with "ON", GRANT/REVOKE <role> with |
| 4462 |
* TO/FROM |
| 4463 |
*/ |
| 4464 |
else if (TailMatches("GRANT|REVOKE", MatchAny) || |
| 4465 |
TailMatches("REVOKE", "GRANT", "OPTION", "FOR", MatchAny)) |
| 4466 |
{ |
| 4467 |
if (TailMatches("SELECT|INSERT|UPDATE|DELETE|TRUNCATE|REFERENCES|TRIGGER|CREATE|CONNECT|TEMPORARY|TEMP|EXECUTE|USAGE|MAINTAIN|ALL")) |
| 4468 |
COMPLETE_WITH("ON"); |
| 4469 |
else if (TailMatches("GRANT", MatchAny)) |
| 4470 |
COMPLETE_WITH("TO"); |
| 4471 |
else |
| 4472 |
COMPLETE_WITH("FROM"); |
| 4473 |
} |
| 4474 |
|
| 4475 |
/* |
| 4476 |
* Complete GRANT/REVOKE <sth> ON with a list of appropriate relations. |
| 4477 |
* |
| 4478 |
* Note: GRANT/REVOKE can get quite complex; tab-completion as implemented |
| 4479 |
* here will only work if the privilege list contains exactly one |
| 4480 |
* privilege. |
| 4481 |
*/ |
| 4482 |
else if (TailMatches("GRANT|REVOKE", MatchAny, "ON") || |
| 4483 |
TailMatches("REVOKE", "GRANT", "OPTION", "FOR", MatchAny, "ON")) |
| 4484 |
{ |
| 4485 |
/* |
| 4486 |
* With ALTER DEFAULT PRIVILEGES, restrict completion to the kinds of |
| 4487 |
* objects supported. |
| 4488 |
*/ |
| 4489 |
if (HeadMatches("ALTER", "DEFAULT", "PRIVILEGES")) |
| 4490 |
COMPLETE_WITH("TABLES", "SEQUENCES", "FUNCTIONS", "PROCEDURES", "ROUTINES", "TYPES", "SCHEMAS", "LARGE OBJECTS"); |
| 4491 |
else |
| 4492 |
COMPLETE_WITH_SCHEMA_QUERY_PLUS(Query_for_list_of_grantables, |
| 4493 |
"ALL FUNCTIONS IN SCHEMA", |
| 4494 |
"ALL PROCEDURES IN SCHEMA", |
| 4495 |
"ALL ROUTINES IN SCHEMA", |
| 4496 |
"ALL SEQUENCES IN SCHEMA", |
| 4497 |
"ALL TABLES IN SCHEMA", |
| 4498 |
"DATABASE", |
| 4499 |
"DOMAIN", |
| 4500 |
"FOREIGN DATA WRAPPER", |
| 4501 |
"FOREIGN SERVER", |
| 4502 |
"FUNCTION", |
| 4503 |
"LANGUAGE", |
| 4504 |
"LARGE OBJECT", |
| 4505 |
"PARAMETER", |
| 4506 |
"PROCEDURE", |
| 4507 |
"ROUTINE", |
| 4508 |
"SCHEMA", |
| 4509 |
"SEQUENCE", |
| 4510 |
"TABLE", |
| 4511 |
"TABLESPACE", |
| 4512 |
"TYPE"); |
| 4513 |
} |
| 4514 |
else if (TailMatches("GRANT|REVOKE", MatchAny, "ON", "ALL") || |
| 4515 |
TailMatches("REVOKE", "GRANT", "OPTION", "FOR", MatchAny, "ON", "ALL")) |
| 4516 |
COMPLETE_WITH("FUNCTIONS IN SCHEMA", |
| 4517 |
"PROCEDURES IN SCHEMA", |
| 4518 |
"ROUTINES IN SCHEMA", |
| 4519 |
"SEQUENCES IN SCHEMA", |
| 4520 |
"TABLES IN SCHEMA"); |
| 4521 |
else if (TailMatches("GRANT|REVOKE", MatchAny, "ON", "FOREIGN") || |
| 4522 |
TailMatches("REVOKE", "GRANT", "OPTION", "FOR", MatchAny, "ON", "FOREIGN")) |
| 4523 |
COMPLETE_WITH("DATA WRAPPER", "SERVER"); |
| 4524 |
|
| 4525 |
/* |
| 4526 |
* Complete "GRANT/REVOKE * ON DATABASE/DOMAIN/..." with a list of |
| 4527 |
* appropriate objects. |
| 4528 |
* |
| 4529 |
* Complete "GRANT/REVOKE * ON *" with "TO/FROM". |
| 4530 |
*/ |
| 4531 |
else if (TailMatches("GRANT|REVOKE", MatchAny, "ON", MatchAny) || |
| 4532 |
TailMatches("REVOKE", "GRANT", "OPTION", "FOR", MatchAny, "ON", MatchAny)) |
| 4533 |
{ |
| 4534 |
if (TailMatches("DATABASE")) |
| 4535 |
COMPLETE_WITH_QUERY(Query_for_list_of_databases); |
| 4536 |
else if (TailMatches("DOMAIN")) |
| 4537 |
COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_domains); |
| 4538 |
else if (TailMatches("FUNCTION")) |
| 4539 |
COMPLETE_WITH_VERSIONED_SCHEMA_QUERY(Query_for_list_of_functions); |
| 4540 |
else if (TailMatches("LANGUAGE")) |
| 4541 |
COMPLETE_WITH_QUERY(Query_for_list_of_languages); |
| 4542 |
else if (TailMatches("PROCEDURE")) |
| 4543 |
COMPLETE_WITH_VERSIONED_SCHEMA_QUERY(Query_for_list_of_procedures); |
| 4544 |
else if (TailMatches("ROUTINE")) |
| 4545 |
COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_routines); |
| 4546 |
else if (TailMatches("SCHEMA")) |
| 4547 |
COMPLETE_WITH_QUERY(Query_for_list_of_schemas); |
| 4548 |
else if (TailMatches("SEQUENCE")) |
| 4549 |
COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_sequences); |
| 4550 |
else if (TailMatches("TABLE")) |
| 4551 |
COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_grantables); |
| 4552 |
else if (TailMatches("TABLESPACE")) |
| 4553 |
COMPLETE_WITH_QUERY(Query_for_list_of_tablespaces); |
| 4554 |
else if (TailMatches("TYPE")) |
| 4555 |
COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_datatypes); |
| 4556 |
else if (TailMatches("GRANT", MatchAny, MatchAny, MatchAny)) |
| 4557 |
COMPLETE_WITH("TO"); |
| 4558 |
else |
| 4559 |
COMPLETE_WITH("FROM"); |
| 4560 |
} |
| 4561 |
|
| 4562 |
/* |
| 4563 |
* Complete "GRANT/REVOKE ... TO/FROM" with username, PUBLIC, |
| 4564 |
* CURRENT_ROLE, CURRENT_USER, or SESSION_USER. |
| 4565 |
*/ |
| 4566 |
else if (Matches("GRANT", MatchAnyN, "TO") || |
| 4567 |
Matches("REVOKE", MatchAnyN, "FROM")) |
| 4568 |
COMPLETE_WITH_QUERY_PLUS(Query_for_list_of_roles, |
| 4569 |
Keywords_for_list_of_grant_roles); |
| 4570 |
|
| 4571 |
/* |
| 4572 |
* Offer grant options after that. |
| 4573 |
*/ |
| 4574 |
else if (Matches("GRANT", MatchAnyN, "TO", MatchAny)) |
| 4575 |
COMPLETE_WITH("WITH ADMIN", |
| 4576 |
"WITH INHERIT", |
| 4577 |
"WITH SET", |
| 4578 |
"WITH GRANT OPTION", |
| 4579 |
"GRANTED BY"); |
| 4580 |
else if (Matches("GRANT", MatchAnyN, "TO", MatchAny, "WITH")) |
| 4581 |
COMPLETE_WITH("ADMIN", |
| 4582 |
"INHERIT", |
| 4583 |
"SET", |
| 4584 |
"GRANT OPTION"); |
| 4585 |
else if (Matches("GRANT", MatchAnyN, "TO", MatchAny, "WITH", "ADMIN|INHERIT|SET")) |
| 4586 |
COMPLETE_WITH("OPTION", "TRUE", "FALSE"); |
| 4587 |
else if (Matches("GRANT", MatchAnyN, "TO", MatchAny, "WITH", MatchAny, "OPTION")) |
| 4588 |
COMPLETE_WITH("GRANTED BY"); |
| 4589 |
else if (Matches("GRANT", MatchAnyN, "TO", MatchAny, "WITH", MatchAny, "OPTION", "GRANTED", "BY")) |
| 4590 |
COMPLETE_WITH_QUERY_PLUS(Query_for_list_of_roles, |
| 4591 |
Keywords_for_list_of_grant_roles); |
| 4592 |
/* Complete "ALTER DEFAULT PRIVILEGES ... GRANT/REVOKE ... TO/FROM */ |
| 4593 |
else if (Matches("ALTER", "DEFAULT", "PRIVILEGES", MatchAnyN, "TO|FROM")) |
| 4594 |
COMPLETE_WITH_QUERY_PLUS(Query_for_list_of_roles, |
| 4595 |
Keywords_for_list_of_grant_roles); |
| 4596 |
/* Offer WITH GRANT OPTION after that */ |
| 4597 |
else if (Matches("ALTER", "DEFAULT", "PRIVILEGES", MatchAnyN, "TO", MatchAny)) |
| 4598 |
COMPLETE_WITH("WITH GRANT OPTION"); |
| 4599 |
/* Complete "GRANT/REVOKE ... ON * *" with TO/FROM */ |
| 4600 |
else if (Matches("GRANT", MatchAnyN, "ON", MatchAny, MatchAny)) |
| 4601 |
COMPLETE_WITH("TO"); |
| 4602 |
else if (Matches("REVOKE", MatchAnyN, "ON", MatchAny, MatchAny)) |
| 4603 |
COMPLETE_WITH("FROM"); |
| 4604 |
|
| 4605 |
/* Complete "GRANT/REVOKE * ON ALL * IN SCHEMA *" with TO/FROM */ |
| 4606 |
else if (TailMatches("GRANT|REVOKE", MatchAny, "ON", "ALL", MatchAny, "IN", "SCHEMA", MatchAny) || |
| 4607 |
TailMatches("REVOKE", "GRANT", "OPTION", "FOR", MatchAny, "ON", "ALL", MatchAny, "IN", "SCHEMA", MatchAny)) |
| 4608 |
{ |
| 4609 |
if (TailMatches("GRANT", MatchAny, MatchAny, MatchAny, MatchAny, MatchAny, MatchAny, MatchAny)) |
| 4610 |
COMPLETE_WITH("TO"); |
| 4611 |
else |
| 4612 |
COMPLETE_WITH("FROM"); |
| 4613 |
} |
| 4614 |
|
| 4615 |
/* Complete "GRANT/REVOKE * ON FOREIGN DATA WRAPPER *" with TO/FROM */ |
| 4616 |
else if (TailMatches("GRANT|REVOKE", MatchAny, "ON", "FOREIGN", "DATA", "WRAPPER", MatchAny) || |
| 4617 |
TailMatches("REVOKE", "GRANT", "OPTION", "FOR", MatchAny, "ON", "FOREIGN", "DATA", "WRAPPER", MatchAny)) |
| 4618 |
{ |
| 4619 |
if (TailMatches("GRANT", MatchAny, MatchAny, MatchAny, MatchAny, MatchAny, MatchAny)) |
| 4620 |
COMPLETE_WITH("TO"); |
| 4621 |
else |
| 4622 |
COMPLETE_WITH("FROM"); |
| 4623 |
} |
| 4624 |
|
| 4625 |
/* Complete "GRANT/REVOKE * ON FOREIGN SERVER *" with TO/FROM */ |
| 4626 |
else if (TailMatches("GRANT|REVOKE", MatchAny, "ON", "FOREIGN", "SERVER", MatchAny) || |
| 4627 |
TailMatches("REVOKE", "GRANT", "OPTION", "FOR", MatchAny, "ON", "FOREIGN", "SERVER", MatchAny)) |
| 4628 |
{ |
| 4629 |
if (TailMatches("GRANT", MatchAny, MatchAny, MatchAny, MatchAny, MatchAny)) |
| 4630 |
COMPLETE_WITH("TO"); |
| 4631 |
else |
| 4632 |
COMPLETE_WITH("FROM"); |
| 4633 |
} |
| 4634 |
|
| 4635 |
/* GROUP BY */ |
| 4636 |
else if (TailMatches("FROM", MatchAny, "GROUP")) |
| 4637 |
COMPLETE_WITH("BY"); |
| 4638 |
|
| 4639 |
/* IMPORT FOREIGN SCHEMA */ |
| 4640 |
else if (Matches("IMPORT")) |
| 4641 |
COMPLETE_WITH("FOREIGN SCHEMA"); |
| 4642 |
else if (Matches("IMPORT", "FOREIGN")) |
| 4643 |
COMPLETE_WITH("SCHEMA"); |
| 4644 |
else if (Matches("IMPORT", "FOREIGN", "SCHEMA", MatchAny)) |
| 4645 |
COMPLETE_WITH("EXCEPT (", "FROM SERVER", "LIMIT TO ("); |
| 4646 |
else if (TailMatches("LIMIT", "TO", "(*)") || |
| 4647 |
TailMatches("EXCEPT", "(*)")) |
| 4648 |
COMPLETE_WITH("FROM SERVER"); |
| 4649 |
else if (TailMatches("FROM", "SERVER", MatchAny)) |
| 4650 |
COMPLETE_WITH("INTO"); |
| 4651 |
else if (TailMatches("FROM", "SERVER", MatchAny, "INTO")) |
| 4652 |
COMPLETE_WITH_QUERY(Query_for_list_of_schemas); |
| 4653 |
else if (TailMatches("FROM", "SERVER", MatchAny, "INTO", MatchAny)) |
| 4654 |
COMPLETE_WITH("OPTIONS ("); |
| 4655 |
|
| 4656 |
/* INSERT --- can be inside EXPLAIN, RULE, etc */ |
| 4657 |
/* Complete NOT MATCHED THEN INSERT */ |
| 4658 |
else if (TailMatches("NOT", "MATCHED", "THEN", "INSERT")) |
| 4659 |
COMPLETE_WITH("VALUES", "("); |
| 4660 |
/* Complete INSERT with "INTO" */ |
| 4661 |
else if (TailMatches("INSERT")) |
| 4662 |
COMPLETE_WITH("INTO"); |
| 4663 |
/* Complete INSERT INTO with table names */ |
| 4664 |
else if (TailMatches("INSERT", "INTO")) |
| 4665 |
COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_updatables); |
| 4666 |
/* Complete "INSERT INTO <table> (" with attribute names */ |
| 4667 |
else if (TailMatches("INSERT", "INTO", MatchAny, "(")) |
| 4668 |
COMPLETE_WITH_ATTR(prev2_wd); |
| 4669 |
|
| 4670 |
/* |
| 4671 |
* Complete INSERT INTO <table> with "(" or "VALUES" or "SELECT" or |
| 4672 |
* "TABLE" or "DEFAULT VALUES" or "OVERRIDING" |
| 4673 |
*/ |
| 4674 |
else if (TailMatches("INSERT", "INTO", MatchAny)) |
| 4675 |
COMPLETE_WITH("(", "DEFAULT VALUES", "SELECT", "TABLE", "VALUES", "OVERRIDING"); |
| 4676 |
|
| 4677 |
/* |
| 4678 |
* Complete INSERT INTO <table> (attribs) with "VALUES" or "SELECT" or |
| 4679 |
* "TABLE" or "OVERRIDING" |
| 4680 |
*/ |
| 4681 |
else if (TailMatches("INSERT", "INTO", MatchAny, MatchAny) && |
| 4682 |
ends_with(prev_wd, ')')) |
| 4683 |
COMPLETE_WITH("SELECT", "TABLE", "VALUES", "OVERRIDING"); |
| 4684 |
|
| 4685 |
/* Complete OVERRIDING */ |
| 4686 |
else if (TailMatches("OVERRIDING")) |
| 4687 |
COMPLETE_WITH("SYSTEM VALUE", "USER VALUE"); |
| 4688 |
|
| 4689 |
/* Complete after OVERRIDING clause */ |
| 4690 |
else if (TailMatches("OVERRIDING", MatchAny, "VALUE")) |
| 4691 |
COMPLETE_WITH("SELECT", "TABLE", "VALUES"); |
| 4692 |
|
| 4693 |
/* Insert an open parenthesis after "VALUES" */ |
| 4694 |
else if (TailMatches("VALUES") && !TailMatches("DEFAULT", "VALUES")) |
| 4695 |
COMPLETE_WITH("("); |
| 4696 |
|
| 4697 |
/* LOCK */ |
| 4698 |
/* Complete LOCK [TABLE] [ONLY] with a list of tables */ |
| 4699 |
else if (Matches("LOCK")) |
| 4700 |
COMPLETE_WITH_SCHEMA_QUERY_PLUS(Query_for_list_of_tables, |
| 4701 |
"TABLE", "ONLY"); |
| 4702 |
else if (Matches("LOCK", "TABLE")) |
| 4703 |
COMPLETE_WITH_SCHEMA_QUERY_PLUS(Query_for_list_of_tables, |
| 4704 |
"ONLY"); |
| 4705 |
else if (Matches("LOCK", "TABLE", "ONLY") || Matches("LOCK", "ONLY")) |
| 4706 |
COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_tables); |
| 4707 |
/* For the following, handle the case of a single table only for now */ |
| 4708 |
|
| 4709 |
/* Complete LOCK [TABLE] [ONLY] <table> with IN or NOWAIT */ |
| 4710 |
else if (Matches("LOCK", MatchAnyExcept("TABLE|ONLY")) || |
| 4711 |
Matches("LOCK", "TABLE", MatchAnyExcept("ONLY")) || |
| 4712 |
Matches("LOCK", "ONLY", MatchAny) || |
| 4713 |
Matches("LOCK", "TABLE", "ONLY", MatchAny)) |
| 4714 |
COMPLETE_WITH("IN", "NOWAIT"); |
| 4715 |
|
| 4716 |
/* Complete LOCK [TABLE] [ONLY] <table> IN with a lock mode */ |
| 4717 |
else if (Matches("LOCK", MatchAnyN, "IN")) |
| 4718 |
COMPLETE_WITH("ACCESS SHARE MODE", |
| 4719 |
"ROW SHARE MODE", "ROW EXCLUSIVE MODE", |
| 4720 |
"SHARE UPDATE EXCLUSIVE MODE", "SHARE MODE", |
| 4721 |
"SHARE ROW EXCLUSIVE MODE", |
| 4722 |
"EXCLUSIVE MODE", "ACCESS EXCLUSIVE MODE"); |
| 4723 |
|
| 4724 |
/* |
| 4725 |
* Complete LOCK [TABLE][ONLY] <table> IN ACCESS|ROW with rest of lock |
| 4726 |
* mode |
| 4727 |
*/ |
| 4728 |
else if (Matches("LOCK", MatchAnyN, "IN", "ACCESS|ROW")) |
| 4729 |
COMPLETE_WITH("EXCLUSIVE MODE", "SHARE MODE"); |
| 4730 |
|
| 4731 |
/* Complete LOCK [TABLE] [ONLY] <table> IN SHARE with rest of lock mode */ |
| 4732 |
else if (Matches("LOCK", MatchAnyN, "IN", "SHARE")) |
| 4733 |
COMPLETE_WITH("MODE", "ROW EXCLUSIVE MODE", |
| 4734 |
"UPDATE EXCLUSIVE MODE"); |
| 4735 |
|
| 4736 |
/* Complete LOCK [TABLE] [ONLY] <table> [IN lockmode MODE] with "NOWAIT" */ |
| 4737 |
else if (Matches("LOCK", MatchAnyN, "MODE")) |
| 4738 |
COMPLETE_WITH("NOWAIT"); |
| 4739 |
|
| 4740 |
/* MERGE --- can be inside EXPLAIN */ |
| 4741 |
else if (TailMatches("MERGE")) |
| 4742 |
COMPLETE_WITH("INTO"); |
| 4743 |
else if (TailMatches("MERGE", "INTO")) |
| 4744 |
COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_mergetargets); |
| 4745 |
|
| 4746 |
/* Complete MERGE INTO <table> [[AS] <alias>] with USING */ |
| 4747 |
else if (TailMatches("MERGE", "INTO", MatchAny)) |
| 4748 |
COMPLETE_WITH("USING", "AS"); |
| 4749 |
else if (TailMatches("MERGE", "INTO", MatchAny, "AS", MatchAny) || |
| 4750 |
TailMatches("MERGE", "INTO", MatchAny, MatchAnyExcept("USING|AS"))) |
| 4751 |
COMPLETE_WITH("USING"); |
| 4752 |
|
| 4753 |
/* |
| 4754 |
* Complete MERGE INTO ... USING with a list of relations supporting |
| 4755 |
* SELECT |
| 4756 |
*/ |
| 4757 |
else if (TailMatches("MERGE", "INTO", MatchAny, "USING") || |
| 4758 |
TailMatches("MERGE", "INTO", MatchAny, "AS", MatchAny, "USING") || |
| 4759 |
TailMatches("MERGE", "INTO", MatchAny, MatchAny, "USING")) |
| 4760 |
COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_selectables); |
| 4761 |
|
| 4762 |
/* |
| 4763 |
* Complete MERGE INTO <table> [[AS] <alias>] USING <relations> [[AS] |
| 4764 |
* alias] with ON |
| 4765 |
*/ |
| 4766 |
else if (TailMatches("MERGE", "INTO", MatchAny, "USING", MatchAny) || |
| 4767 |
TailMatches("MERGE", "INTO", MatchAny, "AS", MatchAny, "USING", MatchAny) || |
| 4768 |
TailMatches("MERGE", "INTO", MatchAny, MatchAny, "USING", MatchAny)) |
| 4769 |
COMPLETE_WITH("AS", "ON"); |
| 4770 |
else if (TailMatches("MERGE", "INTO", MatchAny, "USING", MatchAny, "AS", MatchAny) || |
| 4771 |
TailMatches("MERGE", "INTO", MatchAny, "AS", MatchAny, "USING", MatchAny, "AS", MatchAny) || |
| 4772 |
TailMatches("MERGE", "INTO", MatchAny, MatchAny, "USING", MatchAny, "AS", MatchAny) || |
| 4773 |
TailMatches("MERGE", "INTO", MatchAny, "USING", MatchAny, MatchAnyExcept("ON|AS")) || |
| 4774 |
TailMatches("MERGE", "INTO", MatchAny, "AS", MatchAny, "USING", MatchAny, MatchAnyExcept("ON|AS")) || |
| 4775 |
TailMatches("MERGE", "INTO", MatchAny, MatchAny, "USING", MatchAny, MatchAnyExcept("ON|AS"))) |
| 4776 |
COMPLETE_WITH("ON"); |
| 4777 |
|
| 4778 |
/* Complete MERGE INTO ... ON with target table attributes */ |
| 4779 |
else if (TailMatches("INTO", MatchAny, "USING", MatchAny, "ON")) |
| 4780 |
COMPLETE_WITH_ATTR(prev4_wd); |
| 4781 |
else if (TailMatches("INTO", MatchAny, "AS", MatchAny, "USING", MatchAny, "AS", MatchAny, "ON")) |
| 4782 |
COMPLETE_WITH_ATTR(prev8_wd); |
| 4783 |
else if (TailMatches("INTO", MatchAny, MatchAny, "USING", MatchAny, MatchAny, "ON")) |
| 4784 |
COMPLETE_WITH_ATTR(prev6_wd); |
| 4785 |
|
| 4786 |
/* |
| 4787 |
* Complete ... USING <relation> [[AS] alias] ON join condition |
| 4788 |
* (consisting of one or three words typically used) with WHEN [NOT] |
| 4789 |
* MATCHED |
| 4790 |
*/ |
| 4791 |
else if (TailMatches("USING", MatchAny, "ON", MatchAny) || |
| 4792 |
TailMatches("USING", MatchAny, "AS", MatchAny, "ON", MatchAny) || |
| 4793 |
TailMatches("USING", MatchAny, MatchAny, "ON", MatchAny) || |
| 4794 |
TailMatches("USING", MatchAny, "ON", MatchAny, MatchAnyExcept("WHEN"), MatchAnyExcept("WHEN")) || |
| 4795 |
TailMatches("USING", MatchAny, "AS", MatchAny, "ON", MatchAny, MatchAnyExcept("WHEN"), MatchAnyExcept("WHEN")) || |
| 4796 |
TailMatches("USING", MatchAny, MatchAny, "ON", MatchAny, MatchAnyExcept("WHEN"), MatchAnyExcept("WHEN"))) |
| 4797 |
COMPLETE_WITH("WHEN MATCHED", "WHEN NOT MATCHED"); |
| 4798 |
else if (TailMatches("USING", MatchAny, "ON", MatchAny, "WHEN") || |
| 4799 |
TailMatches("USING", MatchAny, "AS", MatchAny, "ON", MatchAny, "WHEN") || |
| 4800 |
TailMatches("USING", MatchAny, MatchAny, "ON", MatchAny, "WHEN") || |
| 4801 |
TailMatches("USING", MatchAny, "ON", MatchAny, MatchAny, MatchAny, "WHEN") || |
| 4802 |
TailMatches("USING", MatchAny, "AS", MatchAny, "ON", MatchAny, MatchAny, MatchAny, "WHEN") || |
| 4803 |
TailMatches("USING", MatchAny, MatchAny, "ON", MatchAny, MatchAny, MatchAny, "WHEN")) |
| 4804 |
COMPLETE_WITH("MATCHED", "NOT MATCHED"); |
| 4805 |
|
| 4806 |
/* |
| 4807 |
* Complete ... WHEN MATCHED and WHEN NOT MATCHED BY SOURCE|TARGET with |
| 4808 |
* THEN/AND |
| 4809 |
*/ |
| 4810 |
else if (TailMatches("WHEN", "MATCHED") || |
| 4811 |
TailMatches("WHEN", "NOT", "MATCHED", "BY", "SOURCE|TARGET")) |
| 4812 |
COMPLETE_WITH("THEN", "AND"); |
| 4813 |
|
| 4814 |
/* Complete ... WHEN NOT MATCHED with BY/THEN/AND */ |
| 4815 |
else if (TailMatches("WHEN", "NOT", "MATCHED")) |
| 4816 |
COMPLETE_WITH("BY", "THEN", "AND"); |
| 4817 |
|
| 4818 |
/* Complete ... WHEN NOT MATCHED BY with SOURCE/TARGET */ |
| 4819 |
else if (TailMatches("WHEN", "NOT", "MATCHED", "BY")) |
| 4820 |
COMPLETE_WITH("SOURCE", "TARGET"); |
| 4821 |
|
| 4822 |
/* |
| 4823 |
* Complete ... WHEN MATCHED THEN and WHEN NOT MATCHED BY SOURCE THEN with |
| 4824 |
* UPDATE SET/DELETE/DO NOTHING |
| 4825 |
*/ |
| 4826 |
else if (TailMatches("WHEN", "MATCHED", "THEN") || |
| 4827 |
TailMatches("WHEN", "NOT", "MATCHED", "BY", "SOURCE", "THEN")) |
| 4828 |
COMPLETE_WITH("UPDATE SET", "DELETE", "DO NOTHING"); |
| 4829 |
|
| 4830 |
/* |
| 4831 |
* Complete ... WHEN NOT MATCHED [BY TARGET] THEN with INSERT/DO NOTHING |
| 4832 |
*/ |
| 4833 |
else if (TailMatches("WHEN", "NOT", "MATCHED", "THEN") || |
| 4834 |
TailMatches("WHEN", "NOT", "MATCHED", "BY", "TARGET", "THEN")) |
| 4835 |
COMPLETE_WITH("INSERT", "DO NOTHING"); |
| 4836 |
|
| 4837 |
/* NOTIFY --- can be inside EXPLAIN, RULE, etc */ |
| 4838 |
else if (TailMatches("NOTIFY")) |
| 4839 |
COMPLETE_WITH_QUERY(Query_for_list_of_channels); |
| 4840 |
|
| 4841 |
/* OPTIONS */ |
| 4842 |
else if (TailMatches("OPTIONS")) |
| 4843 |
COMPLETE_WITH("("); |
| 4844 |
|
| 4845 |
/* OWNER TO - complete with available roles */ |
| 4846 |
else if (TailMatches("OWNER", "TO")) |
| 4847 |
COMPLETE_WITH_QUERY_PLUS(Query_for_list_of_roles, |
| 4848 |
Keywords_for_list_of_owner_roles); |
| 4849 |
|
| 4850 |
/* ORDER BY */ |
| 4851 |
else if (TailMatches("FROM", MatchAny, "ORDER")) |
| 4852 |
COMPLETE_WITH("BY"); |
| 4853 |
else if (TailMatches("FROM", MatchAny, "ORDER", "BY")) |
| 4854 |
COMPLETE_WITH_ATTR(prev3_wd); |
| 4855 |
|
| 4856 |
/* PREPARE xx AS */ |
| 4857 |
else if (Matches("PREPARE", MatchAny, "AS")) |
| 4858 |
COMPLETE_WITH("SELECT", "UPDATE", "INSERT INTO", "DELETE FROM"); |
| 4859 |
|
| 4860 |
/* |
| 4861 |
* PREPARE TRANSACTION is missing on purpose. It's intended for transaction |
| 4862 |
* managers, not for manual use in interactive sessions. |
| 4863 |
*/ |
| 4864 |
|
| 4865 |
/* REASSIGN OWNED BY xxx TO yyy */ |
| 4866 |
else if (Matches("REASSIGN")) |
| 4867 |
COMPLETE_WITH("OWNED BY"); |
| 4868 |
else if (Matches("REASSIGN", "OWNED")) |
| 4869 |
COMPLETE_WITH("BY"); |
| 4870 |
else if (Matches("REASSIGN", "OWNED", "BY")) |
| 4871 |
COMPLETE_WITH_QUERY(Query_for_list_of_roles); |
| 4872 |
else if (Matches("REASSIGN", "OWNED", "BY", MatchAny)) |
| 4873 |
COMPLETE_WITH("TO"); |
| 4874 |
else if (Matches("REASSIGN", "OWNED", "BY", MatchAny, "TO")) |
| 4875 |
COMPLETE_WITH_QUERY(Query_for_list_of_roles); |
| 4876 |
|
| 4877 |
/* REFRESH MATERIALIZED VIEW */ |
| 4878 |
else if (Matches("REFRESH")) |
| 4879 |
COMPLETE_WITH("MATERIALIZED VIEW"); |
| 4880 |
else if (Matches("REFRESH", "MATERIALIZED")) |
| 4881 |
COMPLETE_WITH("VIEW"); |
| 4882 |
else if (Matches("REFRESH", "MATERIALIZED", "VIEW")) |
| 4883 |
COMPLETE_WITH_SCHEMA_QUERY_PLUS(Query_for_list_of_matviews, |
| 4884 |
"CONCURRENTLY"); |
| 4885 |
else if (Matches("REFRESH", "MATERIALIZED", "VIEW", "CONCURRENTLY")) |
| 4886 |
COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_matviews); |
| 4887 |
else if (Matches("REFRESH", "MATERIALIZED", "VIEW", MatchAny)) |
| 4888 |
COMPLETE_WITH("WITH"); |
| 4889 |
else if (Matches("REFRESH", "MATERIALIZED", "VIEW", "CONCURRENTLY", MatchAny)) |
| 4890 |
COMPLETE_WITH("WITH"); |
| 4891 |
else if (Matches("REFRESH", "MATERIALIZED", "VIEW", MatchAny, "WITH")) |
| 4892 |
COMPLETE_WITH("NO DATA", "DATA"); |
| 4893 |
else if (Matches("REFRESH", "MATERIALIZED", "VIEW", "CONCURRENTLY", MatchAny, "WITH")) |
| 4894 |
COMPLETE_WITH("NO DATA", "DATA"); |
| 4895 |
else if (Matches("REFRESH", "MATERIALIZED", "VIEW", MatchAny, "WITH", "NO")) |
| 4896 |
COMPLETE_WITH("DATA"); |
| 4897 |
else if (Matches("REFRESH", "MATERIALIZED", "VIEW", "CONCURRENTLY", MatchAny, "WITH", "NO")) |
| 4898 |
COMPLETE_WITH("DATA"); |
| 4899 |
|
| 4900 |
/* REINDEX */ |
| 4901 |
else if (Matches("REINDEX") || |
| 4902 |
Matches("REINDEX", "(*)")) |
| 4903 |
COMPLETE_WITH("TABLE", "INDEX", "SYSTEM", "SCHEMA", "DATABASE"); |
| 4904 |
else if (Matches("REINDEX", "TABLE") || |
| 4905 |
Matches("REINDEX", "(*)", "TABLE")) |
| 4906 |
COMPLETE_WITH_SCHEMA_QUERY_PLUS(Query_for_list_of_indexables, |
| 4907 |
"CONCURRENTLY"); |
| 4908 |
else if (Matches("REINDEX", "INDEX") || |
| 4909 |
Matches("REINDEX", "(*)", "INDEX")) |
| 4910 |
COMPLETE_WITH_SCHEMA_QUERY_PLUS(Query_for_list_of_indexes, |
| 4911 |
"CONCURRENTLY"); |
| 4912 |
else if (Matches("REINDEX", "SCHEMA") || |
| 4913 |
Matches("REINDEX", "(*)", "SCHEMA")) |
| 4914 |
COMPLETE_WITH_QUERY_PLUS(Query_for_list_of_schemas, |
| 4915 |
"CONCURRENTLY"); |
| 4916 |
else if (Matches("REINDEX", "SYSTEM|DATABASE") || |
| 4917 |
Matches("REINDEX", "(*)", "SYSTEM|DATABASE")) |
| 4918 |
COMPLETE_WITH_QUERY_PLUS(Query_for_list_of_databases, |
| 4919 |
"CONCURRENTLY"); |
| 4920 |
else if (Matches("REINDEX", "TABLE", "CONCURRENTLY") || |
| 4921 |
Matches("REINDEX", "(*)", "TABLE", "CONCURRENTLY")) |
| 4922 |
COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_indexables); |
| 4923 |
else if (Matches("REINDEX", "INDEX", "CONCURRENTLY") || |
| 4924 |
Matches("REINDEX", "(*)", "INDEX", "CONCURRENTLY")) |
| 4925 |
COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_indexes); |
| 4926 |
else if (Matches("REINDEX", "SCHEMA", "CONCURRENTLY") || |
| 4927 |
Matches("REINDEX", "(*)", "SCHEMA", "CONCURRENTLY")) |
| 4928 |
COMPLETE_WITH_QUERY(Query_for_list_of_schemas); |
| 4929 |
else if (Matches("REINDEX", "SYSTEM|DATABASE", "CONCURRENTLY") || |
| 4930 |
Matches("REINDEX", "(*)", "SYSTEM|DATABASE", "CONCURRENTLY")) |
| 4931 |
COMPLETE_WITH_QUERY(Query_for_list_of_databases); |
| 4932 |
else if (HeadMatches("REINDEX", "(*") && |
| 4933 |
!HeadMatches("REINDEX", "(*)")) |
| 4934 |
{ |
| 4935 |
/* |
| 4936 |
* This fires if we're in an unfinished parenthesized option list. |
| 4937 |
* get_previous_words treats a completed parenthesized option list as |
| 4938 |
* one word, so the above test is correct. |
| 4939 |
*/ |
| 4940 |
if (ends_with(prev_wd, '(') || ends_with(prev_wd, ',')) |
| 4941 |
COMPLETE_WITH("CONCURRENTLY", "TABLESPACE", "VERBOSE"); |
| 4942 |
else if (TailMatches("TABLESPACE")) |
| 4943 |
COMPLETE_WITH_QUERY(Query_for_list_of_tablespaces); |
| 4944 |
} |
| 4945 |
|
| 4946 |
/* SECURITY LABEL */ |
| 4947 |
else if (Matches("SECURITY")) |
| 4948 |
COMPLETE_WITH("LABEL"); |
| 4949 |
else if (Matches("SECURITY", "LABEL")) |
| 4950 |
COMPLETE_WITH("ON", "FOR"); |
| 4951 |
else if (Matches("SECURITY", "LABEL", "FOR", MatchAny)) |
| 4952 |
COMPLETE_WITH("ON"); |
| 4953 |
else if (Matches("SECURITY", "LABEL", "ON") || |
| 4954 |
Matches("SECURITY", "LABEL", "FOR", MatchAny, "ON")) |
| 4955 |
COMPLETE_WITH("TABLE", "COLUMN", "AGGREGATE", "DATABASE", "DOMAIN", |
| 4956 |
"EVENT TRIGGER", "FOREIGN TABLE", "FUNCTION", |
| 4957 |
"LARGE OBJECT", "MATERIALIZED VIEW", "LANGUAGE", |
| 4958 |
"PUBLICATION", "PROCEDURE", "ROLE", "ROUTINE", "SCHEMA", |
| 4959 |
"SEQUENCE", "SUBSCRIPTION", "TABLESPACE", "TYPE", "VIEW"); |
| 4960 |
else if (Matches("SECURITY", "LABEL", "ON", MatchAny, MatchAny)) |
| 4961 |
COMPLETE_WITH("IS"); |
| 4962 |
|
| 4963 |
/* SELECT */ |
| 4964 |
/* naah . . . */ |
| 4965 |
|
| 4966 |
/* SET, RESET, SHOW */ |
| 4967 |
/* Complete with a variable name */ |
| 4968 |
else if (TailMatches("SET|RESET") && |
| 4969 |
!TailMatches("UPDATE", MatchAny, "SET") && |
| 4970 |
!TailMatches("ALTER", "DATABASE|USER|ROLE", MatchAny, "RESET")) |
| 4971 |
COMPLETE_WITH_QUERY_VERBATIM_PLUS(Query_for_list_of_set_vars, |
| 4972 |
"CONSTRAINTS", |
| 4973 |
"TRANSACTION", |
| 4974 |
"SESSION", |
| 4975 |
"ROLE", |
| 4976 |
"TABLESPACE", |
| 4977 |
"ALL"); |
| 4978 |
else if (Matches("SHOW")) |
| 4979 |
COMPLETE_WITH_QUERY_VERBATIM_PLUS(Query_for_list_of_show_vars, |
| 4980 |
"SESSION AUTHORIZATION", |
| 4981 |
"ALL"); |
| 4982 |
else if (Matches("SHOW", "SESSION")) |
| 4983 |
COMPLETE_WITH("AUTHORIZATION"); |
| 4984 |
/* Complete "SET TRANSACTION" */ |
| 4985 |
else if (Matches("SET", "TRANSACTION")) |
| 4986 |
COMPLETE_WITH("SNAPSHOT", "ISOLATION LEVEL", "READ", "DEFERRABLE", "NOT DEFERRABLE"); |
| 4987 |
else if (Matches("BEGIN|START", "TRANSACTION") || |
| 4988 |
Matches("BEGIN", "WORK") || |
| 4989 |
Matches("BEGIN") || |
| 4990 |
Matches("SET", "SESSION", "CHARACTERISTICS", "AS", "TRANSACTION")) |
| 4991 |
COMPLETE_WITH("ISOLATION LEVEL", "READ", "DEFERRABLE", "NOT DEFERRABLE"); |
| 4992 |
else if (Matches("SET|BEGIN|START", "TRANSACTION|WORK", "NOT") || |
| 4993 |
Matches("BEGIN", "NOT") || |
| 4994 |
Matches("SET", "SESSION", "CHARACTERISTICS", "AS", "TRANSACTION", "NOT")) |
| 4995 |
COMPLETE_WITH("DEFERRABLE"); |
| 4996 |
else if (Matches("SET|BEGIN|START", "TRANSACTION|WORK", "ISOLATION") || |
| 4997 |
Matches("BEGIN", "ISOLATION") || |
| 4998 |
Matches("SET", "SESSION", "CHARACTERISTICS", "AS", "TRANSACTION", "ISOLATION")) |
| 4999 |
COMPLETE_WITH("LEVEL"); |
| 5000 |
else if (Matches("SET|BEGIN|START", "TRANSACTION|WORK", "ISOLATION", "LEVEL") || |
| 5001 |
Matches("BEGIN", "ISOLATION", "LEVEL") || |
| 5002 |
Matches("SET", "SESSION", "CHARACTERISTICS", "AS", "TRANSACTION", "ISOLATION", "LEVEL")) |
| 5003 |
COMPLETE_WITH("READ", "REPEATABLE READ", "SERIALIZABLE"); |
| 5004 |
else if (Matches("SET|BEGIN|START", "TRANSACTION|WORK", "ISOLATION", "LEVEL", "READ") || |
| 5005 |
Matches("BEGIN", "ISOLATION", "LEVEL", "READ") || |
| 5006 |
Matches("SET", "SESSION", "CHARACTERISTICS", "AS", "TRANSACTION", "ISOLATION", "LEVEL", "READ")) |
| 5007 |
COMPLETE_WITH("UNCOMMITTED", "COMMITTED"); |
| 5008 |
else if (Matches("SET|BEGIN|START", "TRANSACTION|WORK", "ISOLATION", "LEVEL", "REPEATABLE") || |
| 5009 |
Matches("BEGIN", "ISOLATION", "LEVEL", "REPEATABLE") || |
| 5010 |
Matches("SET", "SESSION", "CHARACTERISTICS", "AS", "TRANSACTION", "ISOLATION", "LEVEL", "REPEATABLE")) |
| 5011 |
COMPLETE_WITH("READ"); |
| 5012 |
else if (Matches("SET|BEGIN|START", "TRANSACTION|WORK", "READ") || |
| 5013 |
Matches("BEGIN", "READ") || |
| 5014 |
Matches("SET", "SESSION", "CHARACTERISTICS", "AS", "TRANSACTION", "READ")) |
| 5015 |
COMPLETE_WITH("ONLY", "WRITE"); |
| 5016 |
/* SET CONSTRAINTS */ |
| 5017 |
else if (Matches("SET", "CONSTRAINTS")) |
| 5018 |
COMPLETE_WITH_SCHEMA_QUERY_PLUS(Query_for_list_of_constraints_with_schema, |
| 5019 |
"ALL"); |
| 5020 |
/* Complete SET CONSTRAINTS <foo> with DEFERRED|IMMEDIATE */ |
| 5021 |
else if (Matches("SET", "CONSTRAINTS", MatchAny)) |
| 5022 |
COMPLETE_WITH("DEFERRED", "IMMEDIATE"); |
| 5023 |
/* Complete SET ROLE */ |
| 5024 |
else if (Matches("SET", "ROLE")) |
| 5025 |
COMPLETE_WITH_QUERY(Query_for_list_of_roles); |
| 5026 |
/* Complete SET SESSION with AUTHORIZATION or CHARACTERISTICS... */ |
| 5027 |
else if (Matches("SET", "SESSION")) |
| 5028 |
COMPLETE_WITH("AUTHORIZATION", "CHARACTERISTICS AS TRANSACTION"); |
| 5029 |
/* Complete SET SESSION AUTHORIZATION with username */ |
| 5030 |
else if (Matches("SET", "SESSION", "AUTHORIZATION")) |
| 5031 |
COMPLETE_WITH_QUERY_PLUS(Query_for_list_of_roles, |
| 5032 |
"DEFAULT"); |
| 5033 |
/* Complete RESET SESSION with AUTHORIZATION */ |
| 5034 |
else if (Matches("RESET", "SESSION")) |
| 5035 |
COMPLETE_WITH("AUTHORIZATION"); |
| 5036 |
/* Complete SET <var> with "TO" */ |
| 5037 |
else if (Matches("SET", MatchAny)) |
| 5038 |
COMPLETE_WITH("TO"); |
| 5039 |
|
| 5040 |
/* |
| 5041 |
* Complete ALTER DATABASE|FUNCTION|PROCEDURE|ROLE|ROUTINE|USER ... SET |
| 5042 |
* <name> |
| 5043 |
*/ |
| 5044 |
else if (Matches("ALTER", "DATABASE|FUNCTION|PROCEDURE|ROLE|ROUTINE|USER", MatchAnyN, "SET", MatchAnyExcept("SCHEMA"))) |
| 5045 |
COMPLETE_WITH("FROM CURRENT", "TO"); |
| 5046 |
|
| 5047 |
/* |
| 5048 |
* Suggest possible variable values in SET variable TO|=, along with the |
| 5049 |
* preceding ALTER syntaxes. |
| 5050 |
*/ |
| 5051 |
else if (TailMatches("SET", MatchAny, "TO|=") && |
| 5052 |
!TailMatches("UPDATE", MatchAny, "SET", MatchAny, "TO|=")) |
| 5053 |
{ |
| 5054 |
/* special cased code for individual GUCs */ |
| 5055 |
if (TailMatches("DateStyle", "TO|=")) |
| 5056 |
COMPLETE_WITH("ISO", "SQL", "Postgres", "German", |
| 5057 |
"YMD", "DMY", "MDY", |
| 5058 |
"US", "European", "NonEuropean", |
| 5059 |
"DEFAULT"); |
| 5060 |
else if (TailMatches("search_path", "TO|=")) |
| 5061 |
{ |
| 5062 |
/* Here, we want to allow pg_catalog, so use narrower exclusion */ |
| 5063 |
COMPLETE_WITH_QUERY_PLUS(Query_for_list_of_schemas |
| 5064 |
" AND nspname NOT LIKE E'pg\\\\_toast%%'" |
| 5065 |
" AND nspname NOT LIKE E'pg\\\\_temp%%'", |
| 5066 |
"DEFAULT"); |
| 5067 |
} |
| 5068 |
else if (TailMatches("TimeZone", "TO|=")) |
| 5069 |
COMPLETE_WITH_TIMEZONE_NAME(); |
| 5070 |
else |
| 5071 |
{ |
| 5072 |
/* generic, type based, GUC support */ |
| 5073 |
char *guctype = get_guctype(prev2_wd); |
| 5074 |
|
| 5075 |
/* |
| 5076 |
* Note: if we don't recognize the GUC name, it's important to not |
| 5077 |
* offer any completions, as most likely we've misinterpreted the |
| 5078 |
* context and this isn't a GUC-setting command at all. |
| 5079 |
*/ |
| 5080 |
if (guctype) |
| 5081 |
{ |
| 5082 |
if (strcmp(guctype, "enum") == 0) |
| 5083 |
{ |
| 5084 |
set_completion_reference_verbatim(prev2_wd); |
| 5085 |
COMPLETE_WITH_QUERY_PLUS(Query_for_values_of_enum_GUC, |
| 5086 |
"DEFAULT"); |
| 5087 |
} |
| 5088 |
else if (strcmp(guctype, "bool") == 0) |
| 5089 |
COMPLETE_WITH("on", "off", "true", "false", "yes", "no", |
| 5090 |
"1", "0", "DEFAULT"); |
| 5091 |
else |
| 5092 |
COMPLETE_WITH("DEFAULT"); |
| 5093 |
|
| 5094 |
free(guctype); |
| 5095 |
} |
| 5096 |
} |
| 5097 |
} |
| 5098 |
|
| 5099 |
/* START TRANSACTION */ |
| 5100 |
else if (Matches("START")) |
| 5101 |
COMPLETE_WITH("TRANSACTION"); |
| 5102 |
|
| 5103 |
/* TABLE, but not TABLE embedded in other commands */ |
| 5104 |
else if (Matches("TABLE")) |
| 5105 |
COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_selectables); |
| 5106 |
|
| 5107 |
/* TABLESAMPLE */ |
| 5108 |
else if (TailMatches("TABLESAMPLE")) |
| 5109 |
COMPLETE_WITH_QUERY(Query_for_list_of_tablesample_methods); |
| 5110 |
else if (TailMatches("TABLESAMPLE", MatchAny)) |
| 5111 |
COMPLETE_WITH("("); |
| 5112 |
|
| 5113 |
/* TRUNCATE */ |
| 5114 |
else if (Matches("TRUNCATE")) |
| 5115 |
COMPLETE_WITH_SCHEMA_QUERY_PLUS(Query_for_list_of_truncatables, |
| 5116 |
"TABLE", "ONLY"); |
| 5117 |
else if (Matches("TRUNCATE", "TABLE")) |
| 5118 |
COMPLETE_WITH_SCHEMA_QUERY_PLUS(Query_for_list_of_truncatables, |
| 5119 |
"ONLY"); |
| 5120 |
else if (Matches("TRUNCATE", MatchAnyN, "ONLY")) |
| 5121 |
COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_truncatables); |
| 5122 |
else if (Matches("TRUNCATE", MatchAny) || |
| 5123 |
Matches("TRUNCATE", "TABLE|ONLY", MatchAny) || |
| 5124 |
Matches("TRUNCATE", "TABLE", "ONLY", MatchAny)) |
| 5125 |
COMPLETE_WITH("RESTART IDENTITY", "CONTINUE IDENTITY", "CASCADE", "RESTRICT"); |
| 5126 |
else if (Matches("TRUNCATE", MatchAnyN, "IDENTITY")) |
| 5127 |
COMPLETE_WITH("CASCADE", "RESTRICT"); |
| 5128 |
|
| 5129 |
/* UNLISTEN */ |
| 5130 |
else if (Matches("UNLISTEN")) |
| 5131 |
COMPLETE_WITH_QUERY_PLUS(Query_for_list_of_channels, "*"); |
| 5132 |
|
| 5133 |
/* UPDATE --- can be inside EXPLAIN, RULE, etc */ |
| 5134 |
/* If prev. word is UPDATE suggest a list of tables */ |
| 5135 |
else if (TailMatches("UPDATE")) |
| 5136 |
COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_updatables); |
| 5137 |
/* Complete UPDATE <table> with "SET" */ |
| 5138 |
else if (TailMatches("UPDATE", MatchAny)) |
| 5139 |
COMPLETE_WITH("SET"); |
| 5140 |
/* Complete UPDATE <table> SET with list of attributes */ |
| 5141 |
else if (TailMatches("UPDATE", MatchAny, "SET")) |
| 5142 |
COMPLETE_WITH_ATTR(prev2_wd); |
| 5143 |
/* UPDATE <table> SET <attr> = */ |
| 5144 |
else if (TailMatches("UPDATE", MatchAny, "SET", MatchAnyExcept("*="))) |
| 5145 |
COMPLETE_WITH("="); |
| 5146 |
|
| 5147 |
/* USER MAPPING */ |
| 5148 |
else if (Matches("ALTER|CREATE|DROP", "USER", "MAPPING")) |
| 5149 |
COMPLETE_WITH("FOR"); |
| 5150 |
else if (Matches("CREATE", "USER", "MAPPING", "FOR")) |
| 5151 |
COMPLETE_WITH_QUERY_PLUS(Query_for_list_of_roles, |
| 5152 |
"CURRENT_ROLE", |
| 5153 |
"CURRENT_USER", |
| 5154 |
"PUBLIC", |
| 5155 |
"USER"); |
| 5156 |
else if (Matches("ALTER|DROP", "USER", "MAPPING", "FOR")) |
| 5157 |
COMPLETE_WITH_QUERY(Query_for_list_of_user_mappings); |
| 5158 |
else if (Matches("CREATE|ALTER|DROP", "USER", "MAPPING", "FOR", MatchAny)) |
| 5159 |
COMPLETE_WITH("SERVER"); |
| 5160 |
else if (Matches("CREATE|ALTER", "USER", "MAPPING", "FOR", MatchAny, "SERVER", MatchAny)) |
| 5161 |
COMPLETE_WITH("OPTIONS"); |
| 5162 |
|
| 5163 |
/* |
| 5164 |
* VACUUM [ ( option [, ...] ) ] [ [ ONLY ] table_and_columns [, ...] ] |
| 5165 |
* VACUUM [ FULL ] [ FREEZE ] [ VERBOSE ] [ ANALYZE ] [ [ ONLY ] table_and_columns [, ...] ] |
| 5166 |
*/ |
| 5167 |
else if (Matches("VACUUM")) |
| 5168 |
COMPLETE_WITH_SCHEMA_QUERY_PLUS(Query_for_list_of_vacuumables, |
| 5169 |
"(", |
| 5170 |
"FULL", |
| 5171 |
"FREEZE", |
| 5172 |
"VERBOSE", |
| 5173 |
"ANALYZE", |
| 5174 |
"ONLY"); |
| 5175 |
else if (HeadMatches("VACUUM", "(*") && |
| 5176 |
!HeadMatches("VACUUM", "(*)")) |
| 5177 |
{ |
| 5178 |
/* |
| 5179 |
* This fires if we're in an unfinished parenthesized option list. |
| 5180 |
* get_previous_words treats a completed parenthesized option list as |
| 5181 |
* one word, so the above test is correct. |
| 5182 |
*/ |
| 5183 |
if (ends_with(prev_wd, '(') || ends_with(prev_wd, ',')) |
| 5184 |
COMPLETE_WITH("FULL", "FREEZE", "ANALYZE", "VERBOSE", |
| 5185 |
"DISABLE_PAGE_SKIPPING", "SKIP_LOCKED", |
| 5186 |
"INDEX_CLEANUP", "PROCESS_MAIN", "PROCESS_TOAST", |
| 5187 |
"TRUNCATE", "PARALLEL", "SKIP_DATABASE_STATS", |
| 5188 |
"ONLY_DATABASE_STATS", "BUFFER_USAGE_LIMIT"); |
| 5189 |
else if (TailMatches("FULL|FREEZE|ANALYZE|VERBOSE|DISABLE_PAGE_SKIPPING|SKIP_LOCKED|PROCESS_MAIN|PROCESS_TOAST|TRUNCATE|SKIP_DATABASE_STATS|ONLY_DATABASE_STATS")) |
| 5190 |
COMPLETE_WITH("ON", "OFF"); |
| 5191 |
else if (TailMatches("INDEX_CLEANUP")) |
| 5192 |
COMPLETE_WITH("AUTO", "ON", "OFF"); |
| 5193 |
} |
| 5194 |
else if (Matches("VACUUM", "(*)")) |
| 5195 |
COMPLETE_WITH_SCHEMA_QUERY_PLUS(Query_for_list_of_vacuumables, |
| 5196 |
"ONLY"); |
| 5197 |
else if (Matches("VACUUM", "FULL")) |
| 5198 |
COMPLETE_WITH_SCHEMA_QUERY_PLUS(Query_for_list_of_vacuumables, |
| 5199 |
"FREEZE", |
| 5200 |
"VERBOSE", |
| 5201 |
"ANALYZE", |
| 5202 |
"ONLY"); |
| 5203 |
else if (Matches("VACUUM", MatchAnyN, "FREEZE")) |
| 5204 |
COMPLETE_WITH_SCHEMA_QUERY_PLUS(Query_for_list_of_vacuumables, |
| 5205 |
"VERBOSE", |
| 5206 |
"ANALYZE", |
| 5207 |
"ONLY"); |
| 5208 |
else if (Matches("VACUUM", MatchAnyN, "VERBOSE")) |
| 5209 |
COMPLETE_WITH_SCHEMA_QUERY_PLUS(Query_for_list_of_vacuumables, |
| 5210 |
"ANALYZE", |
| 5211 |
"ONLY"); |
| 5212 |
else if (Matches("VACUUM", MatchAnyN, "ANALYZE")) |
| 5213 |
COMPLETE_WITH_SCHEMA_QUERY_PLUS(Query_for_list_of_vacuumables, |
| 5214 |
"ONLY"); |
| 5215 |
else if (Matches("VACUUM", MatchAnyN, "(")) |
| 5216 |
/* "VACUUM (" should be caught above, so assume we want columns */ |
| 5217 |
COMPLETE_WITH_ATTR(prev2_wd); |
| 5218 |
else if (HeadMatches("VACUUM")) |
| 5219 |
COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_vacuumables); |
| 5220 |
|
| 5221 |
/* WITH [RECURSIVE] */ |
| 5222 |
|
| 5223 |
/* |
| 5224 |
* Only match when WITH is the first word, as WITH may appear in many |
| 5225 |
* other contexts. |
| 5226 |
*/ |
| 5227 |
else if (Matches("WITH")) |
| 5228 |
COMPLETE_WITH("RECURSIVE"); |
| 5229 |
|
| 5230 |
/* WHERE */ |
| 5231 |
/* Simple case of the word before the where being the table name */ |
| 5232 |
else if (TailMatches(MatchAny, "WHERE")) |
| 5233 |
COMPLETE_WITH_ATTR(prev2_wd); |
| 5234 |
|
| 5235 |
/* ... FROM ... */ |
| 5236 |
/* TODO: also include SRF ? */ |
| 5237 |
else if (TailMatches("FROM") && !Matches("COPY|\\copy", MatchAny, "FROM")) |
| 5238 |
COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_selectables); |
| 5239 |
|
| 5240 |
/* ... JOIN ... */ |
| 5241 |
else if (TailMatches("JOIN")) |
| 5242 |
COMPLETE_WITH_SCHEMA_QUERY_PLUS(Query_for_list_of_selectables, "LATERAL"); |
| 5243 |
else if (TailMatches("JOIN", MatchAny) && !TailMatches("CROSS|NATURAL", "JOIN", MatchAny)) |
| 5244 |
COMPLETE_WITH("ON", "USING ("); |
| 5245 |
else if (TailMatches("JOIN", MatchAny, MatchAny) && |
| 5246 |
!TailMatches("CROSS|NATURAL", "JOIN", MatchAny, MatchAny) && !TailMatches("ON|USING")) |
| 5247 |
COMPLETE_WITH("ON", "USING ("); |
| 5248 |
else if (TailMatches("JOIN", "LATERAL", MatchAny, MatchAny) && |
| 5249 |
!TailMatches("CROSS|NATURAL", "JOIN", "LATERAL", MatchAny, MatchAny) && !TailMatches("ON|USING")) |
| 5250 |
COMPLETE_WITH("ON", "USING ("); |
| 5251 |
else if (TailMatches("JOIN", MatchAny, "USING") || |
| 5252 |
TailMatches("JOIN", MatchAny, MatchAny, "USING") || |
| 5253 |
TailMatches("JOIN", "LATERAL", MatchAny, MatchAny, "USING")) |
| 5254 |
COMPLETE_WITH("("); |
| 5255 |
else if (TailMatches("JOIN", MatchAny, "USING", "(")) |
| 5256 |
COMPLETE_WITH_ATTR(prev3_wd); |
| 5257 |
else if (TailMatches("JOIN", MatchAny, MatchAny, "USING", "(")) |
| 5258 |
COMPLETE_WITH_ATTR(prev4_wd); |
| 5259 |
|
| 5260 |
/* ... AT [ LOCAL | TIME ZONE ] ... */ |
| 5261 |
else if (TailMatches("AT")) |
| 5262 |
COMPLETE_WITH("LOCAL", "TIME ZONE"); |
| 5263 |
else if (TailMatches("AT", "TIME", "ZONE")) |
| 5264 |
COMPLETE_WITH_TIMEZONE_NAME(); |
| 5265 |
|
| 5266 |
/* Backslash commands */ |
| 5267 |
/* TODO: \dc \dd \dl */ |
| 5268 |
else if (TailMatchesCS("\\?")) |
| 5269 |
COMPLETE_WITH_CS("commands", "options", "variables"); |
| 5270 |
else if (TailMatchesCS("\\connect|\\c")) |
| 5271 |
{ |
| 5272 |
if (!recognized_connection_string(text)) |
| 5273 |
COMPLETE_WITH_QUERY(Query_for_list_of_databases); |
| 5274 |
} |
| 5275 |
else if (TailMatchesCS("\\connect|\\c", MatchAny)) |
| 5276 |
{ |
| 5277 |
if (!recognized_connection_string(prev_wd)) |
| 5278 |
COMPLETE_WITH_QUERY(Query_for_list_of_roles); |
| 5279 |
} |
| 5280 |
else if (TailMatchesCS("\\da*")) |
| 5281 |
COMPLETE_WITH_VERSIONED_SCHEMA_QUERY(Query_for_list_of_aggregates); |
| 5282 |
else if (TailMatchesCS("\\dAc*", MatchAny) || |
| 5283 |
TailMatchesCS("\\dAf*", MatchAny)) |
| 5284 |
COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_datatypes); |
| 5285 |
else if (TailMatchesCS("\\dAo*", MatchAny) || |
| 5286 |
TailMatchesCS("\\dAp*", MatchAny)) |
| 5287 |
COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_operator_families); |
| 5288 |
else if (TailMatchesCS("\\dA*")) |
| 5289 |
COMPLETE_WITH_QUERY(Query_for_list_of_access_methods); |
| 5290 |
else if (TailMatchesCS("\\db*")) |
| 5291 |
COMPLETE_WITH_QUERY(Query_for_list_of_tablespaces); |
| 5292 |
else if (TailMatchesCS("\\dconfig*")) |
| 5293 |
COMPLETE_WITH_QUERY_VERBATIM(Query_for_list_of_show_vars); |
| 5294 |
else if (TailMatchesCS("\\dD*")) |
| 5295 |
COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_domains); |
| 5296 |
else if (TailMatchesCS("\\des*")) |
| 5297 |
COMPLETE_WITH_QUERY(Query_for_list_of_servers); |
| 5298 |
else if (TailMatchesCS("\\deu*")) |
| 5299 |
COMPLETE_WITH_QUERY(Query_for_list_of_user_mappings); |
| 5300 |
else if (TailMatchesCS("\\dew*")) |
| 5301 |
COMPLETE_WITH_QUERY(Query_for_list_of_fdws); |
| 5302 |
else if (TailMatchesCS("\\df*")) |
| 5303 |
COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_routines); |
| 5304 |
else if (HeadMatchesCS("\\df*")) |
| 5305 |
COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_datatypes); |
| 5306 |
|
| 5307 |
else if (TailMatchesCS("\\dFd*")) |
| 5308 |
COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_ts_dictionaries); |
| 5309 |
else if (TailMatchesCS("\\dFp*")) |
| 5310 |
COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_ts_parsers); |
| 5311 |
else if (TailMatchesCS("\\dFt*")) |
| 5312 |
COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_ts_templates); |
| 5313 |
/* must be at end of \dF alternatives: */ |
| 5314 |
else if (TailMatchesCS("\\dF*")) |
| 5315 |
COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_ts_configurations); |
| 5316 |
|
| 5317 |
else if (TailMatchesCS("\\di*")) |
| 5318 |
COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_indexes); |
| 5319 |
else if (TailMatchesCS("\\dL*")) |
| 5320 |
COMPLETE_WITH_QUERY(Query_for_list_of_languages); |
| 5321 |
else if (TailMatchesCS("\\dn*")) |
| 5322 |
COMPLETE_WITH_QUERY(Query_for_list_of_schemas); |
| 5323 |
/* no support for completing operators, but we can complete types: */ |
| 5324 |
else if (HeadMatchesCS("\\do*", MatchAny)) |
| 5325 |
COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_datatypes); |
| 5326 |
else if (TailMatchesCS("\\dp") || TailMatchesCS("\\z")) |
| 5327 |
COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_grantables); |
| 5328 |
else if (TailMatchesCS("\\dPi*")) |
| 5329 |
COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_partitioned_indexes); |
| 5330 |
else if (TailMatchesCS("\\dPt*")) |
| 5331 |
COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_partitioned_tables); |
| 5332 |
else if (TailMatchesCS("\\dP*")) |
| 5333 |
COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_partitioned_relations); |
| 5334 |
else if (TailMatchesCS("\\dRp*")) |
| 5335 |
COMPLETE_WITH_VERSIONED_QUERY(Query_for_list_of_publications); |
| 5336 |
else if (TailMatchesCS("\\dRs*")) |
| 5337 |
COMPLETE_WITH_VERSIONED_QUERY(Query_for_list_of_subscriptions); |
| 5338 |
else if (TailMatchesCS("\\ds*")) |
| 5339 |
COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_sequences); |
| 5340 |
else if (TailMatchesCS("\\dt*")) |
| 5341 |
COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_tables); |
| 5342 |
else if (TailMatchesCS("\\dT*")) |
| 5343 |
COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_datatypes); |
| 5344 |
else if (TailMatchesCS("\\du*") || |
| 5345 |
TailMatchesCS("\\dg*") || |
| 5346 |
TailMatchesCS("\\drg*")) |
| 5347 |
COMPLETE_WITH_QUERY(Query_for_list_of_roles); |
| 5348 |
else if (TailMatchesCS("\\dv*")) |
| 5349 |
COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_views); |
| 5350 |
else if (TailMatchesCS("\\dx*")) |
| 5351 |
COMPLETE_WITH_QUERY(Query_for_list_of_extensions); |
| 5352 |
else if (TailMatchesCS("\\dX*")) |
| 5353 |
COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_statistics); |
| 5354 |
else if (TailMatchesCS("\\dm*")) |
| 5355 |
COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_matviews); |
| 5356 |
else if (TailMatchesCS("\\dE*")) |
| 5357 |
COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_foreign_tables); |
| 5358 |
else if (TailMatchesCS("\\dy*")) |
| 5359 |
COMPLETE_WITH_QUERY(Query_for_list_of_event_triggers); |
| 5360 |
|
| 5361 |
/* must be at end of \d alternatives: */ |
| 5362 |
else if (TailMatchesCS("\\d*")) |
| 5363 |
COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_relations); |
| 5364 |
|
| 5365 |
else if (TailMatchesCS("\\ef")) |
| 5366 |
COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_routines); |
| 5367 |
else if (TailMatchesCS("\\ev")) |
| 5368 |
COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_views); |
| 5369 |
|
| 5370 |
else if (TailMatchesCS("\\encoding")) |
| 5371 |
COMPLETE_WITH_QUERY_VERBATIM(Query_for_list_of_encodings); |
| 5372 |
else if (TailMatchesCS("\\h|\\help")) |
| 5373 |
COMPLETE_WITH_LIST(sql_commands); |
| 5374 |
else if (TailMatchesCS("\\h|\\help", MatchAny)) |
| 5375 |
{ |
| 5376 |
if (TailMatches("DROP")) |
| 5377 |
matches = rl_completion_matches(text, drop_command_generator); |
| 5378 |
else if (TailMatches("ALTER")) |
| 5379 |
matches = rl_completion_matches(text, alter_command_generator); |
| 5380 |
|
| 5381 |
/* |
| 5382 |
* CREATE is recognized by tail match elsewhere, so doesn't need to be |
| 5383 |
* repeated here |
| 5384 |
*/ |
| 5385 |
} |
| 5386 |
else if (TailMatchesCS("\\h|\\help", MatchAny, MatchAny)) |
| 5387 |
{ |
| 5388 |
if (TailMatches("CREATE|DROP", "ACCESS")) |
| 5389 |
COMPLETE_WITH("METHOD"); |
| 5390 |
else if (TailMatches("ALTER", "DEFAULT")) |
| 5391 |
COMPLETE_WITH("PRIVILEGES"); |
| 5392 |
else if (TailMatches("CREATE|ALTER|DROP", "EVENT")) |
| 5393 |
COMPLETE_WITH("TRIGGER"); |
| 5394 |
else if (TailMatches("CREATE|ALTER|DROP", "FOREIGN")) |
| 5395 |
COMPLETE_WITH("DATA WRAPPER", "TABLE"); |
| 5396 |
else if (TailMatches("ALTER", "LARGE")) |
| 5397 |
COMPLETE_WITH("OBJECT"); |
| 5398 |
else if (TailMatches("CREATE|ALTER|DROP", "MATERIALIZED")) |
| 5399 |
COMPLETE_WITH("VIEW"); |
| 5400 |
else if (TailMatches("CREATE|ALTER|DROP", "TEXT")) |
| 5401 |
COMPLETE_WITH("SEARCH"); |
| 5402 |
else if (TailMatches("CREATE|ALTER|DROP", "USER")) |
| 5403 |
COMPLETE_WITH("MAPPING FOR"); |
| 5404 |
} |
| 5405 |
else if (TailMatchesCS("\\h|\\help", MatchAny, MatchAny, MatchAny)) |
| 5406 |
{ |
| 5407 |
if (TailMatches("CREATE|ALTER|DROP", "FOREIGN", "DATA")) |
| 5408 |
COMPLETE_WITH("WRAPPER"); |
| 5409 |
else if (TailMatches("CREATE|ALTER|DROP", "TEXT", "SEARCH")) |
| 5410 |
COMPLETE_WITH("CONFIGURATION", "DICTIONARY", "PARSER", "TEMPLATE"); |
| 5411 |
else if (TailMatches("CREATE|ALTER|DROP", "USER", "MAPPING")) |
| 5412 |
COMPLETE_WITH("FOR"); |
| 5413 |
} |
| 5414 |
else if (TailMatchesCS("\\l*") && !TailMatchesCS("\\lo*")) |
| 5415 |
COMPLETE_WITH_QUERY(Query_for_list_of_databases); |
| 5416 |
else if (TailMatchesCS("\\password")) |
| 5417 |
COMPLETE_WITH_QUERY(Query_for_list_of_roles); |
| 5418 |
else if (TailMatchesCS("\\pset")) |
| 5419 |
COMPLETE_WITH_CS("border", "columns", "csv_fieldsep", "expanded", |
| 5420 |
"fieldsep", "fieldsep_zero", "footer", "format", |
| 5421 |
"linestyle", "null", "numericlocale", |
| 5422 |
"pager", "pager_min_lines", |
| 5423 |
"recordsep", "recordsep_zero", |
| 5424 |
"tableattr", "title", "tuples_only", |
| 5425 |
"unicode_border_linestyle", |
| 5426 |
"unicode_column_linestyle", |
| 5427 |
"unicode_header_linestyle", |
| 5428 |
"xheader_width"); |
| 5429 |
else if (TailMatchesCS("\\pset", MatchAny)) |
| 5430 |
{ |
| 5431 |
if (TailMatchesCS("format")) |
| 5432 |
COMPLETE_WITH_CS("aligned", "asciidoc", "csv", "html", "latex", |
| 5433 |
"latex-longtable", "troff-ms", "unaligned", |
| 5434 |
"wrapped"); |
| 5435 |
else if (TailMatchesCS("xheader_width")) |
| 5436 |
COMPLETE_WITH_CS("full", "column", "page"); |
| 5437 |
else if (TailMatchesCS("linestyle")) |
| 5438 |
COMPLETE_WITH_CS("ascii", "old-ascii", "unicode"); |
| 5439 |
else if (TailMatchesCS("pager")) |
| 5440 |
COMPLETE_WITH_CS("on", "off", "always"); |
| 5441 |
else if (TailMatchesCS("unicode_border_linestyle|" |
| 5442 |
"unicode_column_linestyle|" |
| 5443 |
"unicode_header_linestyle")) |
| 5444 |
COMPLETE_WITH_CS("single", "double"); |
| 5445 |
} |
| 5446 |
else if (TailMatchesCS("\\unset")) |
| 5447 |
matches = complete_from_variables(text, "", "", true); |
| 5448 |
else if (TailMatchesCS("\\set")) |
| 5449 |
matches = complete_from_variables(text, "", "", false); |
| 5450 |
else if (TailMatchesCS("\\set", MatchAny)) |
| 5451 |
{ |
| 5452 |
if (TailMatchesCS("AUTOCOMMIT|ON_ERROR_STOP|QUIET|SHOW_ALL_RESULTS|" |
| 5453 |
"SINGLELINE|SINGLESTEP")) |
| 5454 |
COMPLETE_WITH_CS("on", "off"); |
| 5455 |
else if (TailMatchesCS("COMP_KEYWORD_CASE")) |
| 5456 |
COMPLETE_WITH_CS("lower", "upper", |
| 5457 |
"preserve-lower", "preserve-upper"); |
| 5458 |
else if (TailMatchesCS("ECHO")) |
| 5459 |
COMPLETE_WITH_CS("errors", "queries", "all", "none"); |
| 5460 |
else if (TailMatchesCS("ECHO_HIDDEN")) |
| 5461 |
COMPLETE_WITH_CS("noexec", "off", "on"); |
| 5462 |
else if (TailMatchesCS("HISTCONTROL")) |
| 5463 |
COMPLETE_WITH_CS("ignorespace", "ignoredups", |
| 5464 |
"ignoreboth", "none"); |
| 5465 |
else if (TailMatchesCS("ON_ERROR_ROLLBACK")) |
| 5466 |
COMPLETE_WITH_CS("on", "off", "interactive"); |
| 5467 |
else if (TailMatchesCS("SHOW_CONTEXT")) |
| 5468 |
COMPLETE_WITH_CS("never", "errors", "always"); |
| 5469 |
else if (TailMatchesCS("VERBOSITY")) |
| 5470 |
COMPLETE_WITH_CS("default", "verbose", "terse", "sqlstate"); |
| 5471 |
} |
| 5472 |
else if (TailMatchesCS("\\sf*")) |
| 5473 |
COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_routines); |
| 5474 |
else if (TailMatchesCS("\\sv*")) |
| 5475 |
COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_views); |
| 5476 |
else if (TailMatchesCS("\\cd|\\e|\\edit|\\g|\\gx|\\i|\\include|" |
| 5477 |
"\\ir|\\include_relative|\\o|\\out|" |
| 5478 |
"\\s|\\w|\\write|\\lo_import")) |
| 5479 |
{ |
| 5480 |
completion_charp = "\\"; |
| 5481 |
completion_force_quote = false; |
| 5482 |
matches = rl_completion_matches(text, complete_from_files); |
| 5483 |
} |
| 5484 |
|
| 5485 |
/* gen_tabcomplete.pl ends special processing here */ |
| 5486 |
/* END GEN_TABCOMPLETE */ |
| 5487 |
|
| 5488 |
return matches; |
| 5489 |
} |
| 5490 |
|
| 5491 |
|
| 5492 |
/* |
| 5493 |
* GENERATOR FUNCTIONS |
| 5494 |
* |
| 5495 |
* These functions do all the actual work of completing the input. They get |
| 5496 |
* passed the text so far and the count how many times they have been called |
| 5497 |
* so far with the same text. |
| 5498 |
* If you read the above carefully, you'll see that these don't get called |
| 5499 |
* directly but through the readline interface. |
| 5500 |
* The return value is expected to be the full completion of the text, going |
| 5501 |
* through a list each time, or NULL if there are no more matches. The string |
| 5502 |
* will be free()'d by readline, so you must run it through strdup() or |
| 5503 |
* something of that sort. |
| 5504 |
*/ |
| 5505 |
|
| 5506 |
/* |
| 5507 |
* Common routine for create_command_generator and drop_command_generator. |
| 5508 |
* Entries that have 'excluded' flags are not returned. |
| 5509 |
*/ |
| 5510 |
static char * |
| 5511 |
create_or_drop_command_generator(const char *text, int state, bits32 excluded) |
| 5512 |
{ |
| 5513 |
static int list_index, |
| 5514 |
string_length; |
| 5515 |
const char *name; |
| 5516 |
|
| 5517 |
/* If this is the first time for this completion, init some values */ |
| 5518 |
if (state == 0) |
| 5519 |
{ |
| 5520 |
list_index = 0; |
| 5521 |
string_length = strlen(text); |
| 5522 |
} |
| 5523 |
|
| 5524 |
/* find something that matches */ |
| 5525 |
while ((name = words_after_create[list_index++].name)) |
| 5526 |
{ |
| 5527 |
if ((pg_strncasecmp(name, text, string_length) == 0) && |
| 5528 |
!(words_after_create[list_index - 1].flags & excluded)) |
| 5529 |
return pg_strdup_keyword_case(name, text); |
| 5530 |
} |
| 5531 |
/* if nothing matches, return NULL */ |
| 5532 |
return NULL; |
| 5533 |
} |
| 5534 |
|
| 5535 |
/* |
| 5536 |
* This one gives you one from a list of things you can put after CREATE |
| 5537 |
* as defined above. |
| 5538 |
*/ |
| 5539 |
static char * |
| 5540 |
create_command_generator(const char *text, int state) |
| 5541 |
{ |
| 5542 |
return create_or_drop_command_generator(text, state, THING_NO_CREATE); |
| 5543 |
} |
| 5544 |
|
| 5545 |
/* |
| 5546 |
* This function gives you a list of things you can put after a DROP command. |
| 5547 |
*/ |
| 5548 |
static char * |
| 5549 |
drop_command_generator(const char *text, int state) |
| 5550 |
{ |
| 5551 |
return create_or_drop_command_generator(text, state, THING_NO_DROP); |
| 5552 |
} |
| 5553 |
|
| 5554 |
/* |
| 5555 |
* This function gives you a list of things you can put after an ALTER command. |
| 5556 |
*/ |
| 5557 |
static char * |
| 5558 |
alter_command_generator(const char *text, int state) |
| 5559 |
{ |
| 5560 |
return create_or_drop_command_generator(text, state, THING_NO_ALTER); |
| 5561 |
} |
| 5562 |
|
| 5563 |
/* |
| 5564 |
* These functions generate lists using server queries. |
| 5565 |
* They are all wrappers for _complete_from_query. |
| 5566 |
*/ |
| 5567 |
|
| 5568 |
static char * |
| 5569 |
complete_from_query(const char *text, int state) |
| 5570 |
{ |
| 5571 |
/* query is assumed to work for any server version */ |
| 5572 |
return _complete_from_query(completion_charp, NULL, completion_charpp, |
| 5573 |
completion_verbatim, text, state); |
| 5574 |
} |
| 5575 |
|
| 5576 |
static char * |
| 5577 |
complete_from_versioned_query(const char *text, int state) |
| 5578 |
{ |
| 5579 |
const VersionedQuery *vquery = completion_vquery; |
| 5580 |
|
| 5581 |
/* Find appropriate array element */ |
| 5582 |
while (pset.sversion < vquery->min_server_version) |
| 5583 |
vquery++; |
| 5584 |
/* Fail completion if server is too old */ |
| 5585 |
if (vquery->query == NULL) |
| 5586 |
return NULL; |
| 5587 |
|
| 5588 |
return _complete_from_query(vquery->query, NULL, completion_charpp, |
| 5589 |
completion_verbatim, text, state); |
| 5590 |
} |
| 5591 |
|
| 5592 |
static char * |
| 5593 |
complete_from_schema_query(const char *text, int state) |
| 5594 |
{ |
| 5595 |
/* query is assumed to work for any server version */ |
| 5596 |
return _complete_from_query(NULL, completion_squery, completion_charpp, |
| 5597 |
completion_verbatim, text, state); |
| 5598 |
} |
| 5599 |
|
| 5600 |
static char * |
| 5601 |
complete_from_versioned_schema_query(const char *text, int state) |
| 5602 |
{ |
| 5603 |
const SchemaQuery *squery = completion_squery; |
| 5604 |
|
| 5605 |
/* Find appropriate array element */ |
| 5606 |
while (pset.sversion < squery->min_server_version) |
| 5607 |
squery++; |
| 5608 |
/* Fail completion if server is too old */ |
| 5609 |
if (squery->catname == NULL) |
| 5610 |
return NULL; |
| 5611 |
|
| 5612 |
return _complete_from_query(NULL, squery, completion_charpp, |
| 5613 |
completion_verbatim, text, state); |
| 5614 |
} |
| 5615 |
|
| 5616 |
|
| 5617 |
/* |
| 5618 |
* This creates a list of matching things, according to a query described by |
| 5619 |
* the initial arguments. The caller has already done any work needed to |
| 5620 |
* select the appropriate query for the server's version. |
| 5621 |
* |
| 5622 |
* The query can be one of two kinds: |
| 5623 |
* |
| 5624 |
* 1. A simple query, which must contain a restriction clause of the form |
| 5625 |
* output LIKE '%s' |
| 5626 |
* where "output" is the same string that the query returns. The %s |
| 5627 |
* will be replaced by a LIKE pattern to match the already-typed text. |
| 5628 |
* There can be a second '%s', which will be replaced by a suitably-escaped |
| 5629 |
* version of the string provided in completion_ref_object. If there is a |
| 5630 |
* third '%s', it will be replaced by a suitably-escaped version of the string |
| 5631 |
* provided in completion_ref_schema. Those strings should be set up |
| 5632 |
* by calling set_completion_reference or set_completion_reference_verbatim. |
| 5633 |
* Simple queries should return a single column of matches. If "verbatim" |
| 5634 |
* is true, the matches are returned as-is; otherwise, they are taken to |
| 5635 |
* be SQL identifiers and quoted if necessary. |
| 5636 |
* |
| 5637 |
* 2. A schema query used for completion of both schema and relation names. |
| 5638 |
* This is represented by a SchemaQuery object; see that typedef for details. |
| 5639 |
* |
| 5640 |
* See top of file for examples of both kinds of query. |
| 5641 |
* |
| 5642 |
* In addition to the query itself, we accept a null-terminated array of |
| 5643 |
* literal keywords, which will be returned if they match the input-so-far |
| 5644 |
* (case insensitively). (These are in addition to keywords specified |
| 5645 |
* within the schema_query, if any.) |
| 5646 |
* |
| 5647 |
* If "verbatim" is true, then we use the given text as-is to match the |
| 5648 |
* query results; otherwise we parse it as a possibly-qualified identifier, |
| 5649 |
* and reconstruct suitable quoting afterward. |
| 5650 |
* |
| 5651 |
* "text" and "state" are supplied by Readline. "text" is the word we are |
| 5652 |
* trying to complete. "state" is zero on first call, nonzero later. |
| 5653 |
* |
| 5654 |
* readline will call this repeatedly with the same text and varying |
| 5655 |
* state. On each call, we are supposed to return a malloc'd string |
| 5656 |
* that is a candidate completion. Return NULL when done. |
| 5657 |
*/ |
| 5658 |
static char * |
| 5659 |
_complete_from_query(const char *simple_query, |
| 5660 |
const SchemaQuery *schema_query, |
| 5661 |
const char *const *keywords, |
| 5662 |
bool verbatim, |
| 5663 |
const char *text, int state) |
| 5664 |
{ |
| 5665 |
static int list_index, |
| 5666 |
num_schema_only, |
| 5667 |
num_query_other, |
| 5668 |
num_keywords; |
| 5669 |
static PGresult *result = NULL; |
| 5670 |
static bool non_empty_object; |
| 5671 |
static bool schemaquoted; |
| 5672 |
static bool objectquoted; |
| 5673 |
|
| 5674 |
/* |
| 5675 |
* If this is the first time for this completion, we fetch a list of our |
| 5676 |
* "things" from the backend. |
| 5677 |
*/ |
| 5678 |
if (state == 0) |
| 5679 |
{ |
| 5680 |
PQExpBufferData query_buffer; |
| 5681 |
char *schemaname; |
| 5682 |
char *objectname; |
| 5683 |
char *e_object_like; |
| 5684 |
char *e_schemaname; |
| 5685 |
char *e_ref_object; |
| 5686 |
char *e_ref_schema; |
| 5687 |
|
| 5688 |
/* Reset static state, ensuring no memory leaks */ |
| 5689 |
list_index = 0; |
| 5690 |
num_schema_only = 0; |
| 5691 |
num_query_other = 0; |
| 5692 |
num_keywords = 0; |
| 5693 |
PQclear(result); |
| 5694 |
result = NULL; |
| 5695 |
|
| 5696 |
/* Parse text, splitting into schema and object name if needed */ |
| 5697 |
if (verbatim) |
| 5698 |
{ |
| 5699 |
objectname = pg_strdup(text); |
| 5700 |
schemaname = NULL; |
| 5701 |
} |
| 5702 |
else |
| 5703 |
{ |
| 5704 |
parse_identifier(text, |
| 5705 |
&schemaname, &objectname, |
| 5706 |
&schemaquoted, &objectquoted); |
| 5707 |
} |
| 5708 |
|
| 5709 |
/* Remember whether the user has typed anything in the object part */ |
| 5710 |
non_empty_object = (*objectname != '\0'); |
| 5711 |
|
| 5712 |
/* |
| 5713 |
* Convert objectname to a LIKE prefix pattern (e.g. 'foo%'), and set |
| 5714 |
* up suitably-escaped copies of all the strings we need. |
| 5715 |
*/ |
| 5716 |
e_object_like = make_like_pattern(objectname); |
| 5717 |
|
| 5718 |
if (schemaname) |
| 5719 |
e_schemaname = escape_string(schemaname); |
| 5720 |
else |
| 5721 |
e_schemaname = NULL; |
| 5722 |
|
| 5723 |
if (completion_ref_object) |
| 5724 |
e_ref_object = escape_string(completion_ref_object); |
| 5725 |
else |
| 5726 |
e_ref_object = NULL; |
| 5727 |
|
| 5728 |
if (completion_ref_schema) |
| 5729 |
e_ref_schema = escape_string(completion_ref_schema); |
| 5730 |
else |
| 5731 |
e_ref_schema = NULL; |
| 5732 |
|
| 5733 |
initPQExpBuffer(&query_buffer); |
| 5734 |
|
| 5735 |
if (schema_query) |
| 5736 |
{ |
| 5737 |
Assert(simple_query == NULL); |
| 5738 |
|
| 5739 |
/* |
| 5740 |
* We issue different queries depending on whether the input is |
| 5741 |
* already qualified or not. schema_query gives us the pieces to |
| 5742 |
* assemble. |
| 5743 |
*/ |
| 5744 |
if (schemaname == NULL || schema_query->namespace == NULL) |
| 5745 |
{ |
| 5746 |
/* Get unqualified names matching the input-so-far */ |
| 5747 |
appendPQExpBufferStr(&query_buffer, "SELECT "); |
| 5748 |
if (schema_query->use_distinct) |
| 5749 |
appendPQExpBufferStr(&query_buffer, "DISTINCT "); |
| 5750 |
appendPQExpBuffer(&query_buffer, |
| 5751 |
"%s, NULL::pg_catalog.text FROM %s", |
| 5752 |
schema_query->result, |
| 5753 |
schema_query->catname); |
| 5754 |
if (schema_query->refnamespace && completion_ref_schema) |
| 5755 |
appendPQExpBufferStr(&query_buffer, |
| 5756 |
", pg_catalog.pg_namespace nr"); |
| 5757 |
appendPQExpBufferStr(&query_buffer, " WHERE "); |
| 5758 |
if (schema_query->selcondition) |
| 5759 |
appendPQExpBuffer(&query_buffer, "%s AND ", |
| 5760 |
schema_query->selcondition); |
| 5761 |
appendPQExpBuffer(&query_buffer, "(%s) LIKE '%s'", |
| 5762 |
schema_query->result, |
| 5763 |
e_object_like); |
| 5764 |
if (schema_query->viscondition) |
| 5765 |
appendPQExpBuffer(&query_buffer, " AND %s", |
| 5766 |
schema_query->viscondition); |
| 5767 |
if (schema_query->refname) |
| 5768 |
{ |
| 5769 |
Assert(completion_ref_object); |
| 5770 |
appendPQExpBuffer(&query_buffer, " AND %s = '%s'", |
| 5771 |
schema_query->refname, e_ref_object); |
| 5772 |
if (schema_query->refnamespace && completion_ref_schema) |
| 5773 |
appendPQExpBuffer(&query_buffer, |
| 5774 |
" AND %s = nr.oid AND nr.nspname = '%s'", |
| 5775 |
schema_query->refnamespace, |
| 5776 |
e_ref_schema); |
| 5777 |
else if (schema_query->refviscondition) |
| 5778 |
appendPQExpBuffer(&query_buffer, |
| 5779 |
" AND %s", |
| 5780 |
schema_query->refviscondition); |
| 5781 |
} |
| 5782 |
|
| 5783 |
/* |
| 5784 |
* When fetching relation names, suppress system catalogs |
| 5785 |
* unless the input-so-far begins with "pg_". This is a |
| 5786 |
* compromise between not offering system catalogs for |
| 5787 |
* completion at all, and having them swamp the result when |
| 5788 |
* the input is just "p". |
| 5789 |
*/ |
| 5790 |
if (strcmp(schema_query->catname, |
| 5791 |
"pg_catalog.pg_class c") == 0 && |
| 5792 |
strncmp(objectname, "pg_", 3) != 0) |
| 5793 |
{ |
| 5794 |
appendPQExpBufferStr(&query_buffer, |
| 5795 |
" AND c.relnamespace <> (SELECT oid FROM" |
| 5796 |
" pg_catalog.pg_namespace WHERE nspname = 'pg_catalog')"); |
| 5797 |
} |
| 5798 |
|
| 5799 |
/* |
| 5800 |
* If the target object type can be schema-qualified, add in |
| 5801 |
* schema names matching the input-so-far. |
| 5802 |
*/ |
| 5803 |
if (schema_query->namespace) |
| 5804 |
{ |
| 5805 |
appendPQExpBuffer(&query_buffer, "\nUNION ALL\n" |
| 5806 |
"SELECT NULL::pg_catalog.text, n.nspname " |
| 5807 |
"FROM pg_catalog.pg_namespace n " |
| 5808 |
"WHERE n.nspname LIKE '%s'", |
| 5809 |
e_object_like); |
| 5810 |
|
| 5811 |
/* |
| 5812 |
* Likewise, suppress system schemas unless the |
| 5813 |
* input-so-far begins with "pg_". |
| 5814 |
*/ |
| 5815 |
if (strncmp(objectname, "pg_", 3) != 0) |
| 5816 |
appendPQExpBufferStr(&query_buffer, |
| 5817 |
" AND n.nspname NOT LIKE E'pg\\\\_%'"); |
| 5818 |
|
| 5819 |
/* |
| 5820 |
* Since we're matching these schema names to the object |
| 5821 |
* name, handle their quoting using the object name's |
| 5822 |
* quoting state. |
| 5823 |
*/ |
| 5824 |
schemaquoted = objectquoted; |
| 5825 |
} |
| 5826 |
} |
| 5827 |
else |
| 5828 |
{ |
| 5829 |
/* Input is qualified, so produce only qualified names */ |
| 5830 |
appendPQExpBufferStr(&query_buffer, "SELECT "); |
| 5831 |
if (schema_query->use_distinct) |
| 5832 |
appendPQExpBufferStr(&query_buffer, "DISTINCT "); |
| 5833 |
appendPQExpBuffer(&query_buffer, "%s, n.nspname " |
| 5834 |
"FROM %s, pg_catalog.pg_namespace n", |
| 5835 |
schema_query->result, |
| 5836 |
schema_query->catname); |
| 5837 |
if (schema_query->refnamespace && completion_ref_schema) |
| 5838 |
appendPQExpBufferStr(&query_buffer, |
| 5839 |
", pg_catalog.pg_namespace nr"); |
| 5840 |
appendPQExpBuffer(&query_buffer, " WHERE %s = n.oid AND ", |
| 5841 |
schema_query->namespace); |
| 5842 |
if (schema_query->selcondition) |
| 5843 |
appendPQExpBuffer(&query_buffer, "%s AND ", |
| 5844 |
schema_query->selcondition); |
| 5845 |
appendPQExpBuffer(&query_buffer, "(%s) LIKE '%s' AND ", |
| 5846 |
schema_query->result, |
| 5847 |
e_object_like); |
| 5848 |
appendPQExpBuffer(&query_buffer, "n.nspname = '%s'", |
| 5849 |
e_schemaname); |
| 5850 |
if (schema_query->refname) |
| 5851 |
{ |
| 5852 |
Assert(completion_ref_object); |
| 5853 |
appendPQExpBuffer(&query_buffer, " AND %s = '%s'", |
| 5854 |
schema_query->refname, e_ref_object); |
| 5855 |
if (schema_query->refnamespace && completion_ref_schema) |
| 5856 |
appendPQExpBuffer(&query_buffer, |
| 5857 |
" AND %s = nr.oid AND nr.nspname = '%s'", |
| 5858 |
schema_query->refnamespace, |
| 5859 |
e_ref_schema); |
| 5860 |
else if (schema_query->refviscondition) |
| 5861 |
appendPQExpBuffer(&query_buffer, |
| 5862 |
" AND %s", |
| 5863 |
schema_query->refviscondition); |
| 5864 |
} |
| 5865 |
} |
| 5866 |
} |
| 5867 |
else |
| 5868 |
{ |
| 5869 |
Assert(simple_query); |
| 5870 |
/* simple_query is an sprintf-style format string */ |
| 5871 |
appendPQExpBuffer(&query_buffer, simple_query, |
| 5872 |
e_object_like, |
| 5873 |
e_ref_object, e_ref_schema); |
| 5874 |
} |
| 5875 |
|
| 5876 |
/* Limit the number of records in the result */ |
| 5877 |
appendPQExpBuffer(&query_buffer, "\nLIMIT %d", |
| 5878 |
completion_max_records); |
| 5879 |
|
| 5880 |
/* Finally, we can issue the query */ |
| 5881 |
result = exec_query(query_buffer.data); |
| 5882 |
|
| 5883 |
/* Clean up */ |
| 5884 |
termPQExpBuffer(&query_buffer); |
| 5885 |
free(schemaname); |
| 5886 |
free(objectname); |
| 5887 |
free(e_object_like); |
| 5888 |
free(e_schemaname); |
| 5889 |
free(e_ref_object); |
| 5890 |
free(e_ref_schema); |
| 5891 |
} |
| 5892 |
|
| 5893 |
/* Return the next result, if any, but not if the query failed */ |
| 5894 |
if (result && PQresultStatus(result) == PGRES_TUPLES_OK) |
| 5895 |
{ |
| 5896 |
int nskip; |
| 5897 |
|
| 5898 |
while (list_index < PQntuples(result)) |
| 5899 |
{ |
| 5900 |
const char *item = NULL; |
| 5901 |
const char *nsp = NULL; |
| 5902 |
|
| 5903 |
if (!PQgetisnull(result, list_index, 0)) |
| 5904 |
item = PQgetvalue(result, list_index, 0); |
| 5905 |
if (PQnfields(result) > 1 && |
| 5906 |
!PQgetisnull(result, list_index, 1)) |
| 5907 |
nsp = PQgetvalue(result, list_index, 1); |
| 5908 |
list_index++; |
| 5909 |
|
| 5910 |
/* In verbatim mode, we return all the items as-is */ |
| 5911 |
if (verbatim) |
| 5912 |
{ |
| 5913 |
num_query_other++; |
| 5914 |
return pg_strdup(item); |
| 5915 |
} |
| 5916 |
|
| 5917 |
/* |
| 5918 |
* In normal mode, a name requiring quoting will be returned only |
| 5919 |
* if the input was empty or quoted. Otherwise the user might see |
| 5920 |
* completion inserting a quote she didn't type, which is |
| 5921 |
* surprising. This restriction also dodges some odd behaviors of |
| 5922 |
* some versions of readline/libedit. |
| 5923 |
*/ |
| 5924 |
if (non_empty_object) |
| 5925 |
{ |
| 5926 |
if (item && !objectquoted && identifier_needs_quotes(item)) |
| 5927 |
continue; |
| 5928 |
if (nsp && !schemaquoted && identifier_needs_quotes(nsp)) |
| 5929 |
continue; |
| 5930 |
} |
| 5931 |
|
| 5932 |
/* Count schema-only results for hack below */ |
| 5933 |
if (item == NULL && nsp != NULL) |
| 5934 |
num_schema_only++; |
| 5935 |
else |
| 5936 |
num_query_other++; |
| 5937 |
|
| 5938 |
return requote_identifier(nsp, item, schemaquoted, objectquoted); |
| 5939 |
} |
| 5940 |
|
| 5941 |
/* |
| 5942 |
* When the query result is exhausted, check for hard-wired keywords. |
| 5943 |
* These will only be returned if they match the input-so-far, |
| 5944 |
* ignoring case. |
| 5945 |
*/ |
| 5946 |
nskip = list_index - PQntuples(result); |
| 5947 |
if (schema_query && schema_query->keywords) |
| 5948 |
{ |
| 5949 |
const char *const *itemp = schema_query->keywords; |
| 5950 |
|
| 5951 |
while (*itemp) |
| 5952 |
{ |
| 5953 |
const char *item = *itemp++; |
| 5954 |
|
| 5955 |
if (nskip-- > 0) |
| 5956 |
continue; |
| 5957 |
list_index++; |
| 5958 |
if (pg_strncasecmp(text, item, strlen(text)) == 0) |
| 5959 |
{ |
| 5960 |
num_keywords++; |
| 5961 |
return pg_strdup_keyword_case(item, text); |
| 5962 |
} |
| 5963 |
} |
| 5964 |
} |
| 5965 |
if (keywords) |
| 5966 |
{ |
| 5967 |
const char *const *itemp = keywords; |
| 5968 |
|
| 5969 |
while (*itemp) |
| 5970 |
{ |
| 5971 |
const char *item = *itemp++; |
| 5972 |
|
| 5973 |
if (nskip-- > 0) |
| 5974 |
continue; |
| 5975 |
list_index++; |
| 5976 |
if (pg_strncasecmp(text, item, strlen(text)) == 0) |
| 5977 |
{ |
| 5978 |
num_keywords++; |
| 5979 |
return pg_strdup_keyword_case(item, text); |
| 5980 |
} |
| 5981 |
} |
| 5982 |
} |
| 5983 |
} |
| 5984 |
|
| 5985 |
/* |
| 5986 |
* Hack: if we returned only bare schema names, don't let Readline add a |
| 5987 |
* space afterwards. Otherwise the schema will stop being part of the |
| 5988 |
* completion subject text, which is not what we want. |
| 5989 |
*/ |
| 5990 |
if (num_schema_only > 0 && num_query_other == 0 && num_keywords == 0) |
| 5991 |
rl_completion_append_character = '\0'; |
| 5992 |
|
| 5993 |
/* No more matches, so free the result structure and return null */ |
| 5994 |
PQclear(result); |
| 5995 |
result = NULL; |
| 5996 |
return NULL; |
| 5997 |
} |
| 5998 |
|
| 5999 |
|
| 6000 |
/* |
| 6001 |
* Set up completion_ref_object and completion_ref_schema |
| 6002 |
* by parsing the given word. These variables can then be |
| 6003 |
* used in a query passed to _complete_from_query. |
| 6004 |
*/ |
| 6005 |
static void |
| 6006 |
set_completion_reference(const char *word) |
| 6007 |
{ |
| 6008 |
bool schemaquoted, |
| 6009 |
objectquoted; |
| 6010 |
|
| 6011 |
parse_identifier(word, |
| 6012 |
&completion_ref_schema, &completion_ref_object, |
| 6013 |
&schemaquoted, &objectquoted); |
| 6014 |
} |
| 6015 |
|
| 6016 |
/* |
| 6017 |
* Set up completion_ref_object when it should just be |
| 6018 |
* the given word verbatim. |
| 6019 |
*/ |
| 6020 |
static void |
| 6021 |
set_completion_reference_verbatim(const char *word) |
| 6022 |
{ |
| 6023 |
completion_ref_schema = NULL; |
| 6024 |
completion_ref_object = pg_strdup(word); |
| 6025 |
} |
| 6026 |
|
| 6027 |
|
| 6028 |
/* |
| 6029 |
* This function returns in order one of a fixed, NULL pointer terminated list |
| 6030 |
* of strings (if matching). This can be used if there are only a fixed number |
| 6031 |
* SQL words that can appear at certain spot. |
| 6032 |
*/ |
| 6033 |
static char * |
| 6034 |
complete_from_list(const char *text, int state) |
| 6035 |
{ |
| 6036 |
static int string_length, |
| 6037 |
list_index, |
| 6038 |
matches; |
| 6039 |
static bool casesensitive; |
| 6040 |
const char *item; |
| 6041 |
|
| 6042 |
/* need to have a list */ |
| 6043 |
Assert(completion_charpp != NULL); |
| 6044 |
|
| 6045 |
/* Initialization */ |
| 6046 |
if (state == 0) |
| 6047 |
{ |
| 6048 |
list_index = 0; |
| 6049 |
string_length = strlen(text); |
| 6050 |
casesensitive = completion_case_sensitive; |
| 6051 |
matches = 0; |
| 6052 |
} |
| 6053 |
|
| 6054 |
while ((item = completion_charpp[list_index++])) |
| 6055 |
{ |
| 6056 |
/* First pass is case sensitive */ |
| 6057 |
if (casesensitive && strncmp(text, item, string_length) == 0) |
| 6058 |
{ |
| 6059 |
matches++; |
| 6060 |
return pg_strdup(item); |
| 6061 |
} |
| 6062 |
|
| 6063 |
/* Second pass is case insensitive, don't bother counting matches */ |
| 6064 |
if (!casesensitive && pg_strncasecmp(text, item, string_length) == 0) |
| 6065 |
{ |
| 6066 |
if (completion_case_sensitive) |
| 6067 |
return pg_strdup(item); |
| 6068 |
else |
| 6069 |
|
| 6070 |
/* |
| 6071 |
* If case insensitive matching was requested initially, |
| 6072 |
* adjust the case according to setting. |
| 6073 |
*/ |
| 6074 |
return pg_strdup_keyword_case(item, text); |
| 6075 |
} |
| 6076 |
} |
| 6077 |
|
| 6078 |
/* |
| 6079 |
* No matches found. If we're not case insensitive already, lets switch to |
| 6080 |
* being case insensitive and try again |
| 6081 |
*/ |
| 6082 |
if (casesensitive && matches == 0) |
| 6083 |
{ |
| 6084 |
casesensitive = false; |
| 6085 |
list_index = 0; |
| 6086 |
state++; |
| 6087 |
return complete_from_list(text, state); |
| 6088 |
} |
| 6089 |
|
| 6090 |
/* If no more matches, return null. */ |
| 6091 |
return NULL; |
| 6092 |
} |
| 6093 |
|
| 6094 |
|
| 6095 |
/* |
| 6096 |
* This function returns one fixed string the first time even if it doesn't |
| 6097 |
* match what's there, and nothing the second time. The string |
| 6098 |
* to be used must be in completion_charp. |
| 6099 |
* |
| 6100 |
* If the given string is "", this has the effect of preventing readline |
| 6101 |
* from doing any completion. (Without this, readline tries to do filename |
| 6102 |
* completion which is seldom the right thing.) |
| 6103 |
* |
| 6104 |
* If the given string is not empty, readline will replace whatever the |
| 6105 |
* user typed with that string. This behavior might be useful if it's |
| 6106 |
* completely certain that we know what must appear at a certain spot, |
| 6107 |
* so that it's okay to overwrite misspellings. In practice, given the |
| 6108 |
* relatively lame parsing technology used in this file, the level of |
| 6109 |
* certainty is seldom that high, so that you probably don't want to |
| 6110 |
* use this. Use complete_from_list with a one-element list instead; |
| 6111 |
* that won't try to auto-correct "misspellings". |
| 6112 |
*/ |
| 6113 |
static char * |
| 6114 |
complete_from_const(const char *text, int state) |
| 6115 |
{ |
| 6116 |
Assert(completion_charp != NULL); |
| 6117 |
if (state == 0) |
| 6118 |
{ |
| 6119 |
if (completion_case_sensitive) |
| 6120 |
return pg_strdup(completion_charp); |
| 6121 |
else |
| 6122 |
|
| 6123 |
/* |
| 6124 |
* If case insensitive matching was requested initially, adjust |
| 6125 |
* the case according to setting. |
| 6126 |
*/ |
| 6127 |
return pg_strdup_keyword_case(completion_charp, text); |
| 6128 |
} |
| 6129 |
else |
| 6130 |
return NULL; |
| 6131 |
} |
| 6132 |
|
| 6133 |
|
| 6134 |
/* |
| 6135 |
* This function appends the variable name with prefix and suffix to |
| 6136 |
* the variable names array. |
| 6137 |
*/ |
| 6138 |
static void |
| 6139 |
append_variable_names(char ***varnames, int *nvars, |
| 6140 |
int *maxvars, const char *varname, |
| 6141 |
const char *prefix, const char *suffix) |
| 6142 |
{ |
| 6143 |
if (*nvars >= *maxvars) |
| 6144 |
{ |
| 6145 |
*maxvars *= 2; |
| 6146 |
*varnames = (char **) pg_realloc(*varnames, |
| 6147 |
((*maxvars) + 1) * sizeof(char *)); |
| 6148 |
} |
| 6149 |
|
| 6150 |
(*varnames)[(*nvars)++] = psprintf("%s%s%s", prefix, varname, suffix); |
| 6151 |
} |
| 6152 |
|
| 6153 |
|
| 6154 |
/* |
| 6155 |
* This function supports completion with the name of a psql variable. |
| 6156 |
* The variable names can be prefixed and suffixed with additional text |
| 6157 |
* to support quoting usages. If need_value is true, only variables |
| 6158 |
* that are currently set are included; otherwise, special variables |
| 6159 |
* (those that have hooks) are included even if currently unset. |
| 6160 |
*/ |
| 6161 |
static char ** |
| 6162 |
complete_from_variables(const char *text, const char *prefix, const char *suffix, |
| 6163 |
bool need_value) |
| 6164 |
{ |
| 6165 |
char **matches; |
| 6166 |
char **varnames; |
| 6167 |
int nvars = 0; |
| 6168 |
int maxvars = 100; |
| 6169 |
int i; |
| 6170 |
struct _variable *ptr; |
| 6171 |
|
| 6172 |
varnames = (char **) pg_malloc((maxvars + 1) * sizeof(char *)); |
| 6173 |
|
| 6174 |
for (ptr = pset.vars->next; ptr; ptr = ptr->next) |
| 6175 |
{ |
| 6176 |
if (need_value && !(ptr->value)) |
| 6177 |
continue; |
| 6178 |
append_variable_names(&varnames, &nvars, &maxvars, ptr->name, |
| 6179 |
prefix, suffix); |
| 6180 |
} |
| 6181 |
|
| 6182 |
varnames[nvars] = NULL; |
| 6183 |
COMPLETE_WITH_LIST_CS((const char *const *) varnames); |
| 6184 |
|
| 6185 |
for (i = 0; i < nvars; i++) |
| 6186 |
free(varnames[i]); |
| 6187 |
free(varnames); |
| 6188 |
|
| 6189 |
return matches; |
| 6190 |
} |
| 6191 |
|
| 6192 |
|
| 6193 |
/* |
| 6194 |
* This function wraps rl_filename_completion_function() to strip quotes from |
| 6195 |
* the input before searching for matches and to quote any matches for which |
| 6196 |
* the consuming command will require it. |
| 6197 |
* |
| 6198 |
* Caller must set completion_charp to a zero- or one-character string |
| 6199 |
* containing the escape character. This is necessary since \copy has no |
| 6200 |
* escape character, but every other backslash command recognizes "\" as an |
| 6201 |
* escape character. |
| 6202 |
* |
| 6203 |
* Caller must also set completion_force_quote to indicate whether to force |
| 6204 |
* quotes around the result. (The SQL COPY command requires that.) |
| 6205 |
*/ |
| 6206 |
static char * |
| 6207 |
complete_from_files(const char *text, int state) |
| 6208 |
{ |
| 6209 |
#ifdef USE_FILENAME_QUOTING_FUNCTIONS |
| 6210 |
|
| 6211 |
/* |
| 6212 |
* If we're using a version of Readline that supports filename quoting |
| 6213 |
* hooks, rely on those, and invoke rl_filename_completion_function() |
| 6214 |
* without messing with its arguments. Readline does stuff internally |
| 6215 |
* that does not work well at all if we try to handle dequoting here. |
| 6216 |
* Instead, Readline will call quote_file_name() and dequote_file_name() |
| 6217 |
* (see below) at appropriate times. |
| 6218 |
* |
| 6219 |
* ... or at least, mostly it will. There are some paths involving |
| 6220 |
* unmatched file names in which Readline never calls quote_file_name(), |
| 6221 |
* and if left to its own devices it will incorrectly append a quote |
| 6222 |
* anyway. Set rl_completion_suppress_quote to prevent that. If we do |
| 6223 |
* get to quote_file_name(), we'll clear this again. (Yes, this seems |
| 6224 |
* like it's working around Readline bugs.) |
| 6225 |
*/ |
| 6226 |
#ifdef HAVE_RL_COMPLETION_SUPPRESS_QUOTE |
| 6227 |
rl_completion_suppress_quote = 1; |
| 6228 |
#endif |
| 6229 |
|
| 6230 |
/* If user typed a quote, force quoting (never remove user's quote) */ |
| 6231 |
if (*text == '\'') |
| 6232 |
completion_force_quote = true; |
| 6233 |
|
| 6234 |
return rl_filename_completion_function(text, state); |
| 6235 |
#else |
| 6236 |
|
| 6237 |
/* |
| 6238 |
* Otherwise, we have to do the best we can. |
| 6239 |
*/ |
| 6240 |
static const char *unquoted_text; |
| 6241 |
char *unquoted_match; |
| 6242 |
char *ret = NULL; |
| 6243 |
|
| 6244 |
/* If user typed a quote, force quoting (never remove user's quote) */ |
| 6245 |
if (*text == '\'') |
| 6246 |
completion_force_quote = true; |
| 6247 |
|
| 6248 |
if (state == 0) |
| 6249 |
{ |
| 6250 |
/* Initialization: stash the unquoted input. */ |
| 6251 |
unquoted_text = strtokx(text, "", NULL, "'", *completion_charp, |
| 6252 |
false, true, pset.encoding); |
| 6253 |
/* expect a NULL return for the empty string only */ |
| 6254 |
if (!unquoted_text) |
| 6255 |
{ |
| 6256 |
Assert(*text == '\0'); |
| 6257 |
unquoted_text = text; |
| 6258 |
} |
| 6259 |
} |
| 6260 |
|
| 6261 |
unquoted_match = rl_filename_completion_function(unquoted_text, state); |
| 6262 |
if (unquoted_match) |
| 6263 |
{ |
| 6264 |
struct stat statbuf; |
| 6265 |
bool is_dir = (stat(unquoted_match, &statbuf) == 0 && |
| 6266 |
S_ISDIR(statbuf.st_mode) != 0); |
| 6267 |
|
| 6268 |
/* Re-quote the result, if needed. */ |
| 6269 |
ret = quote_if_needed(unquoted_match, " \t\r\n\"`", |
| 6270 |
'\'', *completion_charp, |
| 6271 |
completion_force_quote, |
| 6272 |
pset.encoding); |
| 6273 |
if (ret) |
| 6274 |
free(unquoted_match); |
| 6275 |
else |
| 6276 |
ret = unquoted_match; |
| 6277 |
|
| 6278 |
/* |
| 6279 |
* If it's a directory, replace trailing quote with a slash; this is |
| 6280 |
* usually more convenient. (If we didn't quote, leave this to |
| 6281 |
* libedit.) |
| 6282 |
*/ |
| 6283 |
if (*ret == '\'' && is_dir) |
| 6284 |
{ |
| 6285 |
char *retend = ret + strlen(ret) - 1; |
| 6286 |
|
| 6287 |
Assert(*retend == '\''); |
| 6288 |
*retend = '/'; |
| 6289 |
/* Prevent libedit from adding a space, too */ |
| 6290 |
rl_completion_append_character = '\0'; |
| 6291 |
} |
| 6292 |
} |
| 6293 |
|
| 6294 |
return ret; |
| 6295 |
#endif /* USE_FILENAME_QUOTING_FUNCTIONS */ |
| 6296 |
} |
| 6297 |
|
| 6298 |
|
| 6299 |
/* HELPER FUNCTIONS */ |
| 6300 |
|
| 6301 |
|
| 6302 |
/* |
| 6303 |
* Make a pg_strdup copy of s and convert the case according to |
| 6304 |
* COMP_KEYWORD_CASE setting, using ref as the text that was already entered. |
| 6305 |
*/ |
| 6306 |
static char * |
| 6307 |
pg_strdup_keyword_case(const char *s, const char *ref) |
| 6308 |
{ |
| 6309 |
char *ret, |
| 6310 |
*p; |
| 6311 |
unsigned char first = ref[0]; |
| 6312 |
|
| 6313 |
ret = pg_strdup(s); |
| 6314 |
|
| 6315 |
if (pset.comp_case == PSQL_COMP_CASE_LOWER || |
| 6316 |
((pset.comp_case == PSQL_COMP_CASE_PRESERVE_LOWER || |
| 6317 |
pset.comp_case == PSQL_COMP_CASE_PRESERVE_UPPER) && islower(first)) || |
| 6318 |
(pset.comp_case == PSQL_COMP_CASE_PRESERVE_LOWER && !isalpha(first))) |
| 6319 |
{ |
| 6320 |
for (p = ret; *p; p++) |
| 6321 |
*p = pg_tolower((unsigned char) *p); |
| 6322 |
} |
| 6323 |
else |
| 6324 |
{ |
| 6325 |
for (p = ret; *p; p++) |
| 6326 |
*p = pg_toupper((unsigned char) *p); |
| 6327 |
} |
| 6328 |
|
| 6329 |
return ret; |
| 6330 |
} |
| 6331 |
|
| 6332 |
|
| 6333 |
/* |
| 6334 |
* escape_string - Escape argument for use as string literal. |
| 6335 |
* |
| 6336 |
* The returned value has to be freed. |
| 6337 |
*/ |
| 6338 |
static char * |
| 6339 |
escape_string(const char *text) |
| 6340 |
{ |
| 6341 |
size_t text_length; |
| 6342 |
char *result; |
| 6343 |
|
| 6344 |
text_length = strlen(text); |
| 6345 |
|
| 6346 |
result = pg_malloc(text_length * 2 + 1); |
| 6347 |
PQescapeStringConn(pset.db, result, text, text_length, NULL); |
| 6348 |
|
| 6349 |
return result; |
| 6350 |
} |
| 6351 |
|
| 6352 |
|
| 6353 |
/* |
| 6354 |
* make_like_pattern - Convert argument to a LIKE prefix pattern. |
| 6355 |
* |
| 6356 |
* We escape _ and % in the given text by backslashing, append a % to |
| 6357 |
* represent "any subsequent characters", and then pass the string through |
| 6358 |
* escape_string() so it's ready to insert in a query. The result needs |
| 6359 |
* to be freed. |
| 6360 |
*/ |
| 6361 |
static char * |
| 6362 |
make_like_pattern(const char *word) |
| 6363 |
{ |
| 6364 |
char *result; |
| 6365 |
char *buffer = pg_malloc(strlen(word) * 2 + 2); |
| 6366 |
char *bptr = buffer; |
| 6367 |
|
| 6368 |
while (*word) |
| 6369 |
{ |
| 6370 |
if (*word == '_' || *word == '%') |
| 6371 |
*bptr++ = '\\'; |
| 6372 |
if (IS_HIGHBIT_SET(*word)) |
| 6373 |
{ |
| 6374 |
/* |
| 6375 |
* Transfer multibyte characters without further processing, to |
| 6376 |
* avoid getting confused in unsafe client encodings. |
| 6377 |
*/ |
| 6378 |
int chlen = PQmblenBounded(word, pset.encoding); |
| 6379 |
|
| 6380 |
while (chlen-- > 0) |
| 6381 |
*bptr++ = *word++; |
| 6382 |
} |
| 6383 |
else |
| 6384 |
*bptr++ = *word++; |
| 6385 |
} |
| 6386 |
*bptr++ = '%'; |
| 6387 |
*bptr = '\0'; |
| 6388 |
|
| 6389 |
result = escape_string(buffer); |
| 6390 |
free(buffer); |
| 6391 |
return result; |
| 6392 |
} |
| 6393 |
|
| 6394 |
|
| 6395 |
/* |
| 6396 |
* parse_identifier - Parse a possibly-schema-qualified SQL identifier. |
| 6397 |
* |
| 6398 |
* This involves splitting off the schema name if present, de-quoting, |
| 6399 |
* and downcasing any unquoted text. We are a bit laxer than the backend |
| 6400 |
* in that we allow just portions of a name to be quoted --- that's because |
| 6401 |
* psql metacommands have traditionally behaved that way. |
| 6402 |
* |
| 6403 |
* Outputs are a malloc'd schema name (NULL if none), malloc'd object name, |
| 6404 |
* and booleans telling whether any part of the schema and object name was |
| 6405 |
* double-quoted. |
| 6406 |
*/ |
| 6407 |
static void |
| 6408 |
parse_identifier(const char *ident, |
| 6409 |
char **schemaname, char **objectname, |
| 6410 |
bool *schemaquoted, bool *objectquoted) |
| 6411 |
{ |
| 6412 |
size_t buflen = strlen(ident) + 1; |
| 6413 |
bool enc_is_single_byte = (pg_encoding_max_length(pset.encoding) == 1); |
| 6414 |
char *sname; |
| 6415 |
char *oname; |
| 6416 |
char *optr; |
| 6417 |
bool inquotes; |
| 6418 |
|
| 6419 |
/* Initialize, making a certainly-large-enough output buffer */ |
| 6420 |
sname = NULL; |
| 6421 |
oname = pg_malloc(buflen); |
| 6422 |
*schemaquoted = *objectquoted = false; |
| 6423 |
/* Scan */ |
| 6424 |
optr = oname; |
| 6425 |
inquotes = false; |
| 6426 |
while (*ident) |
| 6427 |
{ |
| 6428 |
unsigned char ch = (unsigned char) *ident++; |
| 6429 |
|
| 6430 |
if (ch == '"') |
| 6431 |
{ |
| 6432 |
if (inquotes && *ident == '"') |
| 6433 |
{ |
| 6434 |
/* two quote marks within a quoted identifier = emit quote */ |
| 6435 |
*optr++ = '"'; |
| 6436 |
ident++; |
| 6437 |
} |
| 6438 |
else |
| 6439 |
{ |
| 6440 |
inquotes = !inquotes; |
| 6441 |
*objectquoted = true; |
| 6442 |
} |
| 6443 |
} |
| 6444 |
else if (ch == '.' && !inquotes) |
| 6445 |
{ |
| 6446 |
/* Found a schema name, transfer it to sname / *schemaquoted */ |
| 6447 |
*optr = '\0'; |
| 6448 |
free(sname); /* drop any catalog name */ |
| 6449 |
sname = oname; |
| 6450 |
oname = pg_malloc(buflen); |
| 6451 |
optr = oname; |
| 6452 |
*schemaquoted = *objectquoted; |
| 6453 |
*objectquoted = false; |
| 6454 |
} |
| 6455 |
else if (!enc_is_single_byte && IS_HIGHBIT_SET(ch)) |
| 6456 |
{ |
| 6457 |
/* |
| 6458 |
* Transfer multibyte characters without further processing. They |
| 6459 |
* wouldn't be affected by our downcasing rule anyway, and this |
| 6460 |
* avoids possibly doing the wrong thing in unsafe client |
| 6461 |
* encodings. |
| 6462 |
*/ |
| 6463 |
int chlen = PQmblenBounded(ident - 1, pset.encoding); |
| 6464 |
|
| 6465 |
*optr++ = (char) ch; |
| 6466 |
while (--chlen > 0) |
| 6467 |
*optr++ = *ident++; |
| 6468 |
} |
| 6469 |
else |
| 6470 |
{ |
| 6471 |
if (!inquotes) |
| 6472 |
{ |
| 6473 |
/* |
| 6474 |
* This downcasing transformation should match the backend's |
| 6475 |
* downcase_identifier() as best we can. We do not know the |
| 6476 |
* backend's locale, though, so it's necessarily approximate. |
| 6477 |
* We assume that psql is operating in the same locale and |
| 6478 |
* encoding as the backend. |
| 6479 |
*/ |
| 6480 |
if (ch >= 'A' && ch <= 'Z') |
| 6481 |
ch += 'a' - 'A'; |
| 6482 |
else if (enc_is_single_byte && IS_HIGHBIT_SET(ch) && isupper(ch)) |
| 6483 |
ch = tolower(ch); |
| 6484 |
} |
| 6485 |
*optr++ = (char) ch; |
| 6486 |
} |
| 6487 |
} |
| 6488 |
|
| 6489 |
*optr = '\0'; |
| 6490 |
*schemaname = sname; |
| 6491 |
*objectname = oname; |
| 6492 |
} |
| 6493 |
|
| 6494 |
|
| 6495 |
/* |
| 6496 |
* requote_identifier - Reconstruct a possibly-schema-qualified SQL identifier. |
| 6497 |
* |
| 6498 |
* Build a malloc'd string containing the identifier, with quoting applied |
| 6499 |
* as necessary. This is more or less the inverse of parse_identifier; |
| 6500 |
* in particular, if an input component was quoted, we'll quote the output |
| 6501 |
* even when that isn't strictly required. |
| 6502 |
* |
| 6503 |
* Unlike parse_identifier, we handle the case where a schema and no |
| 6504 |
* object name is provided, producing just "schema.". |
| 6505 |
*/ |
| 6506 |
static char * |
| 6507 |
requote_identifier(const char *schemaname, const char *objectname, |
| 6508 |
bool quote_schema, bool quote_object) |
| 6509 |
{ |
| 6510 |
char *result; |
| 6511 |
size_t buflen = 1; /* count the trailing \0 */ |
| 6512 |
char *ptr; |
| 6513 |
|
| 6514 |
/* |
| 6515 |
* We could use PQescapeIdentifier for some of this, but not all, and it |
| 6516 |
* adds more notational cruft than it seems worth. |
| 6517 |
*/ |
| 6518 |
if (schemaname) |
| 6519 |
{ |
| 6520 |
buflen += strlen(schemaname) + 1; /* +1 for the dot */ |
| 6521 |
if (!quote_schema) |
| 6522 |
quote_schema = identifier_needs_quotes(schemaname); |
| 6523 |
if (quote_schema) |
| 6524 |
{ |
| 6525 |
buflen += 2; /* account for quote marks */ |
| 6526 |
for (const char *p = schemaname; *p; p++) |
| 6527 |
{ |
| 6528 |
if (*p == '"') |
| 6529 |
buflen++; |
| 6530 |
} |
| 6531 |
} |
| 6532 |
} |
| 6533 |
if (objectname) |
| 6534 |
{ |
| 6535 |
buflen += strlen(objectname); |
| 6536 |
if (!quote_object) |
| 6537 |
quote_object = identifier_needs_quotes(objectname); |
| 6538 |
if (quote_object) |
| 6539 |
{ |
| 6540 |
buflen += 2; /* account for quote marks */ |
| 6541 |
for (const char *p = objectname; *p; p++) |
| 6542 |
{ |
| 6543 |
if (*p == '"') |
| 6544 |
buflen++; |
| 6545 |
} |
| 6546 |
} |
| 6547 |
} |
| 6548 |
result = pg_malloc(buflen); |
| 6549 |
ptr = result; |
| 6550 |
if (schemaname) |
| 6551 |
{ |
| 6552 |
if (quote_schema) |
| 6553 |
*ptr++ = '"'; |
| 6554 |
for (const char *p = schemaname; *p; p++) |
| 6555 |
{ |
| 6556 |
*ptr++ = *p; |
| 6557 |
if (*p == '"') |
| 6558 |
*ptr++ = '"'; |
| 6559 |
} |
| 6560 |
if (quote_schema) |
| 6561 |
*ptr++ = '"'; |
| 6562 |
*ptr++ = '.'; |
| 6563 |
} |
| 6564 |
if (objectname) |
| 6565 |
{ |
| 6566 |
if (quote_object) |
| 6567 |
*ptr++ = '"'; |
| 6568 |
for (const char *p = objectname; *p; p++) |
| 6569 |
{ |
| 6570 |
*ptr++ = *p; |
| 6571 |
if (*p == '"') |
| 6572 |
*ptr++ = '"'; |
| 6573 |
} |
| 6574 |
if (quote_object) |
| 6575 |
*ptr++ = '"'; |
| 6576 |
} |
| 6577 |
*ptr = '\0'; |
| 6578 |
return result; |
| 6579 |
} |
| 6580 |
|
| 6581 |
|
| 6582 |
/* |
| 6583 |
* Detect whether an identifier must be double-quoted. |
| 6584 |
* |
| 6585 |
* Note we'll quote anything that's not ASCII; the backend's quote_ident() |
| 6586 |
* does the same. Perhaps this could be relaxed in future. |
| 6587 |
*/ |
| 6588 |
static bool |
| 6589 |
identifier_needs_quotes(const char *ident) |
| 6590 |
{ |
| 6591 |
int kwnum; |
| 6592 |
|
| 6593 |
/* Check syntax. */ |
| 6594 |
if (!((ident[0] >= 'a' && ident[0] <= 'z') || ident[0] == '_')) |
| 6595 |
return true; |
| 6596 |
if (strspn(ident, "abcdefghijklmnopqrstuvwxyz0123456789_$") != strlen(ident)) |
| 6597 |
return true; |
| 6598 |
|
| 6599 |
/* |
| 6600 |
* Check for keyword. We quote keywords except for unreserved ones. |
| 6601 |
* |
| 6602 |
* It is possible that our keyword list doesn't quite agree with the |
| 6603 |
* server's, but this should be close enough for tab-completion purposes. |
| 6604 |
* |
| 6605 |
* Note: ScanKeywordLookup() does case-insensitive comparison, but that's |
| 6606 |
* fine, since we already know we have all-lower-case. |
| 6607 |
*/ |
| 6608 |
kwnum = ScanKeywordLookup(ident, &ScanKeywords); |
| 6609 |
|
| 6610 |
if (kwnum >= 0 && ScanKeywordCategories[kwnum] != UNRESERVED_KEYWORD) |
| 6611 |
return true; |
| 6612 |
|
| 6613 |
return false; |
| 6614 |
} |
| 6615 |
|
| 6616 |
|
| 6617 |
/* |
| 6618 |
* Execute a query, returning NULL if there was any error. |
| 6619 |
* This should be the preferred way of talking to the database in this file. |
| 6620 |
*/ |
| 6621 |
static PGresult * |
| 6622 |
exec_query(const char *query) |
| 6623 |
{ |
| 6624 |
PGresult *result; |
| 6625 |
|
| 6626 |
if (query == NULL || !pset.db || PQstatus(pset.db) != CONNECTION_OK) |
| 6627 |
return NULL; |
| 6628 |
|
| 6629 |
result = PQexec(pset.db, query); |
| 6630 |
|
| 6631 |
if (PQresultStatus(result) != PGRES_TUPLES_OK) |
| 6632 |
{ |
| 6633 |
/* |
| 6634 |
* Printing an error while the user is typing would be quite annoying, |
| 6635 |
* so we don't. This does complicate debugging of this code; but you |
| 6636 |
* can look in the server log instead. |
| 6637 |
*/ |
| 6638 |
#ifdef NOT_USED |
| 6639 |
pg_log_error("tab completion query failed: %s\nQuery was:\n%s", |
| 6640 |
PQerrorMessage(pset.db), query); |
| 6641 |
#endif |
| 6642 |
PQclear(result); |
| 6643 |
result = NULL; |
| 6644 |
} |
| 6645 |
|
| 6646 |
return result; |
| 6647 |
} |
| 6648 |
|
| 6649 |
|
| 6650 |
/* |
| 6651 |
* Parse all the word(s) before point. |
| 6652 |
* |
| 6653 |
* Returns a malloc'd array of character pointers that point into the malloc'd |
| 6654 |
* data array returned to *buffer; caller must free() both of these when done. |
| 6655 |
* *nwords receives the number of words found, ie, the valid length of the |
| 6656 |
* return array. |
| 6657 |
* |
| 6658 |
* Words are returned right to left, that is, previous_words[0] gets the last |
| 6659 |
* word before point, previous_words[1] the next-to-last, etc. |
| 6660 |
*/ |
| 6661 |
static char ** |
| 6662 |
get_previous_words(int point, char **buffer, int *nwords) |
| 6663 |
{ |
| 6664 |
char **previous_words; |
| 6665 |
char *buf; |
| 6666 |
char *outptr; |
| 6667 |
int words_found = 0; |
| 6668 |
int i; |
| 6669 |
|
| 6670 |
/* |
| 6671 |
* If we have anything in tab_completion_query_buf, paste it together with |
| 6672 |
* rl_line_buffer to construct the full query. Otherwise we can just use |
| 6673 |
* rl_line_buffer as the input string. |
| 6674 |
*/ |
| 6675 |
if (tab_completion_query_buf && tab_completion_query_buf->len > 0) |
| 6676 |
{ |
| 6677 |
i = tab_completion_query_buf->len; |
| 6678 |
buf = pg_malloc(point + i + 2); |
| 6679 |
memcpy(buf, tab_completion_query_buf->data, i); |
| 6680 |
buf[i++] = '\n'; |
| 6681 |
memcpy(buf + i, rl_line_buffer, point); |
| 6682 |
i += point; |
| 6683 |
buf[i] = '\0'; |
| 6684 |
/* Readjust point to reference appropriate offset in buf */ |
| 6685 |
point = i; |
| 6686 |
} |
| 6687 |
else |
| 6688 |
buf = rl_line_buffer; |
| 6689 |
|
| 6690 |
/* |
| 6691 |
* Allocate an array of string pointers and a buffer to hold the strings |
| 6692 |
* themselves. The worst case is that the line contains only |
| 6693 |
* non-whitespace WORD_BREAKS characters, making each one a separate word. |
| 6694 |
* This is usually much more space than we need, but it's cheaper than |
| 6695 |
* doing a separate malloc() for each word. |
| 6696 |
*/ |
| 6697 |
previous_words = (char **) pg_malloc(point * sizeof(char *)); |
| 6698 |
*buffer = outptr = (char *) pg_malloc(point * 2); |
| 6699 |
|
| 6700 |
/* |
| 6701 |
* First we look for a non-word char before the current point. (This is |
| 6702 |
* probably useless, if readline is on the same page as we are about what |
| 6703 |
* is a word, but if so it's cheap.) |
| 6704 |
*/ |
| 6705 |
for (i = point - 1; i >= 0; i--) |
| 6706 |
{ |
| 6707 |
if (strchr(WORD_BREAKS, buf[i])) |
| 6708 |
break; |
| 6709 |
} |
| 6710 |
point = i; |
| 6711 |
|
| 6712 |
/* |
| 6713 |
* Now parse words, working backwards, until we hit start of line. The |
| 6714 |
* backwards scan has some interesting but intentional properties |
| 6715 |
* concerning parenthesis handling. |
| 6716 |
*/ |
| 6717 |
while (point >= 0) |
| 6718 |
{ |
| 6719 |
int start, |
| 6720 |
end; |
| 6721 |
bool inquotes = false; |
| 6722 |
int parentheses = 0; |
| 6723 |
|
| 6724 |
/* now find the first non-space which then constitutes the end */ |
| 6725 |
end = -1; |
| 6726 |
for (i = point; i >= 0; i--) |
| 6727 |
{ |
| 6728 |
if (!isspace((unsigned char) buf[i])) |
| 6729 |
{ |
| 6730 |
end = i; |
| 6731 |
break; |
| 6732 |
} |
| 6733 |
} |
| 6734 |
/* if no end found, we're done */ |
| 6735 |
if (end < 0) |
| 6736 |
break; |
| 6737 |
|
| 6738 |
/* |
| 6739 |
* Otherwise we now look for the start. The start is either the last |
| 6740 |
* character before any word-break character going backwards from the |
| 6741 |
* end, or it's simply character 0. We also handle open quotes and |
| 6742 |
* parentheses. |
| 6743 |
*/ |
| 6744 |
for (start = end; start > 0; start--) |
| 6745 |
{ |
| 6746 |
if (buf[start] == '"') |
| 6747 |
inquotes = !inquotes; |
| 6748 |
if (!inquotes) |
| 6749 |
{ |
| 6750 |
if (buf[start] == ')') |
| 6751 |
parentheses++; |
| 6752 |
else if (buf[start] == '(') |
| 6753 |
{ |
| 6754 |
if (--parentheses <= 0) |
| 6755 |
break; |
| 6756 |
} |
| 6757 |
else if (parentheses == 0 && |
| 6758 |
strchr(WORD_BREAKS, buf[start - 1])) |
| 6759 |
break; |
| 6760 |
} |
| 6761 |
} |
| 6762 |
|
| 6763 |
/* Return the word located at start to end inclusive */ |
| 6764 |
previous_words[words_found++] = outptr; |
| 6765 |
i = end - start + 1; |
| 6766 |
memcpy(outptr, &buf[start], i); |
| 6767 |
outptr += i; |
| 6768 |
*outptr++ = '\0'; |
| 6769 |
|
| 6770 |
/* Continue searching */ |
| 6771 |
point = start - 1; |
| 6772 |
} |
| 6773 |
|
| 6774 |
/* Release parsing input workspace, if we made one above */ |
| 6775 |
if (buf != rl_line_buffer) |
| 6776 |
free(buf); |
| 6777 |
|
| 6778 |
*nwords = words_found; |
| 6779 |
return previous_words; |
| 6780 |
} |
| 6781 |
|
| 6782 |
/* |
| 6783 |
* Look up the type for the GUC variable with the passed name. |
| 6784 |
* |
| 6785 |
* Returns NULL if the variable is unknown. Otherwise the returned string, |
| 6786 |
* containing the type, has to be freed. |
| 6787 |
*/ |
| 6788 |
static char * |
| 6789 |
get_guctype(const char *varname) |
| 6790 |
{ |
| 6791 |
PQExpBufferData query_buffer; |
| 6792 |
char *e_varname; |
| 6793 |
PGresult *result; |
| 6794 |
char *guctype = NULL; |
| 6795 |
|
| 6796 |
e_varname = escape_string(varname); |
| 6797 |
|
| 6798 |
initPQExpBuffer(&query_buffer); |
| 6799 |
appendPQExpBuffer(&query_buffer, |
| 6800 |
"SELECT vartype FROM pg_catalog.pg_settings " |
| 6801 |
"WHERE pg_catalog.lower(name) = pg_catalog.lower('%s')", |
| 6802 |
e_varname); |
| 6803 |
|
| 6804 |
result = exec_query(query_buffer.data); |
| 6805 |
termPQExpBuffer(&query_buffer); |
| 6806 |
free(e_varname); |
| 6807 |
|
| 6808 |
if (PQresultStatus(result) == PGRES_TUPLES_OK && PQntuples(result) > 0) |
| 6809 |
guctype = pg_strdup(PQgetvalue(result, 0, 0)); |
| 6810 |
|
| 6811 |
PQclear(result); |
| 6812 |
|
| 6813 |
return guctype; |
| 6814 |
} |
| 6815 |
|
| 6816 |
#ifdef USE_FILENAME_QUOTING_FUNCTIONS |
| 6817 |
|
| 6818 |
/* |
| 6819 |
* Quote a filename according to SQL rules, returning a malloc'd string. |
| 6820 |
* completion_charp must point to escape character or '\0', and |
| 6821 |
* completion_force_quote must be set correctly, as per comments for |
| 6822 |
* complete_from_files(). |
| 6823 |
*/ |
| 6824 |
static char * |
| 6825 |
quote_file_name(char *fname, int match_type, char *quote_pointer) |
| 6826 |
{ |
| 6827 |
char *s; |
| 6828 |
struct stat statbuf; |
| 6829 |
|
| 6830 |
/* Quote if needed. */ |
| 6831 |
s = quote_if_needed(fname, " \t\r\n\"`", |
| 6832 |
'\'', *completion_charp, |
| 6833 |
completion_force_quote, |
| 6834 |
pset.encoding); |
| 6835 |
if (!s) |
| 6836 |
s = pg_strdup(fname); |
| 6837 |
|
| 6838 |
/* |
| 6839 |
* However, some of the time we have to strip the trailing quote from what |
| 6840 |
* we send back. Never strip the trailing quote if the user already typed |
| 6841 |
* one; otherwise, suppress the trailing quote if we have multiple/no |
| 6842 |
* matches (because we don't want to add a quote if the input is seemingly |
| 6843 |
* unfinished), or if the input was already quoted (because Readline will |
| 6844 |
* do arguably-buggy things otherwise), or if the file does not exist, or |
| 6845 |
* if it's a directory. |
| 6846 |
*/ |
| 6847 |
if (*s == '\'' && |
| 6848 |
completion_last_char != '\'' && |
| 6849 |
(match_type != SINGLE_MATCH || |
| 6850 |
(quote_pointer && *quote_pointer == '\'') || |
| 6851 |
stat(fname, &statbuf) != 0 || |
| 6852 |
S_ISDIR(statbuf.st_mode))) |
| 6853 |
{ |
| 6854 |
char *send = s + strlen(s) - 1; |
| 6855 |
|
| 6856 |
Assert(*send == '\''); |
| 6857 |
*send = '\0'; |
| 6858 |
} |
| 6859 |
|
| 6860 |
/* |
| 6861 |
* And now we can let Readline do its thing with possibly adding a quote |
| 6862 |
* on its own accord. (This covers some additional cases beyond those |
| 6863 |
* dealt with above.) |
| 6864 |
*/ |
| 6865 |
#ifdef HAVE_RL_COMPLETION_SUPPRESS_QUOTE |
| 6866 |
rl_completion_suppress_quote = 0; |
| 6867 |
#endif |
| 6868 |
|
| 6869 |
/* |
| 6870 |
* If user typed a leading quote character other than single quote (i.e., |
| 6871 |
* double quote), zap it, so that we replace it with the correct single |
| 6872 |
* quote. |
| 6873 |
*/ |
| 6874 |
if (quote_pointer && *quote_pointer != '\'') |
| 6875 |
*quote_pointer = '\0'; |
| 6876 |
|
| 6877 |
return s; |
| 6878 |
} |
| 6879 |
|
| 6880 |
/* |
| 6881 |
* Dequote a filename, if it's quoted. |
| 6882 |
* completion_charp must point to escape character or '\0', as per |
| 6883 |
* comments for complete_from_files(). |
| 6884 |
*/ |
| 6885 |
static char * |
| 6886 |
dequote_file_name(char *fname, int quote_char) |
| 6887 |
{ |
| 6888 |
char *unquoted_fname; |
| 6889 |
|
| 6890 |
/* |
| 6891 |
* If quote_char is set, it's not included in "fname". We have to add it |
| 6892 |
* or strtokx will not interpret the string correctly (notably, it won't |
| 6893 |
* recognize escapes). |
| 6894 |
*/ |
| 6895 |
if (quote_char == '\'') |
| 6896 |
{ |
| 6897 |
char *workspace = (char *) pg_malloc(strlen(fname) + 2); |
| 6898 |
|
| 6899 |
workspace[0] = quote_char; |
| 6900 |
strcpy(workspace + 1, fname); |
| 6901 |
unquoted_fname = strtokx(workspace, "", NULL, "'", *completion_charp, |
| 6902 |
false, true, pset.encoding); |
| 6903 |
free(workspace); |
| 6904 |
} |
| 6905 |
else |
| 6906 |
unquoted_fname = strtokx(fname, "", NULL, "'", *completion_charp, |
| 6907 |
false, true, pset.encoding); |
| 6908 |
|
| 6909 |
/* expect a NULL return for the empty string only */ |
| 6910 |
if (!unquoted_fname) |
| 6911 |
{ |
| 6912 |
Assert(*fname == '\0'); |
| 6913 |
unquoted_fname = fname; |
| 6914 |
} |
| 6915 |
|
| 6916 |
/* readline expects a malloc'd result that it is to free */ |
| 6917 |
return pg_strdup(unquoted_fname); |
| 6918 |
} |
| 6919 |
|
| 6920 |
#endif /* USE_FILENAME_QUOTING_FUNCTIONS */ |
| 6921 |
|
| 6922 |
#endif /* USE_READLINE */ |