@@ -354,6 +354,21 @@ static const SchemaQuery Query_for_list_of_tables = {
354
354
NULL
355
355
};
356
356
357
+ static const SchemaQuery Query_for_list_of_constraints_with_schema = {
358
+ /* catname */
359
+ "pg_catalog.pg_constraint c" ,
360
+ /* selcondition */
361
+ "c.conrelid <> 0" ,
362
+ /* viscondition */
363
+ "true" , /* there is no pg_constraint_is_visible */
364
+ /* namespace */
365
+ "c.connamespace" ,
366
+ /* result */
367
+ "pg_catalog.quote_ident(c.conname)" ,
368
+ /* qualresult */
369
+ NULL
370
+ };
371
+
357
372
/* The bit masks for the following three functions come from
358
373
* src/include/catalog/pg_trigger.h.
359
374
*/
@@ -587,6 +602,28 @@ static const SchemaQuery Query_for_list_of_views = {
587
602
" and pg_catalog.quote_ident(c1.relname)='%s'"\
588
603
" and pg_catalog.pg_table_is_visible(c1.oid)"
589
604
605
+ #define Query_for_all_table_constraints \
606
+ "SELECT pg_catalog.quote_ident(conname) "\
607
+ " FROM pg_catalog.pg_constraint c "\
608
+ " WHERE c.conrelid <> 0 "
609
+
610
+ /* the silly-looking length condition is just to eat up the current word */
611
+ #define Query_for_constraint_of_type \
612
+ "SELECT pg_catalog.quote_ident(conname) "\
613
+ " FROM pg_catalog.pg_type t, pg_catalog.pg_constraint con "\
614
+ " WHERE t.oid=contypid and (%d = pg_catalog.length('%s'))"\
615
+ " and pg_catalog.quote_ident(t.typname)='%s'"\
616
+ " and pg_catalog.pg_type_is_visible(t.oid)"
617
+
618
+ /* the silly-looking length condition is just to eat up the current word */
619
+ #define Query_for_list_of_tables_for_constraint \
620
+ "SELECT pg_catalog.quote_ident(relname) "\
621
+ " FROM pg_catalog.pg_class"\
622
+ " WHERE (%d = pg_catalog.length('%s'))"\
623
+ " AND oid IN "\
624
+ " (SELECT conrelid FROM pg_catalog.pg_constraint "\
625
+ " WHERE pg_catalog.quote_ident(conname)='%s')"
626
+
590
627
/* the silly-looking length condition is just to eat up the current word */
591
628
#define Query_for_list_of_tables_for_trigger \
592
629
"SELECT pg_catalog.quote_ident(relname) "\
@@ -1147,6 +1184,17 @@ psql_completion(char *text, int start, int end)
1147
1184
1148
1185
COMPLETE_WITH_LIST (list_ALTERDOMAIN2 );
1149
1186
}
1187
+ /* ALTER DOMAIN <sth> DROP|RENAME|VALIDATE CONSTRAINT */
1188
+ else if (pg_strcasecmp (prev5_wd , "ALTER" ) == 0 &&
1189
+ pg_strcasecmp (prev4_wd , "DOMAIN" ) == 0 &&
1190
+ (pg_strcasecmp (prev2_wd , "DROP" ) == 0 ||
1191
+ pg_strcasecmp (prev2_wd , "RENAME" ) == 0 ||
1192
+ pg_strcasecmp (prev2_wd , "VALIDATE" ) == 0 ) &&
1193
+ pg_strcasecmp (prev_wd , "CONSTRAINT" ) == 0 )
1194
+ {
1195
+ completion_info_charp = prev3_wd ;
1196
+ COMPLETE_WITH_QUERY (Query_for_constraint_of_type );
1197
+ }
1150
1198
/* ALTER DOMAIN <sth> RENAME */
1151
1199
else if (pg_strcasecmp (prev4_wd , "ALTER" ) == 0 &&
1152
1200
pg_strcasecmp (prev3_wd , "DOMAIN" ) == 0 &&
@@ -1340,14 +1388,18 @@ psql_completion(char *text, int start, int end)
1340
1388
1341
1389
COMPLETE_WITH_LIST (list_TABLEDROP );
1342
1390
}
1343
- /* If we have TABLE <sth> DROP COLUMN, provide list of columns */
1344
- else if (pg_strcasecmp (prev4_wd , "TABLE" ) == 0 &&
1391
+ /* If we have ALTER TABLE <sth> DROP COLUMN, provide list of columns */
1392
+ else if (pg_strcasecmp (prev5_wd , "ALTER" ) == 0 &&
1393
+ pg_strcasecmp (prev4_wd , "TABLE" ) == 0 &&
1345
1394
pg_strcasecmp (prev2_wd , "DROP" ) == 0 &&
1346
1395
pg_strcasecmp (prev_wd , "COLUMN" ) == 0 )
1347
1396
COMPLETE_WITH_ATTR (prev3_wd , "" );
1348
- /* If we have TABLE <sth> DROP CONSTRAINT, provide list of constraints */
1349
- else if (pg_strcasecmp (prev4_wd , "TABLE" ) == 0 &&
1350
- pg_strcasecmp (prev2_wd , "DROP" ) == 0 &&
1397
+ /* If we have ALTER TABLE <sth> DROP|RENAME|VALIDATE CONSTRAINT, provide list of constraints */
1398
+ else if (pg_strcasecmp (prev5_wd , "ALTER" ) == 0 &&
1399
+ pg_strcasecmp (prev4_wd , "TABLE" ) == 0 &&
1400
+ (pg_strcasecmp (prev2_wd , "DROP" ) == 0 ||
1401
+ pg_strcasecmp (prev2_wd , "RENAME" ) == 0 ||
1402
+ pg_strcasecmp (prev2_wd , "VALIDATE" ) == 0 ) &&
1351
1403
pg_strcasecmp (prev_wd , "CONSTRAINT" ) == 0 )
1352
1404
{
1353
1405
completion_info_charp = prev3_wd ;
@@ -1744,6 +1796,26 @@ psql_completion(char *text, int start, int end)
1744
1796
1745
1797
COMPLETE_WITH_LIST (list_TRANS2 );
1746
1798
}
1799
+ else if (pg_strcasecmp (prev3_wd , "COMMENT" ) == 0 &&
1800
+ pg_strcasecmp (prev2_wd , "ON" ) == 0 &&
1801
+ pg_strcasecmp (prev_wd , "CONSTRAINT" ) == 0 )
1802
+ {
1803
+ COMPLETE_WITH_QUERY (Query_for_all_table_constraints );
1804
+ }
1805
+ else if (pg_strcasecmp (prev4_wd , "COMMENT" ) == 0 &&
1806
+ pg_strcasecmp (prev3_wd , "ON" ) == 0 &&
1807
+ pg_strcasecmp (prev2_wd , "CONSTRAINT" ) == 0 )
1808
+ {
1809
+ COMPLETE_WITH_CONST ("ON" );
1810
+ }
1811
+ else if (pg_strcasecmp (prev5_wd , "COMMENT" ) == 0 &&
1812
+ pg_strcasecmp (prev4_wd , "ON" ) == 0 &&
1813
+ pg_strcasecmp (prev3_wd , "CONSTRAINT" ) == 0 &&
1814
+ pg_strcasecmp (prev_wd , "ON" ) == 0 )
1815
+ {
1816
+ completion_info_charp = prev2_wd ;
1817
+ COMPLETE_WITH_QUERY (Query_for_list_of_tables_for_constraint );
1818
+ }
1747
1819
else if ((pg_strcasecmp (prev4_wd , "COMMENT" ) == 0 &&
1748
1820
pg_strcasecmp (prev3_wd , "ON" ) == 0 ) ||
1749
1821
(pg_strcasecmp (prev5_wd , "COMMENT" ) == 0 &&
@@ -2805,6 +2877,12 @@ psql_completion(char *text, int start, int end)
2805
2877
2806
2878
COMPLETE_WITH_LIST (my_list );
2807
2879
}
2880
+ /* SET CONSTRAINTS */
2881
+ else if (pg_strcasecmp (prev2_wd , "SET" ) == 0 &&
2882
+ pg_strcasecmp (prev_wd , "CONSTRAINTS" ) == 0 )
2883
+ {
2884
+ COMPLETE_WITH_SCHEMA_QUERY (Query_for_list_of_constraints_with_schema , "UNION SELECT 'ALL'" );
2885
+ }
2808
2886
/* Complete SET CONSTRAINTS <foo> with DEFERRED|IMMEDIATE */
2809
2887
else if (pg_strcasecmp (prev3_wd , "SET" ) == 0 &&
2810
2888
pg_strcasecmp (prev2_wd , "CONSTRAINTS" ) == 0 )
0 commit comments