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.43k stars 85 forks source link

Exactly what data does pspg receive from psql? #230

Closed velle closed 1 year ago

velle commented 1 year ago

Consider the following command:

$ psql -c "SELECT * FROM foo"
 gid | id |                                                                        geom                                                                        
-----+----+----------------------------------------------------------------------------------------------------------------------------------------------------
   1 |  1 | 01020000000400000000000000000024400000000000000000000000000000244000000000000049400000000000003440000000000000494000000000000034400000000000000000
   2 |  2 | 0102000000040000000000000000003E4000000000000000000000000000003E4000000000008051400000000000004940000000000080514000000000000049400000000000000000
(2 rows)

I can use pspg in two ways

Are they equivalent?

In both cases, does pgsg simply receive the output as a ascii-formatted table (using vertical pipe symbol, spaces and newlines)? Or does pspg receive the data in another format? Does the data received by pgps contain data (in addition to what I can see when printed directly to terminal), eg metadata such as datatype for each column that could hint how to format the data in the most user-friendly way?

I am asking about this in order to figure out, if I can customize pspg to do what I am trying to achieve :)

Sincerely

okbob commented 1 year ago

Hi

čt 13. 7. 2023 v 11:56 odesílatel velle @.***> napsal:

Consider the following command:

$ psql -c "SELECT * FROM foo" gid | id | geom -----+----+---------------------------------------------------------------------------------------------------------------------------------------------------- 1 | 1 | 01020000000400000000000000000024400000000000000000000000000000244000000000000049400000000000003440000000000000494000000000000034400000000000000000 2 | 2 | 0102000000040000000000000000003E4000000000000000000000000000003E4000000000008051400000000000004940000000000080514000000000000049400000000000000000 (2 rows)

I can use pspg in two ways

  • $ psql -c "SELECT * FROM cubetown.LS_c" | pspg
  • $ PAGER=pspg psql -c "SELECT * FROM cubetown.LS_c"

Are they equivalent?

yes, for pspg's perspective they are same

pspg can read csv too. So you can do

psql -c "SELECT .." --csv | pspg --csv

In both cases, does pgsg simply receive the output as a ascii-formatted table (using vertical pipe symbol, spaces and newlines)? Or does pspg receive the data in another format? Does the data received by pgps contain data (in addition to what I can see when printed directly to terminal), eg metadata such as datatype for each column that could hint how to format the data in the most user-friendly way?

The default format is just plain text - psql returns only a formatted table (in plain text) without metadata or any invisible data.

I am asking about this in order to figure out, if I can customize pspg to do what I am trying to achieve :)

pspg can work as a postgres client directly when pspg was compiled with libpq support.

pspg -d postgres -h localhost -q "select * from ..."

Sincerely

— Reply to this email directly, view it on GitHub https://github.com/okbob/pspg/issues/230, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAEFO43VEL5QVCTBGNWAHH3XP7A4VANCNFSM6AAAAAA2IWBTHI . You are receiving this because you are subscribed to this thread.Message ID: @.***>

The best input format (for pspg) is output of psql with settings

 \pset linestyle unicode
 \pset border 2
 \pset null ∅