Thread: psql: \pset pager 'always'?
I don't know if this is already done, but... I'm really annoyed by that little 'feature' of psql that decides whether to use pager or not. I personally use GNU 'less' with options -S -F as my pager, which allows me to scroll vertically AS WELL AS horizontally on long input. So a "use pager always" option with no strange automagic behaviour would be nice. Or do you consider this being readable (copyed verbatim from terminal window): template1=# select * from pg_class limit 1; relname | reltype | relowner | relam | relfilenode | relpages | reltuples | reltoastrelid | reltoastidxid | relhasindex | relisshared | relkind | relnatts | relchecks | reltriggers | relukeys | relfkeys | relrefs | relhasoids | relhaspkey | relhasrules | relhassubclass | relacl ----------------------+---------+----------+-------+-------------+----------+-----------+---------------+---------------+-------------+-------------+---------+----------+-----------+-------------+----------+----------+---------+------------+------------+- ------------+----------------+-------- pg_type | 71 | 1 | 0 | 1247 | 2 | 143 | 0 | 0 | t | f | r | 17 | 0 | 0 | 0 | 0 | 0 | t Until that I need to avoid queries with too _few_ resulting rows in psql. ;-) (select * from pg_class works brilliantly). -- Antti Haapala
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 NotDashEscaped: You need GnuPG to verify this message > I'm really annoyed by that little 'feature' of psql that decides whether > to use pager or not. I personally use GNU 'less' with options -S -F as my > pager, which allows me to scroll vertically AS WELL AS horizontally on > long input. So a "use pager always" option with no strange automagic > behaviour would be nice. Not a bad idea. Here is a patch that does just that, while maintaining the "traditional" behavior, so the change should be transparent. Use the command "\pset pager always" to turn it on. Anything else does the normal toggle between "on" and "off" Greg Sabino Mullane greg@turnstep.com PGP Key: 0x14964AC8 200209111525 Index: command.c =================================================================== RCS file: /projects/cvsroot/pgsql-server/src/bin/psql/command.c,v retrieving revision 1.80 diff -c -r1.80 command.c *** command.c 2002/09/04 20:31:35 1.80 --- command.c 2002/09/11 19:24:41 *************** *** 1867,1877 **** /* toggle use of pager */ else if (strcmp(param, "pager") == 0) { ! popt->topt.pager = !popt->topt.pager; if (!quiet) { ! if (popt->topt.pager) puts(gettext("Using pager is on.")); else puts(gettext("Using pager is off.")); } --- 1867,1884 ---- /* toggle use of pager */ else if (strcmp(param, "pager") == 0) { ! if (strcasecmp(value, "always") == 0) ! popt->topt.pager = 2; ! else if (popt->topt.pager == 1) ! popt->topt.pager = 0; ! else ! popt->topt.pager = 1; if (!quiet) { ! if (popt->topt.pager == 1) puts(gettext("Using pager is on.")); + else if (popt->topt.pager == 2) + puts(gettext("Using pager is always.")); else puts(gettext("Using pager is off.")); } Index: help.c =================================================================== RCS file: /projects/cvsroot/pgsql-server/src/bin/psql/help.c,v retrieving revision 1.56 diff -c -r1.56 help.c *** help.c 2002/09/04 20:31:35 1.56 --- help.c 2002/09/11 19:24:41 *************** *** 159,165 **** #endif void ! slashUsage(bool pager) { FILE *output, *pagerfd = NULL; --- 159,165 ---- #endif void ! slashUsage(unsigned small int pager) { FILE *output, *pagerfd = NULL; *************** *** 180,186 **** struct winsize screen_size; result = ioctl(fileno(stdout), TIOCGWINSZ, &screen_size); ! if (result == -1 || 50 > screen_size.ws_row) { #endif pagerprog = getenv("PAGER"); --- 180,186 ---- struct winsize screen_size; result = ioctl(fileno(stdout), TIOCGWINSZ, &screen_size); ! if (result == -1 || 50 > screen_size.ws_row || pager == 2) { #endif pagerprog = getenv("PAGER"); Index: help.h =================================================================== RCS file: /projects/cvsroot/pgsql-server/src/bin/psql/help.h,v retrieving revision 1.9 diff -c -r1.9 help.h *** help.h 2002/07/15 01:56:25 1.9 --- help.h 2002/09/11 19:24:41 *************** *** 10,16 **** void usage(void); ! void slashUsage(bool pager); void helpSQL(const char *topic); --- 10,16 ---- void usage(void); ! void slashUsage(unsigned small int pager); void helpSQL(const char *topic); Index: print.c =================================================================== RCS file: /projects/cvsroot/pgsql-server/src/bin/psql/print.c,v retrieving revision 1.31 diff -c -r1.31 print.c *** print.c 2002/09/01 23:30:46 1.31 --- print.c 2002/09/11 19:24:41 *************** *** 1022,1028 **** lines++; result = ioctl(fileno(stdout), TIOCGWINSZ, &screen_size); ! if (result == -1 || lines > screen_size.ws_row) { #endif pagerprog = getenv("PAGER"); --- 1022,1028 ---- lines++; result = ioctl(fileno(stdout), TIOCGWINSZ, &screen_size); ! if (result == -1 || lines > screen_size.ws_row || opt->pager == 2) { #endif pagerprog = getenv("PAGER"); Index: print.h =================================================================== RCS file: /projects/cvsroot/pgsql-server/src/bin/psql/print.h,v retrieving revision 1.14 diff -c -r1.14 print.h *** print.h 2002/09/04 20:31:36 1.14 --- print.h 2002/09/11 19:24:41 *************** *** 26,33 **** enum printFormat format; /* one of the above */ bool expanded; /* expanded/vertical output (if supported * by output format) */ ! bool pager; /* use pager for output (if to stdout and ! * stdout is a tty) */ bool tuples_only; /* don't output headers, row counts, etc. */ unsigned short int border; /* Print a border around the table. * 0=none, 1=dividing lines, 2=full */ --- 26,34 ---- enum printFormat format; /* one of the above */ bool expanded; /* expanded/vertical output (if supported * by output format) */ ! unsigned short int pager; /* use pager for output (if to stdout and ! * stdout is a tty) ! * 0=off 1=on 2=always */ bool tuples_only; /* don't output headers, row counts, etc. */ unsigned short int border; /* Print a border around the table. * 0=none, 1=dividing lines, 2=full */ Index: startup.c =================================================================== RCS file: /projects/cvsroot/pgsql-server/src/bin/psql/startup.c,v retrieving revision 1.66 diff -c -r1.66 startup.c *** startup.c 2002/09/06 02:33:47 1.66 --- startup.c 2002/09/11 19:24:41 *************** *** 137,143 **** pset.popt.topt.format = PRINT_ALIGNED; pset.queryFout = stdout; pset.popt.topt.border = 1; ! pset.popt.topt.pager = true; pset.popt.default_footer = true; SetVariable(pset.vars, "VERSION", PG_VERSION_STR); --- 137,143 ---- pset.popt.topt.format = PRINT_ALIGNED; pset.queryFout = stdout; pset.popt.topt.border = 1; ! pset.popt.topt.pager = 1; pset.popt.default_footer = true; SetVariable(pset.vars, "VERSION", PG_VERSION_STR); -----BEGIN PGP SIGNATURE----- Comment: http://www.turnstep.com/pgp.html iD8DBQE9f5klvJuQZxSWSsgRAuFGAJwNsHiudvGq+Xq8WpQO4bSrd+QUtwCgo1lB iolPoprltuDfsb4YSjAHHs4= =5Kt2 -----END PGP SIGNATURE-----
This has been saved for the 7.4 release: http://candle.pha.pa.us/cgi-bin/pgpatches2 --------------------------------------------------------------------------- greg@turnstep.com wrote: [ There is text before PGP section. ] > [ PGP not available, raw data follows ] > -----BEGIN PGP SIGNED MESSAGE----- > Hash: SHA1 > NotDashEscaped: You need GnuPG to verify this message > > > > I'm really annoyed by that little 'feature' of psql that decides whether > > to use pager or not. I personally use GNU 'less' with options -S -F as my > > pager, which allows me to scroll vertically AS WELL AS horizontally on > > long input. So a "use pager always" option with no strange automagic > > behaviour would be nice. > > Not a bad idea. Here is a patch that does just that, while maintaining the > "traditional" behavior, so the change should be transparent. Use the > command "\pset pager always" to turn it on. Anything else does the > normal toggle between "on" and "off" > > > Greg Sabino Mullane greg@turnstep.com > PGP Key: 0x14964AC8 200209111525 > > > Index: command.c > =================================================================== > RCS file: /projects/cvsroot/pgsql-server/src/bin/psql/command.c,v > retrieving revision 1.80 > diff -c -r1.80 command.c > *** command.c 2002/09/04 20:31:35 1.80 > --- command.c 2002/09/11 19:24:41 > *************** > *** 1867,1877 **** > /* toggle use of pager */ > else if (strcmp(param, "pager") == 0) > { > ! popt->topt.pager = !popt->topt.pager; > if (!quiet) > { > ! if (popt->topt.pager) > puts(gettext("Using pager is on.")); > else > puts(gettext("Using pager is off.")); > } > --- 1867,1884 ---- > /* toggle use of pager */ > else if (strcmp(param, "pager") == 0) > { > ! if (strcasecmp(value, "always") == 0) > ! popt->topt.pager = 2; > ! else if (popt->topt.pager == 1) > ! popt->topt.pager = 0; > ! else > ! popt->topt.pager = 1; > if (!quiet) > { > ! if (popt->topt.pager == 1) > puts(gettext("Using pager is on.")); > + else if (popt->topt.pager == 2) > + puts(gettext("Using pager is always.")); > else > puts(gettext("Using pager is off.")); > } > Index: help.c > =================================================================== > RCS file: /projects/cvsroot/pgsql-server/src/bin/psql/help.c,v > retrieving revision 1.56 > diff -c -r1.56 help.c > *** help.c 2002/09/04 20:31:35 1.56 > --- help.c 2002/09/11 19:24:41 > *************** > *** 159,165 **** > #endif > > void > ! slashUsage(bool pager) > { > FILE *output, > *pagerfd = NULL; > --- 159,165 ---- > #endif > > void > ! slashUsage(unsigned small int pager) > { > FILE *output, > *pagerfd = NULL; > *************** > *** 180,186 **** > struct winsize screen_size; > > result = ioctl(fileno(stdout), TIOCGWINSZ, &screen_size); > ! if (result == -1 || 50 > screen_size.ws_row) > { > #endif > pagerprog = getenv("PAGER"); > --- 180,186 ---- > struct winsize screen_size; > > result = ioctl(fileno(stdout), TIOCGWINSZ, &screen_size); > ! if (result == -1 || 50 > screen_size.ws_row || pager == 2) > { > #endif > pagerprog = getenv("PAGER"); > Index: help.h > =================================================================== > RCS file: /projects/cvsroot/pgsql-server/src/bin/psql/help.h,v > retrieving revision 1.9 > diff -c -r1.9 help.h > *** help.h 2002/07/15 01:56:25 1.9 > --- help.h 2002/09/11 19:24:41 > *************** > *** 10,16 **** > > void usage(void); > > ! void slashUsage(bool pager); > > void helpSQL(const char *topic); > > --- 10,16 ---- > > void usage(void); > > ! void slashUsage(unsigned small int pager); > > void helpSQL(const char *topic); > > Index: print.c > =================================================================== > RCS file: /projects/cvsroot/pgsql-server/src/bin/psql/print.c,v > retrieving revision 1.31 > diff -c -r1.31 print.c > *** print.c 2002/09/01 23:30:46 1.31 > --- print.c 2002/09/11 19:24:41 > *************** > *** 1022,1028 **** > lines++; > > result = ioctl(fileno(stdout), TIOCGWINSZ, &screen_size); > ! if (result == -1 || lines > screen_size.ws_row) > { > #endif > pagerprog = getenv("PAGER"); > --- 1022,1028 ---- > lines++; > > result = ioctl(fileno(stdout), TIOCGWINSZ, &screen_size); > ! if (result == -1 || lines > screen_size.ws_row || opt->pager == 2) > { > #endif > pagerprog = getenv("PAGER"); > Index: print.h > =================================================================== > RCS file: /projects/cvsroot/pgsql-server/src/bin/psql/print.h,v > retrieving revision 1.14 > diff -c -r1.14 print.h > *** print.h 2002/09/04 20:31:36 1.14 > --- print.h 2002/09/11 19:24:41 > *************** > *** 26,33 **** > enum printFormat format; /* one of the above */ > bool expanded; /* expanded/vertical output (if supported > * by output format) */ > ! bool pager; /* use pager for output (if to stdout and > ! * stdout is a tty) */ > bool tuples_only; /* don't output headers, row counts, etc. */ > unsigned short int border; /* Print a border around the table. > * 0=none, 1=dividing lines, 2=full */ > --- 26,34 ---- > enum printFormat format; /* one of the above */ > bool expanded; /* expanded/vertical output (if supported > * by output format) */ > ! unsigned short int pager; /* use pager for output (if to stdout and > ! * stdout is a tty) > ! * 0=off 1=on 2=always */ > bool tuples_only; /* don't output headers, row counts, etc. */ > unsigned short int border; /* Print a border around the table. > * 0=none, 1=dividing lines, 2=full */ > Index: startup.c > =================================================================== > RCS file: /projects/cvsroot/pgsql-server/src/bin/psql/startup.c,v > retrieving revision 1.66 > diff -c -r1.66 startup.c > *** startup.c 2002/09/06 02:33:47 1.66 > --- startup.c 2002/09/11 19:24:41 > *************** > *** 137,143 **** > pset.popt.topt.format = PRINT_ALIGNED; > pset.queryFout = stdout; > pset.popt.topt.border = 1; > ! pset.popt.topt.pager = true; > pset.popt.default_footer = true; > > SetVariable(pset.vars, "VERSION", PG_VERSION_STR); > --- 137,143 ---- > pset.popt.topt.format = PRINT_ALIGNED; > pset.queryFout = stdout; > pset.popt.topt.border = 1; > ! pset.popt.topt.pager = 1; > pset.popt.default_footer = true; > > SetVariable(pset.vars, "VERSION", PG_VERSION_STR); > > -----BEGIN PGP SIGNATURE----- > Comment: http://www.turnstep.com/pgp.html > > iD8DBQE9f5klvJuQZxSWSsgRAuFGAJwNsHiudvGq+Xq8WpQO4bSrd+QUtwCgo1lB > iolPoprltuDfsb4YSjAHHs4= > =5Kt2 > -----END PGP SIGNATURE----- > > > > ---------------------------(end of broadcast)--------------------------- > TIP 6: Have you searched our list archives? > > http://archives.postgresql.org > [ Decrypting message... End of raw data. ] -- Bruce Momjian | http://candle.pha.pa.us pgman@candle.pha.pa.us | (610) 359-1001 + If your life is a hard drive, | 13 Roberts Road + Christ can be your backup. | Newtown Square, Pennsylvania 19073
antti.haapala@iki.fi (Antti Haapala) writes: > I don't know if this is already done, but... > > I'm really annoyed by that little 'feature' of psql that decides whether > to use pager or not. I personally use GNU 'less' with options -S -F as my > pager, which allows me to scroll vertically AS WELL AS horizontally on > long input. So a "use pager always" option with no strange automagic > behaviour would be nice. Or do you consider this being readable (copyed > verbatim from terminal window): Yes, I'd like to second that. My ugly workaround when I need to have less invoked (so I can scroll sideways) and the result set it small (in rows), I make my window very small (vertically), run the query, then stretch it out again. - Justin -- Justin Hawkins Internode Professional Access
On Thu, Sep 12, 2002 at 10:20:45AM +0930, Justin Hawkins wrote: > antti.haapala@iki.fi (Antti Haapala) writes: > > > I don't know if this is already done, but... > > > > I'm really annoyed by that little 'feature' of psql that decides whether > > to use pager or not. I personally use GNU 'less' with options -S -F as my > > pager, which allows me to scroll vertically AS WELL AS horizontally on > > long input. So a "use pager always" option with no strange automagic > > behaviour would be nice. Or do you consider this being readable (copyed > > verbatim from terminal window): > > Yes, I'd like to second that. > > My ugly workaround when I need to have less invoked (so I can scroll > sideways) and the result set it small (in rows), I make my window very > small (vertically), run the query, then stretch it out again. Remember, you can always use \g like this: select * from table \g |less -S Maybe not neat, but very effective. -- Martijn van Oosterhout <kleptog@svana.org> http://svana.org/kleptog/ > There are 10 kinds of people in the world, those that can do binary > arithmetic and those that can't.
Can someone supply a patch to automatically invoke the pager if the output width is greater than the screen? We already test for screen rows but not for screen width. --------------------------------------------------------------------------- Martijn van Oosterhout wrote: > On Thu, Sep 12, 2002 at 10:20:45AM +0930, Justin Hawkins wrote: > > antti.haapala@iki.fi (Antti Haapala) writes: > > > > > I don't know if this is already done, but... > > > > > > I'm really annoyed by that little 'feature' of psql that decides whether > > > to use pager or not. I personally use GNU 'less' with options -S -F as my > > > pager, which allows me to scroll vertically AS WELL AS horizontally on > > > long input. So a "use pager always" option with no strange automagic > > > behaviour would be nice. Or do you consider this being readable (copyed > > > verbatim from terminal window): > > > > Yes, I'd like to second that. > > > > My ugly workaround when I need to have less invoked (so I can scroll > > sideways) and the result set it small (in rows), I make my window very > > small (vertically), run the query, then stretch it out again. > > Remember, you can always use \g like this: > > select * from table \g |less -S > > Maybe not neat, but very effective. > -- > Martijn van Oosterhout <kleptog@svana.org> http://svana.org/kleptog/ > > There are 10 kinds of people in the world, those that can do binary > > arithmetic and those that can't. > > ---------------------------(end of broadcast)--------------------------- > TIP 6: Have you searched our list archives? > > http://archives.postgresql.org > -- Bruce Momjian | http://candle.pha.pa.us pgman@candle.pha.pa.us | (610) 359-1001 + If your life is a hard drive, | 13 Roberts Road + Christ can be your backup. | Newtown Square, Pennsylvania 19073
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 > Can someone supply a patch to automatically invoke the pager if the > output width is greater than the screen? We already test for screen > rows but not for screen width. Easily done, but I am not sure that this is the right thing to do. A pager is designed to handle excess vertical input, but not all can handle excess horizontal input (the width). I suspect that doing so would not be a good idea for the same reason given to me when I asked "why not send everything to the pager?": some systems force you to specifically exit the pager; this can be real annoying for cases with small input. Greg Sabino Mullane greg@turnstep.com PGP Key: 0x14964AC8 200209180926 -----BEGIN PGP SIGNATURE----- iD8DBQE9iID8vJuQZxSWSsgRAk2mAKDRRopF9H7PMW18+qq5WgPHRiga/QCcCG2e G/ZxYw5fqwGxov9hVd+mhV0= =9nqS -----END PGP SIGNATURE-----
On Wed, Sep 18, 2002 at 01:40:42PM -0000, greg@turnstep.com wrote: > > -----BEGIN PGP SIGNED MESSAGE----- > Hash: SHA1 > > > > Can someone supply a patch to automatically invoke the pager if the > > output width is greater than the screen? We already test for screen > > rows but not for screen width. > > Easily done, but I am not sure that this is the right thing to do. > A pager is designed to handle excess vertical input, but not all > can handle excess horizontal input (the width). I suspect that doing > so would not be a good idea for the same reason given to me when I > asked "why not send everything to the pager?": some systems force you > to specifically exit the pager; this can be real annoying for cases > with small input. While this is true, if you do a select whose output wraps because it is too wide, getting it to go through "less -S" is extremely useful to have the columns line up. OTOH, sending everything to the pager is annoying if the result is only one value. I'd be happy with an easier way to force the pager than "\g |less -S". Perhaps if \g is specified without a filename, it defaults to the pager. Would such a patch be accepted? -- Martijn van Oosterhout <kleptog@svana.org> http://svana.org/kleptog/ > There are 10 kinds of people in the world, those that can do binary > arithmetic and those that can't.
There is a patch at: http://candle.pha.pa.us/cgi-bin/pgpatches2 which will allow you to turn on the pager always. This is for 7.4. --------------------------------------------------------------------------- Martijn van Oosterhout wrote: > On Wed, Sep 18, 2002 at 01:40:42PM -0000, greg@turnstep.com wrote: > > > > -----BEGIN PGP SIGNED MESSAGE----- > > Hash: SHA1 > > > > > > > Can someone supply a patch to automatically invoke the pager if the > > > output width is greater than the screen? We already test for screen > > > rows but not for screen width. > > > > Easily done, but I am not sure that this is the right thing to do. > > A pager is designed to handle excess vertical input, but not all > > can handle excess horizontal input (the width). I suspect that doing > > so would not be a good idea for the same reason given to me when I > > asked "why not send everything to the pager?": some systems force you > > to specifically exit the pager; this can be real annoying for cases > > with small input. > > While this is true, if you do a select whose output wraps because it is too > wide, getting it to go through "less -S" is extremely useful to have the > columns line up. OTOH, sending everything to the pager is annoying if the > result is only one value. > > I'd be happy with an easier way to force the pager than "\g |less -S". > Perhaps if \g is specified without a filename, it defaults to the pager. > Would such a patch be accepted? > > -- > Martijn van Oosterhout <kleptog@svana.org> http://svana.org/kleptog/ > > There are 10 kinds of people in the world, those that can do binary > > arithmetic and those that can't. > > ---------------------------(end of broadcast)--------------------------- > TIP 3: if posting/reading through Usenet, please send an appropriate > subscribe-nomail command to majordomo@postgresql.org so that your > message can get through to the mailing list cleanly > -- Bruce Momjian | http://candle.pha.pa.us pgman@candle.pha.pa.us | (610) 359-1001 + If your life is a hard drive, | 13 Roberts Road + Christ can be your backup. | Newtown Square, Pennsylvania 19073