dbcli / pgcli

Postgres CLI with autocompletion and syntax highlighting
http://pgcli.com
BSD 3-Clause "New" or "Revised" License
12.08k stars 557 forks source link

Enhancement suggestion: inverted SELECT statements #1420

Open truthdoug opened 1 year ago

truthdoug commented 1 year ago

Description

I love the autocompletion of pgcli. I love that it does completion of the columns I'm selecting after I've added the FROM tablename to the query. So, I typically type select 1 from tablename and then go back to the 1 to choose the columns I want.

My crazy idea is that pgcli should be a trailblazer for a new SELECT syntax:

FROM tablename SELECT column1, column2 WHERE column1 is not null...

By putting the table name first, it creates the necessary context for completing column names. pgcli can then rearrange the order of the query before sending to the server.

Joins would work similarly:

FROM table1 t1 JOIN table2 t2 on t1.id = t2.t1_id SELECT t1.name, t2.name WHERE t1.type = 'foo'

I acknowledge that this is crazy and a non-trivial enhancement... but thought I'd float the idea.

radoslawklak commented 1 year ago

I have same idea in mycli project: https://github.com/dbcli/mycli/issues/1069#issue-1324291889