Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

csv format disables PAGER setting altogether #516

Open
suimong opened this issue Mar 12, 2025 · 12 comments
Open

csv format disables PAGER setting altogether #516

suimong opened this issue Mar 12, 2025 · 12 comments

Comments

@suimong
Copy link

suimong commented Mar 12, 2025

Not sure if this is a bug report or feature request. When i set the output format to csv, whether through \pset format csv or through usql --csv, the output will not be piped in to the pager, even if i \pset pager always. My use case is to use visidata as the pager to navigate the query result.

Thanks for this wonderful project.

@kenshaw
Copy link
Member

kenshaw commented Mar 12, 2025

How are you piping it to visidata? By setting $PAGER? or ...?

@kenshaw
Copy link
Member

kenshaw commented Mar 12, 2025

@suimong This worked as expected for me:

$ usql -c 'select "blah";' --csv --no-rc ~/x.sqlite3 |visidata

Can you elaborate more on the version of usql you're using, what platform, terminal, etc., please?

@kenshaw
Copy link
Member

kenshaw commented Mar 12, 2025

BTW -- this is probably a better test example to work with:

$ usql -c '\d' --csv --no-rc ~/x.sqlite3 |visidata

This is what it looks like in my terminal:

Image

@suimong
Copy link
Author

suimong commented Mar 12, 2025

@kenshaw sorry for not stating the problem clearly. Directly piping the result into visidata works perfectly, I usually do \g | visidata. Then I realized that with the default format (aligned), the result of \g is directly piped into a pager specified by PAGER env var. But when I \pset format csv (or any other format, e.g. "unaligned", "csv", "html", "json"), the result of \g directly goes on the screen, not into the pager.

@kenshaw
Copy link
Member

kenshaw commented Mar 12, 2025

Were you aware you could do this?

sq:x.sqlite3=> select "blah" \g | visidata

The schema info commands (\d) don't get piped into $PAGER.

@suimong
Copy link
Author

suimong commented Mar 12, 2025

I'm using usql 0.19.15 on NixOS 24.11. The terminal is alacritty

@kenshaw
Copy link
Member

kenshaw commented Mar 12, 2025

Also, sorry, this also works:

sq:x.sqlite3=>select "blah" \gx (format=csv) | visidata

Any of the \pset variables can be set in this fashion:

sq:x.sqlite3=> select "blah" \g (border=2 footer=off)
+--------+
| "blah" |
+--------+
| blah   |
+--------+

@suimong
Copy link
Author

suimong commented Mar 12, 2025

Also, sorry, this also works:

sq:x.sqlite3=>select "blah" \gx (format=csv) | visidata

Any of the \pset variables can be set in this fashion:

sq:x.sqlite3=> select "blah" \g (border=2 footer=off)
+--------+
| "blah" |
+--------+
| blah |
+--------+

Yes, I know I can explicitly pipe query results into whatever CLI program of my choice. What I'm talking about is implicitly use the PAGER program to view the result, so that to save me some keystrokes on every invocation of \g. Currently, this only works when format is set to "aligned". To be more explicit, \g (format=aligned) will open the PAGER program with the result, and this is a desirable behavior, and I hope such behavior can be enabled for other formats as well.

@suimong
Copy link
Author

suimong commented Mar 12, 2025

Also, thanks for letting me know the \g (OPTION_KEY=VAL) syntax. I'm quite new to usql and couldn't figure that out from the documentation.

@kenshaw
Copy link
Member

kenshaw commented Mar 12, 2025

@suimong The syntax is all taken from psql -- read this page and usql supports basically all of the query stuff. Much of usql's help (ie, \?) was stolen from inspired by psql's own.

@kenshaw
Copy link
Member

kenshaw commented Mar 12, 2025

I'll check/look to see if the $PAGER variable isn't working properly.

@suimong
Copy link
Author

suimong commented Mar 12, 2025

@suimong The syntax is all taken from psql -- read this page and usql supports basically all of the query stuff. Much of usql's help (ie, \?) was stolen from inspired by psql's own.

Thanks for the pointer!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants