2017r2 PostgreSQL plugin gotcha

The new version of the PostgreSQL plugin has a “gotcha” (some might call it a bug) that can bite you in a non-obvious way. Fortunately, it’s easy to work around if you know the symptoms.

The old behavior: calling Connect after the initial connection always returned True, even if you weren’t truly connected. This was misleading but harmless.

New behavior: calling Connect after the initial connection will lead to strange errors about “NULL” in your SQL statement, and that error might not show up immediately.

Solution: make sure you only ever call Connect once. If you need to see if you’re still connected, use a simple SQL query with a known result like “SELECT 1”. (Note: if the database is in the midst of a failed transaction, this will fail but you can compensate for that too.)