On this page:
5.1 Datetime Type Utilities
sql-datetime->srfi-date
srfi-date->sql-date
srfi-date->sql-time
srfi-date->sql-time-tz
srfi-date->sql-timestamp
srfi-date->sql-timestamp-tz
sql-day-time-interval->seconds
5.2 Geometric Types
point
line-string
polygon
multi-point
multi-line-string
multi-polygon
geometry-collection
geometry2d?
line?
linear-ring?
geometry->wkb
wkb->geometry
5.3 Postgre SQL-specific Types
pg-box
pg-path
pg-circle

5 Utilities

The bindings described in this section are provided by the specific modules below, not by db or db/base.

5.1 Datetime Type Utilities

 (require db/util/datetime)

(sql-datetime->srfi-date t)  srfi:date?
  t : (or/c sql-date? sql-time? sql-timestamp?)
(srfi-date->sql-date d)  sql-date?
  d : srfi:date?
(srfi-date->sql-time d)  sql-time?
  d : srfi:date?
(srfi-date->sql-time-tz d)  sql-time?
  d : srfi:date?
(srfi-date->sql-timestamp d)  sql-timestamp?
  d : srfi:date?
(srfi-date->sql-timestamp-tz d)  sql-timestamp?
  d : srfi:date?
Converts between this library’s date and time values and SRFI 19’s date values (see srfi/19). SRFI dates store more information than SQL dates and times, so converting a SQL time to a SRFI date, for example, puts zeroes in the year, month, and day fields.

Examples:

> (sql-datetime->srfi-date
   (query-value pgc "select time '7:30'"))

(tm:date 0 0 30 7 0 0 0 0)

> (sql-datetime->srfi-date
   (query-value pgc "select date '25-dec-1980'"))

(tm:date 0 0 0 0 25 12 1980 0)

> (sql-datetime->srfi-date
   (query-value pgc "select timestamp 'epoch'"))

(tm:date 0 0 0 0 1 1 1970 0)

Returns the length of interval in seconds.

5.2 Geometric Types

 (require db/util/geometry)

The following structures and functions deal with geometric values based on the OpenGIS (ISO 19125) model.

Note: Geometric columns defined using the PostGIS extension to PostgreSQL are not directly supported. Instead, data should be exchanged in the Well-Known Binary format; conversion of the following structures to and from WKB format is supported by the wkb->geometry and geometry->wkb functions.

(struct point (x y))
  x : real?
  y : real?
Represents an OpenGIS Point.
(struct line-string (points))
  points : (listof point?)
Represents an OpenGIS LineString.
(struct polygon (exterior interior))
  exterior : linear-ring?
  interior : (listof linear-ring?)
Represents an OpenGIS Polygon.
(struct multi-point (elements))
  elements : (listof point?)
Represents an OpenGIS MultiPoint, a collection of points.
(struct multi-line-string (elements))
  elements : (listof line-string?)
Represents an OpenGIS MultiLineString, a collection of line-strings.
(struct multi-polygon (elements))
  elements : (listof polygon?)
Represents an OpenGIS MultiPolygon, a collection of polygons.
(struct geometry-collection (elements))
  elements : (listof geometry2d?)
Represents an OpenGIS GeometryCollection, a collection of arbitrary geometric values.

(geometry2d? x)  boolean?
  x : any/c

(line? x)  boolean?
  x : any/c
Returns #t if x is a line-string consisting of exactly two points (cf OpenGIS Line); #f otherwise.

(linear-ring? x)  boolean?
  x : any/c
Returns #t if x is a line-string whose first and last points are equal (cf OpenGIS LinearRing); #f otherwise.

(geometry->wkb g #:big-endian? big-endian?)  bytes?
  g : geometry2d?
  big-endian? : (system-big-endian?)
Returns the Well-Known Binary (WKB) encoding of the geometric value g. The big-endian? argument determines the byte order used (the WKB format includes byte-order markers, so a robust client should accept either encoding).

(wkb->geometry b)  geometry2d?
  b : bytes?
Decodes the Well-Known Binary (WKB) representation of a geometric value.

5.3 PostgreSQL-specific Types

 (require db/util/postgresql)

The following structures represent certain of PostgreSQL’s built-in geometric types that have no appropriate analogue in the OpenGIS model: box, path, and circle. The point, lseg, and polygon PostgreSQL built-in types are represented using point, line-string (line?), and polygon structures.

Note: PostgreSQL’s built-in geometric types are distinct from those provided by the PostGIS extension library (see Geometric Types).

(struct pg-box (ne sw))
  ne : point?
  sw : point?
(struct pg-path (closed? points))
  closed? : boolean?
  points : (listof point?)
(struct pg-circle (center radius))
  center : point?
  radius : real?