Postgres data types

This page explains how the various data types available in Postgres are handled in Gallium Data

Numbers

All these types are exposed to filter logic as JavaScript numbers, except for extremely large or extremely precise numbers (with precision greater than 15 digits), in which case the value will be exposed to the JavaScript logic as a Java BigDecimal object (this can only happen for values of type decimal/numeric).

For values of type decimal/numeric, keep in mind that JavaScript numbers are floating-point numbers, and therefore that some precision may be lost. See the Bind packet for ways to avoid that.

Example

Given two columns named weight and tare of type decimal:

let weight = context.packet.weight;

context.packet.tare = weight / 10;

Characters

All these types are exposed as strings.

Example

let country = context.packet.country_name;

if (country.toLowerCase() === 'norway') {

    context.packet.region = 'Scandinavia';

}

Binary

Parameters of type bytea are exposed as byte arrays, e.g.:

context.packet.setParameter(2, [1,2,3,4,5,6,7,8,9,0]);

Date/time

All these types are exposed as strings in the indicated format. It is usually possible to pass a JavaScript Date object for date and timestamp types.

Ranges

All these types are exposed as strings in the indicated format.

Geometric types

All geometric types are exposed as strings.

Network addresses

All these types are exposed as strings in the indicated format.

Miscellaneous types

Arrays

Array types are exposed as JavaScript arrays, and the type of the array members is as described above.