CHM-manual for PostgreSQL 9.6

CHM IconAs I already wrote years ago, I use PostgreSQL manuals very often since the 8.x versions. And if for earlier versions it was possible to download CHM help file, now it’s not.

PostgreSQL manual consists of the 1351 topics (and still grows!) and I don’t like the search engine on the site much. It is also worth noting that the tree of contents (TOC) in CHM version speeds up navigation a lot!

A good friend of mine Edward Smirnov obsessed with creating a utility capable to compile the manual in CHM format using a set of HTML / SGML files shipped with PostgreSQL. He managed this! The only thing missing is the Index support (HHK file in CHM archive).

However, even without this feature such manual a hundred times more comfortable for me than the online counterpart. Especially I’m excited about lightning full-text searches.

We’ve put PostgreSQL 9.6 CHM manual at MicroOLAP Database Designer for PostgreSQL
and PostgresDAC download pages, welcome to download it.

UPD By default Windows doesn’t allow using .chm files downloaded from Internet. So you should right-click on the .chm file, then Properties and then check Unblock checkbox (or Unblock button in Windows 7 and older).

Unblock CHM
Unblock CHM


Easy PostgreSQL docs for Sublime Text

I’m using this perfect tool called Sublime Text 3 for a bunch of tasks. One of them is viewing SQL scripts from time to time. ST3 has perfect SQL highlighting, but what I miss the most is the context help functionality, e.g. I select “LEFT JOIN” and hit F1 hot key. But that’s not problem since ST3 has a lot of packages. To solve my problem I need GotoDocumentation package and some tuning. Here is my settings for GotoDocumentation:

"docs": {
// obj containing the docs for each scope
// these are merged with the default ones
// the key value pair represent scope -> doc url
// supported placeholders:
// - %(query)s the selected text/word
// - %(scope)s the current scope
"sql": ""

"pascal": "",
// if we have no docs for the current scope
// we will try using the fallback one,
// to disable set to false
"fallback_scope": "google"

ST3 context help  for pg sql
ST3 context help for pg sql

Creating titles from text (SQL)

Task: get title (or excerpt) from given text (body)

left(body, 29) ||
COALESCE( substring( substr( body, 30 ) from '(.+?)(\,| )' ), '' ) as title,

Details: Take the first 29 characters, concatenate them with substring started from the 30-th character till the first occurrence of comma or space. Or concatenate with empty string, if pattern doesn’t match (COALESCE).

MERGE in PostgreSQL

Found cool trick how today implement Orable MERGE in PostgreSQL:

Oracle statement:


  1. MERGE INTO acme_obj_value d
  2. USING ( SELECT object_id
  3.         FROM   acme_state_tmp
  4.       ) s
  5. ON (d.object_id = s.object_id)
  6.   WHEN matched THEN
  7.     UPDATE SET d.date_value = LEAST(l_dt, d.date_value)
  8.   WHEN NOT matched THEN
  9.     INSERT (, d.object_id, d.date_value)
  10.     VALUES (acme_param_sequence.NEXTVAL, s.object_id, l_dt)

PostgreSQL statement:


  1. WITH s AS (
  2.      SELECT object_id
  3.      FROM   acme_state_tmp
  4. ),
  5. upd AS (
  6.      UPDATE acme_obj_value
  7.      SET    date_value = LEAST(l_dt, d.date_value)
  8.      FROM   s
  9.      WHERE  acme_obj_value.object_id = s.object_id
  10.      RETURNING acme_obj_value.object_id
  11. )
  12. INSERT INTO acme_obj_value(id, object_id,  date_value)
  13. SELECT NEXTVAL(‘acme_param_sequence’), s.object_id, l_dt
  14. FROM   s
  15. WHERE  s.object_id NOT IN (SELECT object_id FROM upd)