TABLE tab completion

Started by Magnus Haganderover 14 years ago5 messages
#1Magnus Hagander
magnus@hagander.net
1 attachment(s)

TABLE tab completion in psql only completes to tables, not views. but
the TABLE command works fine for both tables and views (and also
sequences).

Seems we should just complete it to relations and not tables - or can
anyone see a particular reason why we shouldn't?

Trivial patch attached.

--
 Magnus Hagander
 Me: http://www.hagander.net/
 Work: http://www.redpill-linpro.com/

Attachments:

table_complete.patchtext/x-patch; charset=US-ASCII; name=table_complete.patchDownload
diff --git a/src/bin/psql/tab-complete.c b/src/bin/psql/tab-complete.c
index 4f7df36..8515c38 100644
--- a/src/bin/psql/tab-complete.c
+++ b/src/bin/psql/tab-complete.c
@@ -636,7 +636,7 @@ static const pgsql_thing_t words_after_create[] = {
 	{"SCHEMA", Query_for_list_of_schemas},
 	{"SEQUENCE", NULL, &Query_for_list_of_sequences},
 	{"SERVER", Query_for_list_of_servers},
-	{"TABLE", NULL, &Query_for_list_of_tables},
+	{"TABLE", NULL, &Query_for_list_of_relations},
 	{"TABLESPACE", Query_for_list_of_tablespaces},
 	{"TEMP", NULL, NULL, THING_NO_DROP},		/* for CREATE TEMP TABLE ... */
 	{"TEMPLATE", Query_for_list_of_ts_templates, NULL, THING_NO_SHOW},
#2Dean Rasheed
dean.a.rasheed@gmail.com
In reply to: Magnus Hagander (#1)
Re: TABLE tab completion

On 24 September 2011 11:59, Magnus Hagander <magnus@hagander.net> wrote:

TABLE tab completion in psql only completes to tables, not views. but
the TABLE command works fine for both tables and views (and also
sequences).

Seems we should just complete it to relations and not tables - or can
anyone see a particular reason why we shouldn't?

Doesn't that mean that "DROP TABLE <tab>" would offer up views as well
as tables, which would be incorrect?

Regards,
Dean

#3Magnus Hagander
magnus@hagander.net
In reply to: Dean Rasheed (#2)
1 attachment(s)
Re: TABLE tab completion

On Sun, Sep 25, 2011 at 15:06, Dean Rasheed <dean.a.rasheed@gmail.com> wrote:

On 24 September 2011 11:59, Magnus Hagander <magnus@hagander.net> wrote:

TABLE tab completion in psql only completes to tables, not views. but
the TABLE command works fine for both tables and views (and also
sequences).

Seems we should just complete it to relations and not tables - or can
anyone see a particular reason why we shouldn't?

Doesn't that mean that "DROP TABLE <tab>" would offer up views as well
as tables, which would be incorrect?

Meh - you are correct, of course. I guess that's why we have code review :-)

So - not a oneliner, but how about something like this?

(Happy to have someone point out a neater way of doing it, not
entirely fluent in how we do the tab completion..)

--
 Magnus Hagander
 Me: http://www.hagander.net/
 Work: http://www.redpill-linpro.com/

Attachments:

psql_table.patchtext/x-patch; charset=US-ASCII; name=psql_table.patchDownload
diff --git a/src/bin/psql/tab-complete.c b/src/bin/psql/tab-complete.c
index 4f7df36..0e2f524 100644
--- a/src/bin/psql/tab-complete.c
+++ b/src/bin/psql/tab-complete.c
@@ -2648,6 +2648,12 @@ psql_completion(char *text, int start, int end)
 	else if (pg_strcasecmp(prev_wd, "START") == 0)
 		COMPLETE_WITH_CONST("TRANSACTION");
 
+/* TABLE */
+	else if (pg_strcasecmp(prev_wd, "TABLE") == 0 &&
+			 pg_strcasecmp(prev2_wd, "TABLE") == 0)
+		/* must not match DROP TABLE etc */
+		COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_relations, NULL);
+
 /* TRUNCATE */
 	else if (pg_strcasecmp(prev_wd, "TRUNCATE") == 0)
 		COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_tables, NULL);
#4David Fetter
david@fetter.org
In reply to: Magnus Hagander (#3)
Re: TABLE tab completion

On Mon, Sep 26, 2011 at 10:37:50AM +0200, Magnus Hagander wrote:

On Sun, Sep 25, 2011 at 15:06, Dean Rasheed <dean.a.rasheed@gmail.com> wrote:

On 24 September 2011 11:59, Magnus Hagander <magnus@hagander.net> wrote:

TABLE tab completion in psql only completes to tables, not views. but
the TABLE command works fine for both tables and views (and also
sequences).

Seems we should just complete it to relations and not tables - or can
anyone see a particular reason why we shouldn't?

Doesn't that mean that "DROP TABLE <tab>" would offer up views as well
as tables, which would be incorrect?

Meh - you are correct, of course. I guess that's why we have code review :-)

So - not a oneliner, but how about something like this?

(Happy to have someone point out a neater way of doing it, not
entirely fluent in how we do the tab completion..)

That's pretty much it. Should it also (eventually) do SRFs?

Cheers,
David.
--
David Fetter <david@fetter.org> http://fetter.org/
Phone: +1 415 235 3778 AIM: dfetter666 Yahoo!: dfetter
Skype: davidfetter XMPP: david.fetter@gmail.com
iCal: webcal://www.tripit.com/feed/ical/people/david74/tripit.ics

Remember to vote!
Consider donating to Postgres: http://www.postgresql.org/about/donate

#5Magnus Hagander
magnus@hagander.net
In reply to: Magnus Hagander (#3)
Re: TABLE tab completion

On Mon, Sep 26, 2011 at 10:37, Magnus Hagander <magnus@hagander.net> wrote:

On Sun, Sep 25, 2011 at 15:06, Dean Rasheed <dean.a.rasheed@gmail.com> wrote:

On 24 September 2011 11:59, Magnus Hagander <magnus@hagander.net> wrote:

TABLE tab completion in psql only completes to tables, not views. but
the TABLE command works fine for both tables and views (and also
sequences).

Seems we should just complete it to relations and not tables - or can
anyone see a particular reason why we shouldn't?

Doesn't that mean that "DROP TABLE <tab>" would offer up views as well
as tables, which would be incorrect?

Meh - you are correct, of course. I guess that's why we have code review :-)

So - not a oneliner, but how about something like this?

(Happy to have someone point out a neater way of doing it, not
entirely fluent in how we do the tab completion..)

Rebased on top of the changes Tom made to the infrastructure, and applied.

--
 Magnus Hagander
 Me: http://www.hagander.net/
 Work: http://www.redpill-linpro.com/