!1135 修改 \h 帮助信息;补充自动补齐的语法

Merge pull request !1135 from chenxiaobin/readline0729
This commit is contained in:
opengauss-bot
2021-08-05 07:07:08 +00:00
committed by Gitee
5 changed files with 410 additions and 42 deletions

View File

@ -10,7 +10,7 @@
</refnamediv> </refnamediv>
<refsynopsisdiv> <refsynopsisdiv>
<synopsis> <synopsis>
CREATE CLIENT MASTER KEY CREATE CLIENT MASTER KEY client_master_key_name
[WITH] ( ['KEY_STORE' , 'KEY_PATH' , 'ALGORITHM'] ); [WITH] ( ['KEY_STORE' , 'KEY_PATH' , 'ALGORITHM'] );
</synopsis> </synopsis>
</refsynopsisdiv> </refsynopsisdiv>

View File

@ -10,7 +10,7 @@
</refnamediv> </refnamediv>
<refsynopsisdiv> <refsynopsisdiv>
<synopsis> <synopsis>
CREATE COLUMN ENCRYPTION KEY CREATE COLUMN ENCRYPTION KEY column_encryption_key_name
[WITH] ( ['CLIENT_MASTER_KEY' , 'ALGORITHM'] ); [WITH] ( ['CLIENT_MASTER_KEY' , 'ALGORITHM'] );
</synopsis> </synopsis>
</refsynopsisdiv> </refsynopsisdiv>

View File

@ -0,0 +1,332 @@
<!--
doc/src/sgml/ref/create_language.sgml
PostgreSQL documentation
-->
<refentry id="SQL-CREATELANGUAGE">
<refmeta>
<refentrytitle>CREATE LANGUAGE</refentrytitle>
<manvolnum>7</manvolnum>
<refmiscinfo>SQL - Language Statements</refmiscinfo>
</refmeta>
<refnamediv>
<refname>CREATE LANGUAGE</refname>
<refpurpose>define a new procedural language</refpurpose>
</refnamediv>
<indexterm zone="sql-createlanguage">
<primary>CREATE LANGUAGE</primary>
</indexterm>
<refsynopsisdiv>
<synopsis>
CREATE [ OR REPLACE ] [ PROCEDURAL ] LANGUAGE <replaceable class="parameter">name</replaceable>;
CREATE [ OR REPLACE ] [ TRUSTED ] [ PROCEDURAL ] LANGUAGE <replaceable class="parameter">name</replaceable>
HANDLER <replaceable class="parameter">call_handler</replaceable> [ INLINE <replaceable class="parameter">inline_handler</replaceable> ] [ VALIDATOR <replaceable>valfunction</replaceable> ];
</synopsis>
</refsynopsisdiv>
<refsect1 id="sql-createlanguage-description">
<title>Description</title>
<para>
<command>CREATE LANGUAGE</command> registers a new
procedural language with a <productname>PostgreSQL</productname>
database. Subsequently, functions and trigger procedures can be
defined in this new language.
</para>
<note>
<para>
As of <productname>PostgreSQL</productname> 9.1, most procedural
languages have been made into <quote>extensions</>, and should
therefore be installed with <xref linkend="sql-createextension">
not <command>CREATE LANGUAGE</command>. Direct use of
<command>CREATE LANGUAGE</command> should now be confined to
extension installation scripts. If you have a <quote>bare</>
language in your database, perhaps as a result of an upgrade,
you can convert it to an extension using
<literal>CREATE EXTENSION <replaceable>langname</> FROM
unpackaged</literal>.
</para>
</note>
<para>
<command>CREATE LANGUAGE</command> effectively associates the
language name with handler function(s) that are responsible for executing
functions written in the language. Refer to <xref linkend="plhandler">
for more information about language handlers.
</para>
<para>
There are two forms of the <command>CREATE LANGUAGE</command> command.
In the first form, the user supplies just the name of the desired
language, and the <productname>PostgreSQL</productname> server consults
the <link linkend="catalog-pg-pltemplate"><structname>pg_pltemplate</structname></link>
system catalog to determine the correct parameters. In the second form,
the user supplies the language parameters along with the language name.
The second form can be used to create a language that is not defined in
<structname>pg_pltemplate</>, but this approach is considered obsolescent.
</para>
<para>
When the server finds an entry in the <structname>pg_pltemplate</> catalog
for the given language name, it will use the catalog data even if the
command includes language parameters. This behavior simplifies loading of
old dump files, which are likely to contain out-of-date information
about language support functions.
</para>
<para>
Ordinarily, the user must have the
<productname>PostgreSQL</productname> superuser privilege to
register a new language. However, the owner of a database can register
a new language within that database if the language is listed in
the <structname>pg_pltemplate</structname> catalog and is marked
as allowed to be created by database owners (<structfield>tmpldbacreate</>
is true). The default is that trusted languages can be created
by database owners, but this can be adjusted by superusers by modifying
the contents of <structname>pg_pltemplate</structname>.
The creator of a language becomes its owner and can later
drop it, rename it, or assign it to a new owner.
</para>
<para>
<command>CREATE OR REPLACE LANGUAGE</command> will either create a
new language, or replace an existing definition. If the language
already exists, its parameters are updated according to the values
specified or taken from <structname>pg_pltemplate</structname>,
but the language's ownership and permissions settings do not change,
and any existing functions written in the language are assumed to still
be valid. In addition to the normal privilege requirements for creating
a language, the user must be superuser or owner of the existing language.
The <literal>REPLACE</> case is mainly meant to be used to
ensure that the language exists. If the language has a
<structname>pg_pltemplate</structname> entry then <literal>REPLACE</>
will not actually change anything about an existing definition, except in
the unusual case where the <structname>pg_pltemplate</structname> entry
has been modified since the language was created.
</para>
</refsect1>
<refsect1 id="sql-createlanguage-parameters">
<title>Parameters</title>
<variablelist>
<varlistentry>
<term><literal>TRUSTED</literal></term>
<listitem>
<para><literal>TRUSTED</literal> specifies that the language does
not grant access to data that the user would not otherwise
have. If this key word is omitted
when registering the language, only users with the
<productname>PostgreSQL</productname> superuser privilege can
use this language to create new functions.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><literal>PROCEDURAL</literal></term>
<listitem>
<para>
This is a noise word.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><replaceable class="parameter">name</replaceable></term>
<listitem>
<para>
The name of the new procedural language.
The name must be unique among the languages in the database.
</para>
<para>
For backward compatibility, the name can be enclosed by single
quotes.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><literal>HANDLER</literal> <replaceable class="parameter">call_handler</replaceable></term>
<listitem>
<para><replaceable class="parameter">call_handler</replaceable> is
the name of a previously registered function that will be
called to execute the procedural language's functions. The call
handler for a procedural language must be written in a compiled
language such as C with version 1 call convention and
registered with <productname>PostgreSQL</productname> as a
function taking no arguments and returning the
<type>language_handler</type> type, a placeholder type that is
simply used to identify the function as a call handler.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><literal>INLINE</literal> <replaceable class="parameter">inline_handler</replaceable></term>
<listitem>
<para><replaceable class="parameter">inline_handler</replaceable> is the
name of a previously registered function that will be called
to execute an anonymous code block
(<xref linkend="sql-do"> command)
in this language.
If no <replaceable class="parameter">inline_handler</replaceable>
function is specified, the language does not support anonymous code
blocks.
The handler function must take one argument of
type <type>internal</type>, which will be the <command>DO</> command's
internal representation, and it will typically return
<type>void</>. The return value of the handler is ignored.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><literal>VALIDATOR</literal> <replaceable class="parameter">valfunction</replaceable></term>
<listitem>
<para><replaceable class="parameter">valfunction</replaceable> is the
name of a previously registered function that will be called
when a new function in the language is created, to validate the
new function.
If no
validator function is specified, then a new function will not
be checked when it is created.
The validator function must take one argument of
type <type>oid</type>, which will be the OID of the
to-be-created function, and will typically return <type>void</>.
</para>
<para>
A validator function would typically inspect the function body
for syntactical correctness, but it can also look at other
properties of the function, for example if the language cannot
handle certain argument types. To signal an error, the
validator function should use the <function>ereport()</function>
function. The return value of the function is ignored.
</para>
</listitem>
</varlistentry>
</variablelist>
<para>
The <literal>TRUSTED</> option and the support function name(s) are
ignored if the server has an entry for the specified language
name in <structname>pg_pltemplate</>.
</para>
</refsect1>
<refsect1 id="sql-createlanguage-notes">
<title>Notes</title>
<para>
The <xref linkend="app-createlang"> program is a simple wrapper around
the <command>CREATE LANGUAGE</> command. It eases
installation of procedural languages from the shell command line.
</para>
<para>
Use <xref linkend="sql-droplanguage">, or better yet the <xref
linkend="app-droplang"> program, to drop procedural languages.
</para>
<para>
The system catalog <classname>pg_language</classname> (see <xref
linkend="catalog-pg-language">) records information about the
currently installed languages. Also, <command>createlang</command>
has an option to list the installed languages.
</para>
<para>
To create functions in a procedural language, a user must have the
<literal>USAGE</literal> privilege for the language. By default,
<literal>USAGE</> is granted to <literal>PUBLIC</> (i.e., everyone)
for trusted languages. This can be revoked if desired.
</para>
<para>
Procedural languages are local to individual databases.
However, a language can be installed into the <literal>template1</literal>
database, which will cause it to be available automatically in
all subsequently-created databases.
</para>
<para>
The call handler function, the inline handler function (if any),
and the validator function (if any)
must already exist if the server does not have an entry for the language
in <structname>pg_pltemplate</>. But when there is an entry,
the functions need not already exist;
they will be automatically defined if not present in the database.
(This might result in <command>CREATE LANGUAGE</> failing, if the
shared library that implements the language is not available in
the installation.)
</para>
<para>
In <productname>PostgreSQL</productname> versions before 7.3, it was
necessary to declare handler functions as returning the placeholder
type <type>opaque</>, rather than <type>language_handler</>.
To support loading
of old dump files, <command>CREATE LANGUAGE</> will accept a function
declared as returning <type>opaque</>, but it will issue a notice and
change the function's declared return type to <type>language_handler</>.
</para>
</refsect1>
<refsect1 id="sql-createlanguage-examples">
<title>Examples</title>
<para>
The preferred way of creating any of the standard procedural languages
is just:
<programlisting>
CREATE LANGUAGE plperl;
</programlisting>
</para>
<para>
For a language not known in the <structname>pg_pltemplate</> catalog, a
sequence such as this is needed:
<programlisting>
CREATE FUNCTION plsample_call_handler() RETURNS language_handler
AS '$libdir/plsample'
LANGUAGE C;
CREATE LANGUAGE plsample
HANDLER plsample_call_handler;
</programlisting></para>
</refsect1>
<refsect1 id="sql-createlanguage-compat">
<title>Compatibility</title>
<para>
<command>CREATE LANGUAGE</command> is a
<productname>PostgreSQL</productname> extension.
</para>
</refsect1>
<refsect1>
<title>See Also</title>
<simplelist type="inline">
<member><xref linkend="sql-alterlanguage"></member>
<member><xref linkend="sql-createfunction"></member>
<member><xref linkend="sql-droplanguage"></member>
<member><xref linkend="sql-grant"></member>
<member><xref linkend="sql-revoke"></member>
<member><xref linkend="app-createlang"></member>
<member><xref linkend="app-droplang"></member>
</simplelist>
</refsect1>
</refentry>

View File

@ -18,11 +18,7 @@ CREATE [ [ GLOBAL | LOCAL ] { TEMPORARY | TEMP } | UNLOGGED ] TABLE [ IF NOT EXI
[ WITH ( {storage_parameter = value} [, ... ] ) ] [ WITH ( {storage_parameter = value} [, ... ] ) ]
[ ON COMMIT { PRESERVE ROWS | DELETE ROWS | DROP } ] [ ON COMMIT { PRESERVE ROWS | DELETE ROWS | DROP } ]
[ COMPRESS | NOCOMPRESS ] [ COMPRESS | NOCOMPRESS ]
[ TABLESPACE tablespace_name ] [ TABLESPACE tablespace_name ];
[ DISTRIBUTE BY { REPLICATION | { HASH ( column_name [,...] ) |
RANGE ( column_name [,...] ) range_distribution_rules |
LIST ( column_name [,...] ) list_distribution_rules } } ]
[ TO { GROUP groupname | NODE ( nodename [, ... ] ) } ];
where column_constraint can be: where column_constraint can be:
[ CONSTRAINT constraint_name ] [ CONSTRAINT constraint_name ]
@ -52,19 +48,6 @@ where like_option can be:
where index_parameters can be: where index_parameters can be:
[ WITH ( {storage_parameter = value} [, ... ] ) ] [ WITH ( {storage_parameter = value} [, ... ] ) ]
[ USING INDEX TABLESPACE tablespace_name ] [ USING INDEX TABLESPACE tablespace_name ]
where range_distribution_rules can be:
[ ( SLICE name VALUES LESS THAN (expression | MAXVALUE [, ... ]) [DATANODE datanode_name]
[, ... ] ) |
( SLICE name START (expression) END (expression) EVERY (expression) [DATANODE datanode_name]
[, ... ] ) |
SLICE REFERENCES table_name
]
where list_distribution_rules can be:
[ ( SLICE name VALUES (expression [, ... ]) [DATANODE datanode_name]
[, ... ] ) |
( SLICE name VALUES (DEFAULT) [DATANODE datanode_name] ) |
SLICE REFERENCES table_name
]
</synopsis> </synopsis>
</refsynopsisdiv> </refsynopsisdiv>
</refentry> </refentry>

View File

@ -480,6 +480,21 @@ static const SchemaQuery Query_for_list_of_matviews = {
NULL NULL
}; };
static const SchemaQuery Query_for_list_of_constraints_with_schema = {
/* catname */
"pg_catalog.pg_constraint c",
/* selcondition */
"c.conrelid <> 0",
/* viscondition */
"true",
/* namespace */
"c.connamespace",
/* result */
"pg_catalog.quote_ident(c.conname)",
/* qualresult */
NULL
};
/* /*
* Queries to get lists of names of various kinds of things, possibly * Queries to get lists of names of various kinds of things, possibly
* restricted to names matching a partially entered name. In these queries, * restricted to names matching a partially entered name. In these queries,
@ -675,6 +690,8 @@ typedef struct {
static const pgsql_thing_t words_after_create[] = { static const pgsql_thing_t words_after_create[] = {
{"AGGREGATE", NULL, &Query_for_list_of_aggregates, 0}, {"AGGREGATE", NULL, &Query_for_list_of_aggregates, 0},
{"APP WORKLOAD GROUP", NULL, NULL, 0},
{"APP WORKLOAD GROUP MAPPING", NULL, NULL, 0},
#ifdef PGXC #ifdef PGXC
{"BARRIER", NULL, NULL, 0}, /* Comes barrier name next, so skip it */ {"BARRIER", NULL, NULL, 0}, /* Comes barrier name next, so skip it */
#endif #endif
@ -898,7 +915,7 @@ static char** PsqlCompletion(const char *text, int start, int end)
"COMMENT", "COMMIT", "COPY", "CREATE", "CURSOR", "DEALLOCATE", "DECLARE", "COMMENT", "COMMIT", "COPY", "CREATE", "CURSOR", "DEALLOCATE", "DECLARE",
"DELETE FROM", "DISCARD", "DO", "DROP", "END", "EXECUTE", "EXPLAIN", "FETCH", "DELETE FROM", "DISCARD", "DO", "DROP", "END", "EXECUTE", "EXPLAIN", "FETCH",
"GRANT", "INSERT", "LISTEN", "LOAD", "LOCK", "MOVE", "NOTIFY", "PREPARE", "GRANT", "INSERT", "LISTEN", "LOAD", "LOCK", "MOVE", "NOTIFY", "PREPARE",
"REASSIGN", "REFRESH MATERIALIZED VIEW", "REINDEX", "RELEASE", "RESET", "REVOKE", "ROLLBACK", "REASSIGN", "REFRESH", "REINDEX", "RELEASE", "RESET", "REVOKE", "ROLLBACK",
"SAVEPOINT", "SECURITY LABEL", "SELECT", "SET", "SHOW", "START", "SAVEPOINT", "SECURITY LABEL", "SELECT", "SET", "SHOW", "START",
"TABLE", "TRUNCATE", "UNLISTEN", "UPDATE", "VACUUM", "VALUES", "WITH", "TABLE", "TRUNCATE", "UNLISTEN", "UPDATE", "VACUUM", "VALUES", "WITH",
NULL NULL
@ -1063,12 +1080,12 @@ static char** PsqlCompletion(const char *text, int start, int end)
*/ */
else if (pg_strcasecmp(PREV_WD, "ALTER") == 0 && pg_strcasecmp(PREV3_WD, "TABLE") != 0) { else if (pg_strcasecmp(PREV_WD, "ALTER") == 0 && pg_strcasecmp(PREV3_WD, "TABLE") != 0) {
static const char* const listAlter[] = { static const char* const listAlter[] = {
"AGGREGATE", "COLLATION", "CONVERSION", "DATABASE", "DEFAULT PRIVILEGES", "DOMAIN", "AGGREGATE", "APP WORKLOAD GROUP", "APP WORKLOAD GROUP MAPPING", "COLLATION", "CONVERSION",
"EXTENSION", "FOREIGN DATA WRAPPER", "FOREIGN TABLE", "FUNCTION", "DATABASE", "DEFAULT PRIVILEGES", "DOMAIN", "EXTENSION", "FOREIGN DATA WRAPPER",
"GROUP", "INDEX", "LANGUAGE", "LARGE OBJECT", "MATERIALIZED VIEW", "OPERATOR", "FOREIGN TABLE", "FUNCTION", "GROUP", "INDEX", "LANGUAGE", "LARGE OBJECT",
"POLICY", "PROCEDURE", "ROLE", "ROW LEVEL SECURITY POLICY", "RULE", "SCHEMA", "MATERIALIZED VIEW", "OPERATOR", "POLICY", "PROCEDURE", "ROLE", "ROW LEVEL SECURITY POLICY",
"SERVER", "SESSION", "SEQUENCE", "SYSTEM", "TABLE", "TABLESPACE", "TEXT SEARCH", "TRIGGER", "RULE", "SCHEMA", "SERVER", "SESSION", "SEQUENCE", "SYSTEM", "TABLE", "TABLESPACE",
"TYPE", "USER", "USER MAPPING FOR", "VIEW", NULL "TEXT SEARCH", "TRIGGER", "TYPE", "USER", "USER MAPPING FOR", "VIEW", NULL
}; };
COMPLETE_WITH_LIST(listAlter); COMPLETE_WITH_LIST(listAlter);
@ -1260,11 +1277,11 @@ static char** PsqlCompletion(const char *text, int start, int end)
"INDEPENDENT", "INHERIT", "LOGIN", "MONADMIN", "NOAUDITADMIN", "INDEPENDENT", "INHERIT", "LOGIN", "MONADMIN", "NOAUDITADMIN",
"NOCREATEDB", "NOCREATEROLE", "NOCREATEUSER", "NODE GROUP", "NOCREATEDB", "NOCREATEROLE", "NOCREATEUSER", "NODE GROUP",
"NOINDEPENDENT", "NOINHERIT", "NOLOGIN", "NOMONADMIN", "NOOPRADMIN", "NOINDEPENDENT", "NOINHERIT", "NOLOGIN", "NOMONADMIN", "NOOPRADMIN",
"NOPERSISTENCE", "NOPOLADMIN", "NOREPLICATION", "NOSUPERUSER", "NOPERSISTENCE", "NOPOLADMIN", "NOREPLICATION",
"NOSYSADMIN", "NOUSEFT", "NOVCADMIN", "OPRADMIN", "PASSWORD", "NOSYSADMIN", "NOUSEFT", "NOVCADMIN", "OPRADMIN", "PASSWORD",
"PERM SPACE", "PERSISTENCE", "PGUSER", "POLADMIN", "RENAME TO", "PERM SPACE", "PERSISTENCE", "PGUSER", "POLADMIN", "RENAME TO",
"REPLICATION", "RESET", "RESOURCE POOL", "SET", "SPILL SPACE", "REPLICATION", "RESET", "RESOURCE POOL", "SET", "SPILL SPACE",
"SUPERUSER", "SYSADMIN", "TEMP SPACE", "UNENCRYPTED", "USEFT", "SYSADMIN", "TEMP SPACE", "UNENCRYPTED", "USEFT",
"USER GROUP", "VALID", "VCADMIN", "WITH", NULL "USER GROUP", "VALID", "VCADMIN", "WITH", NULL
}; };
@ -1292,11 +1309,11 @@ static char** PsqlCompletion(const char *text, int start, int end)
"INDEPENDENT", "INHERIT", "LOGIN", "MONADMIN", "NOAUDITADMIN", "INDEPENDENT", "INHERIT", "LOGIN", "MONADMIN", "NOAUDITADMIN",
"NOCREATEDB", "NOCREATEROLE", "NOCREATEUSER", "NODE GROUP", "NOCREATEDB", "NOCREATEROLE", "NOCREATEUSER", "NODE GROUP",
"NOINDEPENDENT", "NOINHERIT", "NOLOGIN", "NOMONADMIN", "NOOPRADMIN", "NOINDEPENDENT", "NOINHERIT", "NOLOGIN", "NOMONADMIN", "NOOPRADMIN",
"NOPERSISTENCE", "NOPOLADMIN", "NOREPLICATION", "NOSUPERUSER", "NOPERSISTENCE", "NOPOLADMIN", "NOREPLICATION",
"NOSYSADMIN", "NOUSEFT", "NOVCADMIN", "OPRADMIN", "PASSWORD", "NOSYSADMIN", "NOUSEFT", "NOVCADMIN", "OPRADMIN", "PASSWORD",
"PERM SPACE", "PERSISTENCE", "PGUSER", "POLADMIN", "RENAME TO", "PERM SPACE", "PERSISTENCE", "PGUSER", "POLADMIN", "RENAME TO",
"REPLICATION", "RESET", "RESOURCE POOL", "SET", "SPILL SPACE", "REPLICATION", "RESET", "RESOURCE POOL", "SET", "SPILL SPACE",
"SUPERUSER", "SYSADMIN", "TEMP SPACE", "UNENCRYPTED", "USEFT", "SYSADMIN", "TEMP SPACE", "UNENCRYPTED", "USEFT",
"USER GROUP", "VALID", "VCADMIN", NULL "USER GROUP", "VALID", "VCADMIN", NULL
}; };
@ -1920,10 +1937,16 @@ static char** PsqlCompletion(const char *text, int start, int end)
COMPLETE_WITH_QUERY(Query_for_list_of_available_extensions); COMPLETE_WITH_QUERY(Query_for_list_of_available_extensions);
/* CREATE EXTENSION <name> */ /* CREATE EXTENSION <name> */
else if (pg_strcasecmp(PREV3_WD, "CREATE") == 0 && pg_strcasecmp(PREV2_WD, "EXTENSION") == 0) { else if (pg_strcasecmp(PREV3_WD, "CREATE") == 0 && pg_strcasecmp(PREV2_WD, "EXTENSION") == 0) {
static const char* const listCreateExtension[] = {"WITH SCHEMA", "VERSION", "FROM", NULL}; static const char* const listCreateExtension[] = {"WITH", "SCHEMA", "VERSION", "FROM", NULL};
COMPLETE_WITH_LIST(listCreateExtension); COMPLETE_WITH_LIST(listCreateExtension);
} }
else if (pg_strcasecmp(PREV4_WD, "CREATE") == 0 && pg_strcasecmp(PREV3_WD, "EXTENSION") == 0 &&
pg_strcasecmp(PREV_WD, "WITH") == 0) {
static const char* const listCreateExtensionWith[] = {"SCHEMA", "VERSION", "FROM", NULL};
COMPLETE_WITH_LIST(listCreateExtensionWith);
}
/* CREATE FOREIGN */ /* CREATE FOREIGN */
else if (pg_strcasecmp(PREV2_WD, "CREATE") == 0 && pg_strcasecmp(PREV_WD, "FOREIGN") == 0) { else if (pg_strcasecmp(PREV2_WD, "CREATE") == 0 && pg_strcasecmp(PREV_WD, "FOREIGN") == 0) {
static const char* const listCreateForeign[] = {"DATA WRAPPER", "TABLE", NULL}; static const char* const listCreateForeign[] = {"DATA WRAPPER", "TABLE", NULL};
@ -2286,10 +2309,10 @@ static char** PsqlCompletion(const char *text, int start, int end)
"IN GROUP", "IN ROLE", "INDEPENDENT", "INHERIT", "LOGIN", "MONADMIN", "IN GROUP", "IN ROLE", "INDEPENDENT", "INHERIT", "LOGIN", "MONADMIN",
"NOAUDITADMIN", "NOCREATEDB", "NOCREATEROLE", "NOCREATEUSER", "NODE GROUP", "NOAUDITADMIN", "NOCREATEDB", "NOCREATEROLE", "NOCREATEUSER", "NODE GROUP",
"NOINDEPENDENT", "NOINHERIT", "NOLOGIN", "NOMONADMIN", "NOOPRADMIN", "NOINDEPENDENT", "NOINHERIT", "NOLOGIN", "NOMONADMIN", "NOOPRADMIN",
"NOPERSISTENCE", "NOPOLADMIN", "NOREPLICATION", "NOSUPERUSER", "NOSYSADMIN", "NOPERSISTENCE", "NOPOLADMIN", "NOREPLICATION", "NOSYSADMIN",
"NOUSEFT", "NOVCADMIN", "OPRADMIN", "PASSWORD", "PERM SPACE", "PERSISTENCE", "NOUSEFT", "NOVCADMIN", "OPRADMIN", "PASSWORD", "PERM SPACE", "PERSISTENCE",
"PGUSER", "POLADMIN", "PROFILE", "PROFILE DEFAULT", "REPLICATION", "PGUSER", "POLADMIN", "PROFILE", "PROFILE DEFAULT", "REPLICATION",
"RESOURCE POOL", "ROLE", "SPILL SPACE", "SUPERUSER", "SYSADMIN", "SYSID", "RESOURCE POOL", "ROLE", "SPILL SPACE", "SYSADMIN", "SYSID",
"TEMP SPACE", "UNENCRYPTED", "USEFT", "USER", "USER GROUP", "VALID", "TEMP SPACE", "UNENCRYPTED", "USEFT", "USER", "USER GROUP", "VALID",
"VCADMIN", "WITH", NULL "VCADMIN", "WITH", NULL
}; };
@ -2319,10 +2342,10 @@ static char** PsqlCompletion(const char *text, int start, int end)
"IN GROUP", "IN ROLE", "INDEPENDENT", "INHERIT", "LOGIN", "MONADMIN", "IN GROUP", "IN ROLE", "INDEPENDENT", "INHERIT", "LOGIN", "MONADMIN",
"NOAUDITADMIN", "NOCREATEDB", "NOCREATEROLE", "NOCREATEUSER", "NODE GROUP", "NOAUDITADMIN", "NOCREATEDB", "NOCREATEROLE", "NOCREATEUSER", "NODE GROUP",
"NOINDEPENDENT", "NOINHERIT", "NOLOGIN", "NOMONADMIN", "NOOPRADMIN", "NOINDEPENDENT", "NOINHERIT", "NOLOGIN", "NOMONADMIN", "NOOPRADMIN",
"NOPERSISTENCE", "NOPOLADMIN", "NOREPLICATION", "NOSUPERUSER", "NOSYSADMIN", "NOPERSISTENCE", "NOPOLADMIN", "NOREPLICATION", "NOSYSADMIN",
"NOUSEFT", "NOVCADMIN", "OPRADMIN", "PASSWORD", "PERM SPACE", "PERSISTENCE", "NOUSEFT", "NOVCADMIN", "OPRADMIN", "PASSWORD", "PERM SPACE", "PERSISTENCE",
"PGUSER", "POLADMIN", "PROFILE", "PROFILE DEFAULT", "REPLICATION", "PGUSER", "POLADMIN", "PROFILE", "PROFILE DEFAULT", "REPLICATION",
"RESOURCE POOL", "ROLE", "SPILL SPACE", "SUPERUSER", "SYSADMIN", "SYSID", "RESOURCE POOL", "ROLE", "SPILL SPACE", "SYSADMIN", "SYSID",
"TEMP SPACE", "UNENCRYPTED", "USEFT", "USER", "USER GROUP", "VALID", "TEMP SPACE", "UNENCRYPTED", "USEFT", "USER", "USER GROUP", "VALID",
"VCADMIN", NULL "VCADMIN", NULL
}; };
@ -2394,7 +2417,9 @@ static char** PsqlCompletion(const char *text, int start, int end)
/* CURSOR */ /* CURSOR */
else if (pg_strcasecmp(PREV2_WD, "CURSOR") == 0) { else if (pg_strcasecmp(PREV2_WD, "CURSOR") == 0) {
static const char* const listDeclareCursor[] = {"BINARY", "NO SCROLL","WITH HOLD", "WITHOUT HOLD", "FOR", NULL}; static const char* const listDeclareCursor[] = {
"BINARY", "SCROLL", "NO SCROLL","INSENSITIVE","FOR", NULL
};
COMPLETE_WITH_LIST(listDeclareCursor); COMPLETE_WITH_LIST(listDeclareCursor);
} }
@ -2658,7 +2683,11 @@ static char** PsqlCompletion(const char *text, int start, int end)
" UNION SELECT 'LARGE OBJECT'" " UNION SELECT 'LARGE OBJECT'"
" UNION SELECT 'SCHEMA'" " UNION SELECT 'SCHEMA'"
" UNION SELECT 'TABLESPACE'" " UNION SELECT 'TABLESPACE'"
" UNION SELECT 'TYPE'"); " UNION SELECT 'TYPE'"
" UNION SELECT 'TABLE'"
" UNION SELECT 'DIRECTORY'"
" UNION SELECT 'NODE GROUP'"
" UNION SELECT 'DATA SOURCE'");
else if ((pg_strcasecmp(PREV4_WD, "GRANT") == 0 || pg_strcasecmp(PREV4_WD, "REVOKE") == 0) && else if ((pg_strcasecmp(PREV4_WD, "GRANT") == 0 || pg_strcasecmp(PREV4_WD, "REVOKE") == 0) &&
pg_strcasecmp(PREV2_WD, "ON") == 0 && pg_strcasecmp(PREV_WD, "FOREIGN") == 0) { pg_strcasecmp(PREV2_WD, "ON") == 0 && pg_strcasecmp(PREV_WD, "FOREIGN") == 0) {
static const char* const listPrivilegeForeign[] = {"DATA WRAPPER", "SERVER", NULL}; static const char* const listPrivilegeForeign[] = {"DATA WRAPPER", "SERVER", NULL};
@ -2683,6 +2712,8 @@ static char** PsqlCompletion(const char *text, int start, int end)
COMPLETE_WITH_QUERY(Query_for_list_of_tablespaces); COMPLETE_WITH_QUERY(Query_for_list_of_tablespaces);
else if (pg_strcasecmp(PREV_WD, "TYPE") == 0) else if (pg_strcasecmp(PREV_WD, "TYPE") == 0)
COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_datatypes, NULL); COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_datatypes, NULL);
else if (pg_strcasecmp(PREV_WD, "DATA") == 0)
COMPLETE_WITH_CONST("SOURCE");
else if (pg_strcasecmp(PREV4_WD, "GRANT") == 0) else if (pg_strcasecmp(PREV4_WD, "GRANT") == 0)
COMPLETE_WITH_CONST("TO"); COMPLETE_WITH_CONST("TO");
else else
@ -2773,8 +2804,11 @@ static char** PsqlCompletion(const char *text, int start, int end)
/* Complete LOCK [TABLE] <table> with "IN" */ /* Complete LOCK [TABLE] <table> with "IN" */
else if ((pg_strcasecmp(PREV2_WD, "LOCK") == 0 && pg_strcasecmp(PREV_WD, "TABLE") != 0) || else if ((pg_strcasecmp(PREV2_WD, "LOCK") == 0 && pg_strcasecmp(PREV_WD, "TABLE") != 0) ||
(pg_strcasecmp(PREV2_WD, "TABLE") == 0 && pg_strcasecmp(PREV3_WD, "LOCK") == 0)) (pg_strcasecmp(PREV2_WD, "TABLE") == 0 && pg_strcasecmp(PREV3_WD, "LOCK") == 0)) {
COMPLETE_WITH_CONST("IN"); static const char* const lockTableList[] = {"IN", "NOWAIT", NULL};
COMPLETE_WITH_LIST(lockTableList);
}
/* Complete LOCK [TABLE] <table> IN with a lock mode */ /* Complete LOCK [TABLE] <table> IN with a lock mode */
else if (pg_strcasecmp(PREV_WD, "IN") == 0 && (pg_strcasecmp(PREV3_WD, "LOCK") == 0 || else if (pg_strcasecmp(PREV_WD, "IN") == 0 && (pg_strcasecmp(PREV3_WD, "LOCK") == 0 ||
@ -2790,6 +2824,20 @@ static char** PsqlCompletion(const char *text, int start, int end)
COMPLETE_WITH_LIST(lockModes); COMPLETE_WITH_LIST(lockModes);
} }
else if ((pg_strcasecmp(PREV_WD, "ACCESS") == 0 || pg_strcasecmp(PREV_WD, "ROW") == 0) &&
pg_strcasecmp(PREV2_WD, "IN") == 0 && (pg_strcasecmp(PREV4_WD, "LOCK") == 0 ||
(pg_strcasecmp(PREV4_WD, "TABLE") == 0 && pg_strcasecmp(PREV5_WD, "LOCK") == 0))) {
static const char* const lockModesAccess[] = {"SHARE MODE", "EXCLUSIVE MODE", NULL};
COMPLETE_WITH_LIST(lockModesAccess);
}
else if (pg_strcasecmp(PREV_WD, "SHARE") == 0&& pg_strcasecmp(PREV2_WD, "IN") == 0 &&
(pg_strcasecmp(PREV4_WD, "LOCK") == 0 || (pg_strcasecmp(PREV4_WD, "TABLE") == 0 &&
pg_strcasecmp(PREV5_WD, "LOCK") == 0))) {
static const char* const lockModesAccess[] = {"UPDATE EXCLUSIVE MODE", "ROW EXCLUSIVE MODE", "MODE", NULL};
COMPLETE_WITH_LIST(lockModesAccess);
}
/* NOTIFY */ /* NOTIFY */
else if (pg_strcasecmp(PREV_WD, "NOTIFY") == 0) else if (pg_strcasecmp(PREV_WD, "NOTIFY") == 0)
COMPLETE_WITH_QUERY("SELECT pg_catalog.quote_ident(channel) FROM pg_catalog.pg_listening_channels() AS channel " COMPLETE_WITH_QUERY("SELECT pg_catalog.quote_ident(channel) FROM pg_catalog.pg_listening_channels() AS channel "
@ -2838,8 +2886,10 @@ static char** PsqlCompletion(const char *text, int start, int end)
COMPLETE_WITH_QUERY(Query_for_list_of_roles); COMPLETE_WITH_QUERY(Query_for_list_of_roles);
/* REFRESH MATERIALIZED VIEW */ /* REFRESH MATERIALIZED VIEW */
else if (pg_strcasecmp(PREV_WD, "REFRESH") == 0) else if (pg_strcasecmp(PREV_WD, "REFRESH") == 0) {
COMPLETE_WITH_CONST("MATERIALIZED VIEW"); static const char* const refreshObject[] = {"MATERIALIZED VIEW", "INCREMENTAL MATERIALIZED VIEW", NULL};
COMPLETE_WITH_LIST(refreshObject);
}
else if (pg_strcasecmp(PREV2_WD, "REFRESH") == 0 && pg_strcasecmp(PREV_WD, "MATERIALIZED") == 0) else if (pg_strcasecmp(PREV2_WD, "REFRESH") == 0 && pg_strcasecmp(PREV_WD, "MATERIALIZED") == 0)
COMPLETE_WITH_CONST("VIEW"); COMPLETE_WITH_CONST("VIEW");
else if (pg_strcasecmp(PREV3_WD, "REFRESH") == 0 && pg_strcasecmp(PREV2_WD, "MATERIALIZED") == 0 && else if (pg_strcasecmp(PREV3_WD, "REFRESH") == 0 && pg_strcasecmp(PREV2_WD, "MATERIALIZED") == 0 &&
@ -2948,6 +2998,9 @@ static char** PsqlCompletion(const char *text, int start, int end)
COMPLETE_WITH_LIST(myList); COMPLETE_WITH_LIST(myList);
} }
else if (pg_strcasecmp(PREV2_WD, "SET") == 0 && pg_strcasecmp(PREV_WD, "CONSTRAINTS") == 0) {
COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_constraints_with_schema, " UNION SELECT 'ALL'");
}
/* Complete SET CONSTRAINTS <foo> with DEFERRED|IMMEDIATE */ /* Complete SET CONSTRAINTS <foo> with DEFERRED|IMMEDIATE */
else if (pg_strcasecmp(PREV3_WD, "SET") == 0 && pg_strcasecmp(PREV2_WD, "CONSTRAINTS") == 0) { else if (pg_strcasecmp(PREV3_WD, "SET") == 0 && pg_strcasecmp(PREV2_WD, "CONSTRAINTS") == 0) {
static const char* const constraintList[] = {"DEFERRED", "IMMEDIATE", NULL}; static const char* const constraintList[] = {"DEFERRED", "IMMEDIATE", NULL};