psql suggestion "select <tab>" offers nothing, can we get functions like "\df <tab>"

Started by Kirk Wolak9 months ago6 messages
#1Kirk Wolak
wolakk@gmail.com

Hackers,
"call <tab>" works. Obviously it was a trivial case.

But "select <tab>" does nothing.

Worse, "select pg_stat_st<tab>" has no clue. I was looking for ... _reset

It's not that difficult to add, I am suggesting that we use the same
logic as \df at that point?

Is there any such support for this?
Is it bad form to offer a bounty for someone to do this in this list? (I
simply won't have time for 2-3 months).

Thanks!

#2Tom Lane
tgl@sss.pgh.pa.us
In reply to: Kirk Wolak (#1)
Re: psql suggestion "select <tab>" offers nothing, can we get functions like "\df <tab>"

Kirk Wolak <wolakk@gmail.com> writes:

But "select <tab>" does nothing.

What would you have it offer? Every single column and function name
in the database? Seems unlikely to be very helpful.

postgres=# select count(distinct attname) from pg_attribute;
count
-------
1218
(1 row)

postgres=# select count(distinct proname) from pg_proc;
count
-------
2787
(1 row)

That's with zero user-defined objects.

regards, tom lane

#3Pavel Stehule
pavel.stehule@gmail.com
In reply to: Tom Lane (#2)
Re: psql suggestion "select <tab>" offers nothing, can we get functions like "\df <tab>"

Hi

čt 3. 4. 2025 v 20:17 odesílatel Tom Lane <tgl@sss.pgh.pa.us> napsal:

Kirk Wolak <wolakk@gmail.com> writes:

But "select <tab>" does nothing.

What would you have it offer? Every single column and function name
in the database? Seems unlikely to be very helpful.

postgres=# select count(distinct attname) from pg_attribute;
count
-------
1218
(1 row)

postgres=# select count(distinct proname) from pg_proc;
count
-------
2787
(1 row)

That's with zero user-defined objects.

you can try https://www.pgcli.com/

the tab complete there is better (or different) than in psql. I don't use
it, but I know people who use it well.

I agree so tab complete for functions can be nice feature. It is a question
if it can work with readline. At the end it is always faster for me to
write \df *reset*, and using mouse for copy

Regards

Pavel

Show quoted text

regards, tom lane

#4Kirill Reshke
reshkekirill@gmail.com
In reply to: Kirk Wolak (#1)
Re: psql suggestion "select <tab>" offers nothing, can we get functions like "\df <tab>"

On Thu, 3 Apr 2025 at 20:07, Kirk Wolak <wolakk@gmail.com> wrote:

Worse, "select pg_stat_st<tab>" has no clue. I was looking for ... _reset

It's not that difficult to add, I am suggesting that we use the same logic as \df at that point?

Is not so simple here, because we have to try to complete this query
with all attributes and functions, and there can be just too many
different attname in the database. For example, with 100.000 tables
you probably should wait for more than one second for a psql
background query to complete (and you cannot cancel it too!). So this
is very questionable if this feature is worth it.

--
Best regards,
Kirill Reshke

#5Kirill Reshke
reshkekirill@gmail.com
In reply to: Kirill Reshke (#4)
Re: psql suggestion "select <tab>" offers nothing, can we get functions like "\df <tab>"

On Fri, 4 Apr 2025, 16:41 Kirill Reshke, <reshkekirill@gmail.com> wrote:

On Thu, 3 Apr 2025 at 20:07, Kirk Wolak <wolakk@gmail.com> wrote:

Worse, "select pg_stat_st<tab>" has no clue. I was looking for ...

_reset

It's not that difficult to add, I am suggesting that we use the same

logic as \df at that point?

Is not so simple here, because we have to try to complete this query
with all attributes and functions, and there can be just too many
different attname in the database. For example, with 100.000 tables
you probably should wait for more than one second for a psql
background query to complete (and you cannot cancel it too!). So this
is very questionable if this feature is worth it.

--
Best regards,
Kirill Reshke

Maybe we can tab-complete here if prefix matches pg_% ? Does that makes
good use case?

Show quoted text
#6Greg Sabino Mullane
htamfids@gmail.com
In reply to: Kirill Reshke (#5)
Re: psql suggestion "select <tab>" offers nothing, can we get functions like "\df <tab>"

On Mon, Apr 7, 2025 at 12:55 PM Kirill Reshke <reshkekirill@gmail.com>
wrote:

Maybe we can tab-complete here if prefix matches pg_% ? Does that makes
good use case?

I think you will have to get much more specific than pg_ before tab
completion makes sense. You are still looking at hundreds of answers. The
example upthread could benefit from tab completion (pg_stat_st<TAB>) but
where does one programmatically draw the line? (digs around). Looks like
pg_<single-letter><TAB> could be useful - while pg_s has ~ 150 entries,
everything else is doable:

greg=# with alpha as (select chr(x) from generate_series(97,122) x)
select chr, count(*) from pg_proc, alpha where proname ~ ('pg_'||chr) group
by 1 order by 1;
chr | count
-----+-------
a | 17
b | 15
c | 43
d | 14
e | 11
f | 4
g | 41
h | 7
i | 18
j | 1
k | 4
l | 46
m | 6
n | 14
o | 4
p | 9
q | 5
r | 35
s | 150
t | 38
v | 6
w | 6
x | 3

--
Cheers,
Greg

--
Crunchy Data - https://www.crunchydata.com
Enterprise Postgres Software Products & Tech Support