Shell (psql+)

Readable help

Stock psql ships the grammar straight from the PostgreSQL documentation. It is accurate and almost unreadable — a wall of [ ], { | }, and ... with no explanation of what any of it means or a single example to copy.

psql+ keeps \h but reformats it: the syntax is laid out so you can read it, each option is explained in a line, and every command ends with a worked, copy-pasteable example.

\h create index

=> \h create index

CREATE INDEX — build an index on a table

  CREATE [ UNIQUE ] INDEX [ CONCURRENTLY ] [ name ]
      ON table [ USING method ] ( column [ , ... ] )
      [ WHERE predicate ]

Options
  UNIQUE        Reject duplicate values in the indexed columns.
  CONCURRENTLY  Build without locking writes. Slower; cannot run
                inside a transaction block.
  USING method  btree (default), hash, gin, gist, brin, ...
  WHERE         Build a partial index covering only matching rows.

Example
  CREATE INDEX CONCURRENTLY idx_orders_status
      ON orders (status)
      WHERE status = 'pending';

\h select

=> \h select

SELECT — retrieve rows from tables and views

  SELECT [ DISTINCT ] select_list
      FROM from_item [ , ... ]
      [ WHERE condition ]
      [ GROUP BY expression [ , ... ] ]
      [ HAVING condition ]
      [ ORDER BY expression [ ASC | DESC ] ]
      [ LIMIT count ] [ OFFSET start ]

Clauses
  DISTINCT   Drop duplicate result rows.
  WHERE      Keep only rows matching the condition.
  GROUP BY   Collapse rows into groups for aggregates.
  HAVING     Filter groups (WHERE runs before grouping).
  ORDER BY   Sort the result; ASC default.
  LIMIT      Cap the number of rows returned.

Example
  SELECT status, count(*)
      FROM orders
      GROUP BY status
      HAVING count(*) > 10
      ORDER BY count(*) DESC
      LIMIT 5;

Compare that to stock psql, where \h select prints several screens of bracketed grammar and nothing else — no per-clause explanation and no example to run.

Scope

  • \h <command> covers SQL commands (SELECT, INSERT, CREATE INDEX, ALTER TABLE, and so on). Pass a multi-word command exactly as you would type it: \h create index.
  • \h with no argument lists the SQL commands you can look up.
  • For backslash meta-commands (\d, \timing, \copy, ...), the standard \? help still works unchanged.

Use \h when you have forgotten the shape of a statement and want the answer in seconds — read the syntax, scan the options, copy the example, and move on.