okbob / pspg

Unix pager (with very rich functionality) designed for work with tables. Designed for PostgreSQL, but MySQL is supported too. Works well with pgcli too. Can be used as CSV or TSV viewer too. It supports searching, selecting rows, columns, or block and export selected area to clipboard.
BSD 2-Clause "Simplified" License
2.48k stars 86 forks source link

Feature request: possibility for faster watch time #241

Closed Napam closed 7 months ago

Napam commented 7 months ago

Hi, thank you very much for pspg, it is a very nice and useful tool.

I see in the code that watch_time is an integer, which you multiply by 1000 to get seconds, meaning the fastest watch time I can get is 1 second. Would it be possible to use floats instead such one can say something like 0.5 seconds to achieve even faster watch times?

My use case is the following:

  1. I have an sql file which I have open in my editor, and I write sql in there :)
  2. I have a file watcher based on inotify (entr) which runs something like psql ...options.... -o --file sql_file.sql -o output when the file gets saved (this runs in the background)
  3. In the same time I have pspg watch the output file

Edit:

An arguably better thing for my case is to just watch the output file for changes, then reload when needed. Or even let it watch a sql file, and then pspg will execute and reload the output itself.

Edit 2: Correction: the file watcher I am using does have inotify support like pspg, but its kinda irrelevant for me as i am on a mac

okbob commented 7 months ago

pspg supports inotify by default - so when you change the file, then the pspg should to do refresh

I tested

pavel@nemesis:~/src/pspg-master/src$ psql -c "select * from pg_class" > ~/o.dat
pavel@nemesis:~/src/pspg-master/src$ psql -c "select * from pg_class limit 10" > ~/o.dat
pavel@nemesis:~/src/pspg-master/src$ psql -c "select * from pg_class limit 20" > ~/o.dat

and in separate terminal just pspg -f ~/o.dat and it is working

--watch option is necessary only when inotify API is not available or doesn't work

okbob commented 7 months ago

Maybe you should to look on https://github.com/okbob/pspg#streaming-modes

Napam commented 7 months ago

Oh ok! I guess you already had it covered. I am on an apple silicon mac, so unfortunately neither linux or inotify isn't easily available for me as far as I know :(

I tried using the streaming mode (not query stream), but it didn't behave that well in my case. Or rather, it behaved perfectly as it should for its use case (streaming). So it worked perfectly when I used psql interactively, but it didn't really work when doing what I did with using a file watcher (entr) which wrote to the output file.

As I understand it, query streams is for a the "REPL"-like behavior, correct? While I would rather just write some sql in a file, then execute it on save.

Napam commented 7 months ago

Also: after testing around more with my current setup with running the entr file watcher in the background and such made everything using curses (e.g. htop, pspg) really laggy and buggy during interaction (like scrolling up and down).

I guess this feature request isn't really that essential nor urgent for me after all as I have other way worse issues 😅 .

okbob commented 7 months ago

pspg should to support KQUEUE, that is used by MacOS too. Unfortunately, Apple is strange - see, all reported issues are related to Apple. It is compatible just with self. And I have not this comp, so I cannot to test all special behaviour. I tested pspg against FreeBSD, but some API on Apple are legacy or modified and in some details works differently.

Napam commented 7 months ago

Ah I see, thats very unfortunate. Anyways, thank you very much for your support and quick response! I'll mark this issue as closed.

Except for my little problem, the programs works very well on my mac.