Next: Index, Previous: Introspection, Up: Top [Contents][Index]
Sometimes you just want to poke around manually, interacting with a database connection by typing in exploratory commands, and the external command-line program psql(1) does not provide enough insight or customizability (or perhaps is not available). This chapter presents an alternative method for running such a REPL (read-eval-print loop).
To get started, load the postgres-gxrepl module:
(use-modules (database postgres-gxrepl))
This provides the procedure gxrepl. The “gx” stands for “guile
extensible”, which is not the case at the moment, but we have great and
humble plans for this module...
Run a read-eval-print loop, talking to database conn.
conn may be a string naming a database, a string with
var=val options suitable for passing to pg-connectdb,
or a connection object that satisfies pg-connection?.
The repl accepts two kinds of commands:
CREATE TABLE or
SELECT are executed using pg-exec.
Sending an EOF exits the repl.
Most comma commands are relatively self-explanatory, with guidance from
,help. The rest of this chapter delves into some of the more
arcane commands.
Primarily, the fixed-part select is an exploratory type of interaction
where you can fix certain parts of a normal select query so that
you can concentrate on varying the rest.
For example:
,fix #:from icbmcoords
Use the table ‘icbmcoords’ (with columns ‘one’, ‘two’ and ‘importance’).
,fsel one two #:where (< 9 importance)
Select some tuples.
,fix #:cols ("latitude" . one) ("longitude" . two)
More descriptive titles.
,fix #:where (< 9 importance) (> 3 importance)
We are scatterbrained, which helps ameliorate the evilness.
,fix #:where/combiner or
Uh oh, wits recovered, we once again are a menace.
For comparison, here is the last example again, recast into SQL:
SELECT one AS "latitude", two AS "longitude" FROM icbmcoords WHERE ((9 < importance) OR (3 > importance));
Next: Index, Previous: Introspection, Up: Top [Contents][Index]