Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit4cba9c2

Browse files
committed
Add more tab completion for CREATE TABLE in psql
The following completion patterns are added:- CREATE TABLE <name> with '(', OF or PARTITION OF.- CREATE TABLE <name> OF with list of composite types.- CREATE TABLE name (...) with PARTITION OF, WITH, TABLESPACE, ONCOMMIT (depending on the presence of a temporary table).- CREATE TABLE ON COMMIT with actions (only for temporary tables).Author: Dagfinn Ilmari MannsåkerDiscussion:https://postgr.es/m/d8j1s77kdbb.fsf@dalvik.ping.uio.no
1 parent1075dfd commit4cba9c2

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

‎src/bin/psql/tab-complete.c

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,18 @@ static const SchemaQuery Query_for_list_of_datatypes = {
344344
.qualresult="pg_catalog.quote_ident(t.typname)",
345345
};
346346

347+
staticconstSchemaQueryQuery_for_list_of_composite_datatypes= {
348+
.catname="pg_catalog.pg_type t",
349+
/* selcondition --- only get composite types */
350+
.selcondition="(SELECT c.relkind = "CppAsString2(RELKIND_COMPOSITE_TYPE)
351+
" FROM pg_catalog.pg_class c WHERE c.oid = t.typrelid) "
352+
"AND t.typname !~ '^_'",
353+
.viscondition="pg_catalog.pg_type_is_visible(t.oid)",
354+
.namespace="t.typnamespace",
355+
.result="pg_catalog.format_type(t.oid, NULL)",
356+
.qualresult="pg_catalog.quote_ident(t.typname)",
357+
};
358+
347359
staticconstSchemaQueryQuery_for_list_of_domains= {
348360
.catname="pg_catalog.pg_type t",
349361
.selcondition="t.typtype = 'd'",
@@ -2412,6 +2424,24 @@ psql_completion(const char *text, int start, int end)
24122424
/* Limited completion support for partition bound specification */
24132425
elseif (TailMatches("PARTITION","OF",MatchAny))
24142426
COMPLETE_WITH("FOR VALUES","DEFAULT");
2427+
/* Complete CREATE TABLE <name> with '(', OF or PARTITION OF */
2428+
elseif (TailMatches("CREATE","TABLE",MatchAny)||
2429+
TailMatches("CREATE","TEMP|TEMPORARY|UNLOGGED","TABLE",MatchAny))
2430+
COMPLETE_WITH("(","OF","PARTITION OF");
2431+
/* Complete CREATE TABLE <name> OF with list of composite types */
2432+
elseif (TailMatches("CREATE","TABLE",MatchAny,"OF")||
2433+
TailMatches("CREATE","TEMP|TEMPORARY|UNLOGGED","TABLE",MatchAny,"OF"))
2434+
COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_composite_datatypes,NULL);
2435+
/* Complete CREATE TABLE name (...) with supported options */
2436+
elseif (TailMatches("CREATE","TABLE",MatchAny,"(*)")||
2437+
TailMatches("CREATE","UNLOGGED","TABLE",MatchAny,"(*)"))
2438+
COMPLETE_WITH("INHERITS (","PARTITION BY","TABLESPACE","WITH (");
2439+
elseif (TailMatches("CREATE","TEMP|TEMPORARY","TABLE",MatchAny,"(*)"))
2440+
COMPLETE_WITH("INHERITS (","ON COMMIT","PARTITION BY",
2441+
"TABLESPACE","WITH (");
2442+
/* Complete CREATE TABLE ON COMMIT with actions */
2443+
elseif (TailMatches("CREATE","TEMP|TEMPORARY","TABLE",MatchAny,"(*)","ON","COMMIT"))
2444+
COMPLETE_WITH("DELETE ROWS","DROP","PRESERVE ROWS");
24152445

24162446
/* CREATE TABLESPACE */
24172447
elseif (Matches("CREATE","TABLESPACE",MatchAny))

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp