Thursday, August 13, 2009

epsql available

Hello

Today I uploaded patch enhancing psql on pgfoundry. You can download it from url http://pgfoundry.org/frs/download.php/2335/epsql.diff. This patch should be applied on postgresql 8.4 source:
cd postgresql-8.4.0/src/bin/psql
patch -p1 < epsql.diff
make clean
make all
su
make install
Enhanced psql has new metacommand \lf and new formating option linestyle (+2 new border styles).

\lf

\lf print function's source code (with and without row numbers):
postgres=# \lf foo(int)
**** CREATE OR REPLACE FUNCTION public.foo(_a integer)
**** RETURNS integer
**** LANGUAGE plpgsql
**** AS $function$
1 BEGIN
2 RETURN _a + 1;
3 END;
**** $function$

postgres=# \lf- foo(int)
CREATE OR REPLACE FUNCTION public.foo(_a integer)
RETURNS integer
LANGUAGE plpgsql
AS $function$
BEGIN
RETURN _a + 1;
END;
$function$

smart wrap mode

original wrap mode:
postgres=# \pset format wrapped
Output format is wrapped.
postgres=# select * from test;
+--------------------------------------------------------------------------------------+
| a |
+--------------------------------------------------------------------------------------+
| Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor inci |
| didunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exerc |
| itation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dol |
| or in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. |
| Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt m |
| ollit anim id est laborum. |
+--------------------------------------------------------------------------------------+
(1 row)
modified wrap mode:
postgres=# select * from test;
+--------------------------------------------------------------------------------------+
| a |
+--------------------------------------------------------------------------------------+
| Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor |
| incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud |
| exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute |
| irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla |
| pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia |
| deserunt mollit anim id est laborum. |
+--------------------------------------------------------------------------------------+
(1 row)

Border styles

postgres=# \pset border 0
Border style is 0.
postgres=# \d pg_database
Table "pg_catalog.pg_database"
Column Type Modifiers
------------- --------- ---------
datname name not null
datdba oid not null
encoding integer not null
datcollate name not null
datctype name not null
datistemplate boolean not null
datallowconn boolean not null
datconnlimit integer not null
datlastsysoid oid not null
datfrozenxid xid not null
dattablespace oid not null
datconfig text[]
datacl aclitem[]

postgres=# \pset border 1
Border style is 1.
postgres=# \d pg_database
Table "pg_catalog.pg_database"
Column | Type | Modifiers
---------------+-----------+-----------
datname | name | not null
datdba | oid | not null
encoding | integer | not null
datcollate | name | not null
datctype | name | not null
datistemplate | boolean | not null
datallowconn | boolean | not null
datconnlimit | integer | not null
datlastsysoid | oid | not null
datfrozenxid | xid | not null
dattablespace | oid | not null
datconfig | text[] |
datacl | aclitem[] |

postgres=# \pset border 2
Border style is 2.
postgres=# \d pg_database
Table "pg_catalog.pg_database"
+---------------+-----------+-----------+
| Column | Type | Modifiers |
+---------------+-----------+-----------+
| datname | name | not null |
| datdba | oid | not null |
| encoding | integer | not null |
| datcollate | name | not null |
| datctype | name | not null |
| datistemplate | boolean | not null |
| datallowconn | boolean | not null |
| datconnlimit | integer | not null |
| datlastsysoid | oid | not null |
| datfrozenxid | xid | not null |
| dattablespace | oid | not null |
| datconfig | text[] | |
| datacl | aclitem[] | |
+---------------+-----------+-----------+

postgres=# \pset border 3
Border style is 3.
postgres=# \d pg_database
Table "pg_catalog.pg_database"
+---------------+-----------+-----------+
| Column | Type | Modifiers |
+---------------+-----------+-----------+
| datname | name | not null |
+---------------+-----------+-----------+
| datdba | oid | not null |
+---------------+-----------+-----------+
| encoding | integer | not null |
+---------------+-----------+-----------+
| datcollate | name | not null |
+---------------+-----------+-----------+
| datctype | name | not null |
+---------------+-----------+-----------+
| datistemplate | boolean | not null |
+---------------+-----------+-----------+
| datallowconn | boolean | not null |
+---------------+-----------+-----------+
| datconnlimit | integer | not null |
+---------------+-----------+-----------+
| datlastsysoid | oid | not null |
+---------------+-----------+-----------+
| datfrozenxid | xid | not null |
+---------------+-----------+-----------+
| dattablespace | oid | not null |
+---------------+-----------+-----------+
| datconfig | text[] | |
+---------------+-----------+-----------+
| datacl | aclitem[] | |
+---------------+-----------+-----------+

postgres=# \pset border 4
Border style is 4.
postgres=# \d pg_database
Table "pg_catalog.pg_database"
Column | Type | Modifiers
---------------+-----------+----------
datname | name | not null
---------------+-----------+----------
datdba | oid | not null
---------------+-----------+----------
encoding | integer | not null
---------------+-----------+----------
datcollate | name | not null
---------------+-----------+----------
datctype | name | not null
---------------+-----------+----------
datistemplate | boolean | not null
---------------+-----------+----------
datallowconn | boolean | not null
---------------+-----------+----------
datconnlimit | integer | not null
---------------+-----------+----------
datlastsysoid | oid | not null
---------------+-----------+----------
datfrozenxid | xid | not null
---------------+-----------+----------
dattablespace | oid | not null
---------------+-----------+----------
datconfig | text[] |
---------------+-----------+----------
datacl | aclitem[] |

Linestyles

postgres=# \pset linestyle 0
Border line style is 0.
postgres=# \d pg_user_mapping
Table "pg_catalog.pg_user_mapping"
+-----------+--------+-----------+
| Column | Type | Modifiers |
+-----------+--------+-----------+
| umuser | oid | not null |
+-----------+--------+-----------+
| umserver | oid | not null |
+-----------+--------+-----------+
| umoptions | text[] | |
+-----------+--------+-----------+

postgres=# \pset linestyle 1
Border line style is 1.
postgres=# \d pg_user_mapping
Table "pg_catalog.pg_user_mapping"
┌───────────┬────────┬───────────┐
│ Column │ Type │ Modifiers │
├───────────┼────────┼───────────┤
│ umuser │ oid │ not null │
├───────────┼────────┼───────────┤
│ umserver │ oid │ not null │
├───────────┼────────┼───────────┤
│ umoptions │ text[] │ │
└───────────┴────────┴───────────┘

postgres=# \pset linestyle 2
Border line style is 2.
postgres=# \d pg_user_mapping
Table "pg_catalog.pg_user_mapping"
┌───────────┬────────┬───────────┐
│ Column │ Type │ Modifiers │
├───────────┴────────┴───────────┤
│ umuser │ oid │ not null │
├───────────┼────────┼───────────┤
│ umserver │ oid │ not null │
├───────────┼────────┼───────────┤
│ umoptions │ text[] │ │
└────────────────────────────────┘

postgres=# \pset linestyle 3
Border line style is 3.
postgres=# \d pg_user_mapping
Table "pg_catalog.pg_user_mapping"
╔═══════════╤════════╤═══════════╗
║ Column │ Type │ Modifiers ║
╟───────────┼────────┼───────────╢
║ umuser │ oid │ not null ║
╟───────────┼────────┼───────────╢
║ umserver │ oid │ not null ║
╟───────────┼────────┼───────────╢
║ umoptions │ text[] │ ║
╚═══════════╧════════╧═══════════╝

postgres=# \pset linestyle 4
Border line style is 4.
postgres=# \d pg_user_mapping
Table "pg_catalog.pg_user_mapping"
╔═══════════╤════════╤═══════════╗
║ Column │ Type │ Modifiers ║
╠═══════════╪════════╪═══════════╣
║ umuser │ oid │ not null ║
╟───────────┼────────┼───────────╢
║ umserver │ oid │ not null ║
╟───────────┼────────┼───────────╢
║ umoptions │ text[] │ ║
╚═══════════╧════════╧═══════════╝

postgres=# \pset linestyle 5
Border line style is 5.
postgres=# \d pg_user_mapping
Table "pg_catalog.pg_user_mapping"
╔═══════════╦════════╦═══════════╗
║ Column ║ Type ║ Modifiers ║
╠═══════════╩════════╩═══════════╣
║ umuser │ oid │ not null ║
╟───────────┼────────┼───────────╢
║ umserver │ oid │ not null ║
╟───────────┼────────┼───────────╢
║ umoptions │ text[] │ ║
╚════════════════════════════════╝

postgres=# \pset linestyle 6
Border line style is 6.
postgres=# \d pg_user_mapping
Table "pg_catalog.pg_user_mapping"
╔═══════════╦════════╦═══════════╗
║ Column ║ Type ║ Modifiers ║
╠═══════════╬════════╬═══════════╣
║ umuser ║ oid ║ not null ║
╟───────────╫────────╫───────────╢
║ umserver ║ oid ║ not null ║
╟───────────╫────────╫───────────╢
║ umoptions ║ text[] ║ ║
╚═══════════╩════════╩═══════════╝
Please, test it, use it.
Regards
Pavel Stehule

3 Comments:

At August 13, 2009 at 3:59 PM , Blogger Bruce Momjian said...

Great. Hopefully this will allow a testbed for future enhancements to the community's psql implementation.

 
At August 13, 2009 at 10:52 PM , Blogger Oleg Bartunov said...

Pavel, while you're on psql may be you can add !$ support,like in shell !

 
At August 13, 2009 at 10:59 PM , Blogger Pavel Stěhule said...

To Oleg: I don't know what it does?

My ideas about next features are for and if support

like
\for query;
\do
..
..
\done

and
\if query
\then
..
\else
..
\fi

 

Post a Comment

Subscribe to Post Comments [Atom]

Links to this post:

Create a Link

<< Home