Listen/Notify

Any connection can be given a callback to run on notifications. However they
are only received when other traffic is going on.

A special listen-only connection can be established for instant notification
processing with PG.connect_listen.

# see full example in examples/listen_notify.cr
PG.connect_listen("postgres:///", "a", "b") do |n| # connect and listen on "a" and "b"
puts " got: #{n.payload} on #{n.channel}" # print notifications as they come in
end

Arrays

Crystal-pg supports several popular array types. If you only need a 1
dimensional array, you can cast down to the appropriate Crystal type:

Requirements

Crystal-pg is tested on Postgres
versions 9.2 through 9.6. Since it uses protocol version 3, older versions probably also
work but are not guaranteed.

Supported Datatypes

text

boolean

int8, int4, int2

float4, float8

timestamptz, date, timestamp (but no one should use ts when tstz exists!)

json and jsonb

uuid

bytea

numeric/decimal (1)

varchar

regtype

geo types: point, box, path, lseg, polygon, circle, line

array types: int8, int4, int2, float8, float4, bool, text

1: A note on numeric: In Postgres this type has arbitrary precision. In this
driver, it is represented as a PG::Numeric which retains all precision, but
if you need to do any math on it, you will probably need to cast it to a
float first. If you need true arbitrary precision, you can optionally
require pg_ext/big_rational which adds #to_big_r, but requires that you
have LibGMP installed.