@@ -303,6 +303,57 @@ static const SchemaQuery Query_for_list_of_tables = {
303
303
NULL
304
304
};
305
305
306
+ /* The bit masks for the following three functions come from
307
+ * src/include/catalog/pg_trigger.h.
308
+ */
309
+ static const SchemaQuery Query_for_list_of_insertables = {
310
+ /* catname */
311
+ "pg_catalog.pg_class c" ,
312
+ /* selcondition */
313
+ "(c.relkind = 'r' OR (c.relkind = 'v' AND c.relhastriggers AND EXISTS "
314
+ "(SELECT 1 FROM pg_catalog.pg_trigger t WHERE t.tgrelid = c.oid AND t.tgtype & (1 << 2) <> 0)))" ,
315
+ /* viscondition */
316
+ "pg_catalog.pg_table_is_visible(c.oid)" ,
317
+ /* namespace */
318
+ "c.relnamespace" ,
319
+ /* result */
320
+ "pg_catalog.quote_ident(c.relname)" ,
321
+ /* qualresult */
322
+ NULL
323
+ };
324
+
325
+ static const SchemaQuery Query_for_list_of_deletables = {
326
+ /* catname */
327
+ "pg_catalog.pg_class c" ,
328
+ /* selcondition */
329
+ "(c.relkind = 'r' OR (c.relkind = 'v' AND c.relhastriggers AND EXISTS "
330
+ "(SELECT 1 FROM pg_catalog.pg_trigger t WHERE t.tgrelid = c.oid AND t.tgtype & (1 << 3) <> 0)))" ,
331
+ /* viscondition */
332
+ "pg_catalog.pg_table_is_visible(c.oid)" ,
333
+ /* namespace */
334
+ "c.relnamespace" ,
335
+ /* result */
336
+ "pg_catalog.quote_ident(c.relname)" ,
337
+ /* qualresult */
338
+ NULL
339
+ };
340
+
341
+ static const SchemaQuery Query_for_list_of_updatables = {
342
+ /* catname */
343
+ "pg_catalog.pg_class c" ,
344
+ /* selcondition */
345
+ "(c.relkind = 'r' OR (c.relkind = 'v' AND c.relhastriggers AND EXISTS "
346
+ "(SELECT 1 FROM pg_catalog.pg_trigger t WHERE t.tgrelid = c.oid AND t.tgtype & (1 << 4) <> 0)))" ,
347
+ /* viscondition */
348
+ "pg_catalog.pg_table_is_visible(c.oid)" ,
349
+ /* namespace */
350
+ "c.relnamespace" ,
351
+ /* result */
352
+ "pg_catalog.quote_ident(c.relname)" ,
353
+ /* qualresult */
354
+ NULL
355
+ };
356
+
306
357
static const SchemaQuery Query_for_list_of_tisv = {
307
358
/* catname */
308
359
"pg_catalog.pg_class c" ,
@@ -1655,7 +1706,7 @@ psql_completion(char *text, int start, int end)
1655
1706
pg_strcasecmp (prev2_wd , "TRIGGER" ) == 0 )
1656
1707
{
1657
1708
static const char * const list_CREATETRIGGER [] =
1658
- {"BEFORE" , "AFTER" , NULL };
1709
+ {"BEFORE" , "AFTER" , "INSTEAD OF" , NULL };
1659
1710
1660
1711
COMPLETE_WITH_LIST (list_CREATETRIGGER );
1661
1712
}
@@ -1778,7 +1829,7 @@ psql_completion(char *text, int start, int end)
1778
1829
/* Complete DELETE FROM with a list of tables */
1779
1830
else if (pg_strcasecmp (prev2_wd , "DELETE" ) == 0 &&
1780
1831
pg_strcasecmp (prev_wd , "FROM" ) == 0 )
1781
- COMPLETE_WITH_SCHEMA_QUERY (Query_for_list_of_tables , NULL );
1832
+ COMPLETE_WITH_SCHEMA_QUERY (Query_for_list_of_deletables , NULL );
1782
1833
/* Complete DELETE FROM <table> */
1783
1834
else if (pg_strcasecmp (prev3_wd , "DELETE" ) == 0 &&
1784
1835
pg_strcasecmp (prev2_wd , "FROM" ) == 0 )
@@ -2066,7 +2117,7 @@ psql_completion(char *text, int start, int end)
2066
2117
/* Complete INSERT INTO with table names */
2067
2118
else if (pg_strcasecmp (prev2_wd , "INSERT" ) == 0 &&
2068
2119
pg_strcasecmp (prev_wd , "INTO" ) == 0 )
2069
- COMPLETE_WITH_SCHEMA_QUERY (Query_for_list_of_tables , NULL );
2120
+ COMPLETE_WITH_SCHEMA_QUERY (Query_for_list_of_insertables , NULL );
2070
2121
/* Complete "INSERT INTO <table> (" with attribute names */
2071
2122
else if (pg_strcasecmp (prev4_wd , "INSERT" ) == 0 &&
2072
2123
pg_strcasecmp (prev3_wd , "INTO" ) == 0 &&
@@ -2423,7 +2474,7 @@ psql_completion(char *text, int start, int end)
2423
2474
/* UPDATE */
2424
2475
/* If prev. word is UPDATE suggest a list of tables */
2425
2476
else if (pg_strcasecmp (prev_wd , "UPDATE" ) == 0 )
2426
- COMPLETE_WITH_SCHEMA_QUERY (Query_for_list_of_tables , NULL );
2477
+ COMPLETE_WITH_SCHEMA_QUERY (Query_for_list_of_updatables , NULL );
2427
2478
/* Complete UPDATE <table> with "SET" */
2428
2479
else if (pg_strcasecmp (prev2_wd , "UPDATE" ) == 0 )
2429
2480
COMPLETE_WITH_CONST ("SET" );
0 commit comments