helpers.Column(col) → {helpers.Column}

new Column(col) → {helpers.Column}

Read-only structure with details for a single column. Used primarily by ColumnSet.

The class parses details into a template, to be used for query generation.

Name Type Description
col string | helpers.ColumnConfig

Column details, depending on the type.

When it is a string, it is expected to contain a name for both the column and the source property, assuming that the two are the same. The name must adhere to JavaScript syntax for variable names. The name can be appended with any format modifier as supported by as.format (^, ~, #, :csv, :list, :json, :alias, :name, :raw, :value), which is then removed from the name and put into property mod. If the name starts with ?, it is removed, while setting flag cnd = true.

If the string doesn't adhere to the above requirements, the method will throw TypeError = Invalid column syntax.

When col is a simple ColumnConfig-like object, it is used as an input configurator to set all the properties of the class.

Name Type Attributes Description
name string

Destination column name + source property name (if prop is skipped). The name must adhere to JavaScript syntax for variables, unless prop is specified, in which case name represents only the column name, and therefore can be any non-empty string.

prop string <optional>

Source property name, if different from the column's name. It must adhere to JavaScript syntax for variables.

It is ignored when it is the same as name.

mod string <optional>

Formatting modifier, as supported by method as.format: ^, ~, #, :csv, :list, :json, :alias, :name, :raw, :value.

cast string <optional>

Server-side type casting, without :: in front.

cnd boolean <optional>

Conditional column flag.

Used by methods update and sets, ignored by methods insert and values. It indicates that the column is reserved for a WHERE condition, not to be set or updated.

It can be set from a string initialization, by adding ? in front of the name.

def * <optional>

Default value for the property, to be used only when the source object doesn't have the property. It is ignored when property init is set.

init helpers.initCB <optional>

Override callback for the value.

skip helpers.skipCB <optional>

An override for skipping columns dynamically.

Used by methods update (for a single object) and sets, ignored by methods insert and values.

It is also ignored when conditional flag cnd is set.

const pgp = require('pg-promise')({
    capSQL: true // if you want all generated SQL capitalized

const Column = pgp.helpers.Column;

// creating a column from just a name:
const col1 = new Column('colName');
// Column {
//    name: "colName"
// }

// creating a column from a name + modifier:
const col2 = new Column('colName:csv');
// Column {
//    name: "colName"
//    mod: ":csv"
// }

// creating a column from a configurator:
const col3 = new Column({
    name: 'colName', // required
    prop: 'propName', // optional
    mod: '^', // optional
    def: 123 // optional
// Column {
//    name: "colName"
//    prop: "propName"
//    mod: "^"
//    def: 123
// }


(readonly) castText :string

Full-syntax sql type casting, if there is any, or else an empty string.

  • string

(readonly) escapedName :string

Escaped name of the column, ready to be injected into queries directly.

  • string

(readonly) variable :string

Full-syntax formatting variable, ready for direct use in query templates.

  • string
const cs = new pgp.helpers.ColumnSet([
        name: 'places',
        mod: ':csv',
        cast: 'int[]'

// cs.columns[0].variable = ${id}
// cs.columns[1].variable = ${coordinate:json}
// cs.columns[2].variable = ${places:csv}::int[]


toString(levelopt) → {string}

Creates a well-formatted multi-line string that represents the object.

It is called automatically when writing the object into the console.

Name Type Attributes Default Description
level number <optional>

Nested output level, to provide visual offset.