Hi,

Magnus's patch for adding tab completion of views to the TABLE statement reminded me of a minor annoyance of mine -- that EXECUTE always completes with "PROCEDURE" as if it would have been part of CREATE TRIGGER ... EXECUTE even when it is the first word of the line.

Attached is a simple patch which adds completion of prepared statement names to the EXECUTE statement.

What could perhaps be added is that if you press tab again after completing the prepared statement name you might want to see a single "(" appear. Did not add that though since "EXECUTE foo();" is not valid syntax (while "EXECUTE foo(1);" is) and I did not feel the extra lines of code to add a query to check if the number of expected parameters is greater than 0 were worth it.

--
Andreas Karlsson
diff --git a/src/bin/psql/tab-complete.c b/src/bin/psql/tab-complete.c
new file mode 100644
index 4f7df36..15bb8c1
*** a/src/bin/psql/tab-complete.c
--- b/src/bin/psql/tab-complete.c
*************** static const SchemaQuery Query_for_list_
*** 588,593 ****
--- 588,598 ----
  "   FROM pg_catalog.pg_available_extensions "\
  "  WHERE substring(pg_catalog.quote_ident(name),1,%d)='%s' AND installed_version IS NULL"
  
+ #define Query_for_list_of_prepared_statements \
+ " SELECT pg_catalog.quote_ident(name) "\
+ "   FROM pg_catalog.pg_prepared_statements "\
+ "  WHERE substring(pg_catalog.quote_ident(name),1,%d)='%s'"
+ 
  /*
   * This is a list of all "things" in Pgsql, which can show up after CREATE or
   * DROP; and there is also a query to get a list of them.
*************** psql_completion(char *text, int start, i
*** 1642,1647 ****
--- 1647,1658 ----
  		COMPLETE_WITH_LIST(list_CSV);
  	}
  
+ /* EXECUTE */
+ 	else if (pg_strcasecmp(prev_wd, "EXECUTE") == 0 &&
+ 			 pg_strcasecmp(prev2_wd, "EXECUTE") == 0)
+ 		/* must not match CREATE TRIGGER ... EXECUTE PROCEDURE */
+ 	        COMPLETE_WITH_QUERY(Query_for_list_of_prepared_statements);
+ 
  	/* CREATE DATABASE */
  	else if (pg_strcasecmp(prev3_wd, "CREATE") == 0 &&
  			 pg_strcasecmp(prev2_wd, "DATABASE") == 0)
-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

Reply via email to