Pretty borders in psql

Z PostgreSQL
Skočit na navigaci Skočit na vyhledávání

Pretty borders is simple and secure patch to PostgreSQL that enhances "line graphic" possibilities in PostgreSQL's console:

Installation

You need source code of PostgreSQL:

  1. download patch
  2. apply patch and compile
  3. install
pavel ~/src/postgresql $ patch -p1 < more_linestyles.diff 
patching file src/bin/psql/command.c
patching file src/bin/psql/print.c
patching file src/bin/psql/print.h
patching file src/bin/psql/tab-complete.c

Usage

You can set a combination of border type (0..4) and linestyle:

postgres=# \pset border 2
Border style is 2.
postgres=# \pset linestyle 
ascii            unicode          unicode-double1  unicode-double3  
old-ascii        unicode2         unicode-double2  unicode-double4  
postgres=# \pset linestyle unicode-double2
Line style is unicode-double2.
postgres=# select * from mytab;
╔═══╤════════════╤═══════╗
║ a │     b      │   c   ║
╠═══╪════════════╪═══════╣
║ 1 │ 2012-05-24 │ Hello ║
║ 2 │ 2012-05-25 │ Hello ║
║   │            │ World ║
╚═══╧════════════╧═══════╝
(2 rows)

postgres=# \pset border 3
Border style is 3.
postgres=# select * from mytab;
 a │     b      │   c   
═══╪════════════╪═══════
 1 │ 2012-05-24 │ Hello
───┼────────────┼───────
 2 │ 2012-05-25 │ Hello 
   │            │ World
(2 rows)

Possible modes

postgres=# \pset linestyle ascii 
Line style is ascii.
postgres=# select * from mytab ;
+---+------------+-------+
| a |     b      |   c   |
+---+------------+-------+
| 1 | 2012-05-24 | Hello |
+---+------------+-------+
| 2 | 2012-05-25 | Hello+|
|   |            | World |
+---+------------+-------+
(2 rows)

postgres=# select * from mytab ;
+---+------------+-------+
| a |     b      |   c   |
+---+------------+-------+
| 1 | 2012-05-24 | Hello |
+---+------------+-------+
| 2 | 2012-05-25 | Hello |
|                : World |
+---+------------+-------+
(2 rows)

postgres=# \pset linestyle unicode
Line style is unicode.
postgres=# select * from mytab ;
┌───┬────────────┬───────┐
│ a │     b      │   c   │
├───┼────────────┼───────┤
│ 1 │ 2012-05-24 │ Hello │
├───┼────────────┼───────┤
│ 2 │ 2012-05-25 │ Hello↵│
│   │            │ World │
└───┴────────────┴───────┘
(2 rows)

postgres=# \pset linestyle unicode2
Line style is unicode2.
postgres=# select * from mytab ;
┌───┬────────────┬───────┐
│ a │     b      │   c   │
├───┴────────────┴───────┤
│ 1 │ 2012-05-24 │ Hello │
├───┼────────────┼───────┤
│ 2 │ 2012-05-25 │ Hello │
│   │            │ World │
└────────────────────────┘
(2 rows)

postgres=# \pset linestyle unicode-double1
Line style is unicode-double1.
postgres=# select * from mytab ;
╔═══╤════════════╤═══════╗
║ a │     b      │   c   ║
╟───┼────────────┼───────╢
║ 1 │ 2012-05-24 │ Hello ║
╟───┼────────────┼───────╢
║ 2 │ 2012-05-25 │ Hello ║
║   │            │ World ║
╚═══╧════════════╧═══════╝
(2 rows)

postgres=# \pset linestyle unicode-double2
Line style is unicode-double2.
postgres=# select * from mytab ;
╔═══╤════════════╤═══════╗
║ a │     b      │   c   ║
╠═══╪════════════╪═══════╣
║ 1 │ 2012-05-24 │ Hello ║
╟───┼────────────┼───────╢
║ 2 │ 2012-05-25 │ Hello ║
║   │            │ World ║
╚═══╧════════════╧═══════╝
(2 rows)

postgres=# \pset linestyle unicode-double3
Line style is unicode-double3.
postgres=# select * from mytab ;
╔═══╦════════════╦═══════╗
║ a ║     b      ║   c   ║
╠═══╩════════════╩═══════╣
║ 1 │ 2012-05-24 │ Hello ║
╟───┼────────────┼───────╢
║ 2 │ 2012-05-25 │ Hello ║
║   │            │ World ║
╚════════════════════════╝
(2 rows)

postgres=# \pset linestyle unicode-double4
Line style is unicode-double4.
postgres=# select * from mytab ;
╔═══╦════════════╦═══════╗
║ a ║     b      ║   c   ║
╠═══╬════════════╬═══════╣
║ 1 ║ 2012-05-24 ║ Hello ║
╟───╫────────────╫───────╢
║ 2 ║ 2012-05-25 ║ Hello ║
║   ║            ║ World ║
╚═══╩════════════╩═══════╝
(2 rows)

unicode-double5 style (note: inside proposal for pg9.4. this style is renamed to unicode-bold1)
┌───────────┬──────────┬──────────┬────────────┬────────────┬───────────────────────┐
│   Name    │  Owner   │ Encoding │  Collate   │   Ctype    │   Access privileges   │
┝━━━━━━━━━━━┿━━━━━━━━━━┿━━━━━━━━━━┿━━━━━━━━━━━━┿━━━━━━━━━━━━┿━━━━━━━━━━━━━━━━━━━━━━━┥
│ postgres  │ postgres │ UTF8     │ en_US.utf8 │ en_US.utf8 │                       │
│ template0 │ postgres │ UTF8     │ en_US.utf8 │ en_US.utf8 │ =c/postgres           │
│           │          │          │            │            │ postgres=CTc/postgres │
│ template1 │ postgres │ UTF8     │ en_US.utf8 │ en_US.utf8 │ =c/postgres           │
│           │          │          │            │            │ postgres=CTc/postgres │
└───────────┴──────────┴──────────┴────────────┴────────────┴───────────────────────┘

unicode-double6 style (note: inside proposal for pg9.4. this style is renamed to unicode-double5)
┌───────────┬──────────┬──────────┬────────────┬────────────┬───────────────────────┐
│   Name    │  Owner   │ Encoding │  Collate   │   Ctype    │   Access privileges   │
╞═══════════╪══════════╪══════════╪════════════╪════════════╪═══════════════════════╡
│ postgres  │ postgres │ UTF8     │ en_US.utf8 │ en_US.utf8 │                       │
│ template0 │ postgres │ UTF8     │ en_US.utf8 │ en_US.utf8 │ =c/postgres           │
│           │          │          │            │            │ postgres=CTc/postgres │
│ template1 │ postgres │ UTF8     │ en_US.utf8 │ en_US.utf8 │ =c/postgres           │
│           │          │          │            │            │ postgres=CTc/postgres │
└───────────┴──────────┴──────────┴────────────┴────────────┴───────────────────────┘

postgres=# \pset border 0
Border style is 0.
postgres=# select * from mytab ;
a     b        c   
─ ────────── ─────
1 2012-05-24 Hello
2 2012-05-25 Hello↵
             World
(2 rows)

postgres=# \pset border 1
Border style is 1.
postgres=# select * from mytab ;
 a │     b      │   c   
───┼────────────┼───────
 1 │ 2012-05-24 │ Hello
 2 │ 2012-05-25 │ Hello↵
   │            │ World
(2 rows)

postgres=# \pset border 2
Border style is 2.
postgres=# select * from mytab ;
┌───┬────────────┬───────┐
│ a │     b      │   c   │
├───┼────────────┼───────┤
│ 1 │ 2012-05-24 │ Hello │
│ 2 │ 2012-05-25 │ Hello↵│
│   │            │ World │
└───┴────────────┴───────┘
(2 rows)

postgres=# \pset border 3
Border style is 3.
postgres=# select * from mytab;
 a │     b      │   c   
───┼────────────┼───────
 1 │ 2012-05-24 │ Hello
───┼────────────┼───────
 2 │ 2012-05-25 │ Hello↵
   │            │ World
(2 rows)

postgres=# \pset border 4
Border style is 4.
postgres=# select * from mytab;
┌───┬────────────┬───────┐
│ a │     b      │   c   │
├───┼────────────┼───────┤
│ 1 │ 2012-05-24 │ Hello │
├───┼────────────┼───────┤
│ 2 │ 2012-05-25 │ Hello↵│
│   │            │ World │
└───┴────────────┴───────┘
(2 rows)

Downloads