# Class: Column

Class which represent a column. Provides attributes and methods for details of the column.

# Hierarchy

# Properties

# arrayDimension

arrayDimension: number

Defined in pg-structure/column.ts:130

If type is an array, this is the dimension of the array. Otherwise this is 0.


# attributeNumber

attributeNumber: number

Defined in pg-structure/column.ts:48

The number of the column. Ordinary columns are numbered from 1 up. Since dropped columns have an attribute number too, attribute number may be different from array index number.


# Optional comment

comment? : undefined | string

Inherited from DbObject.comment

Defined in pg-structure/base/db-object.ts:75

Comment of the database object defined in database including {@link DbObject#commentData comment data}.


# defaultWithTypeCast

defaultWithTypeCast: string | null

Defined in pg-structure/column.ts:147

Default expression of the column with typecast. PostgreSQL returns default values with typecast. Default values includes single quotes except sql functions and numeric values. Also sql functions and numeric values do not contain type cast.

Numeric values are returned as string too. Please see: https://github.com/brianc/node-postgres/issues/1300

# Example

const table = db('crm').schema('public').table('contact');
const defaultName = table.get("name").default;                     // "'George'"
const defaultNameWithCast = table.get("name").defaultWithTypeCast; // "'George'::character varying"
const defaultAge = table.get("age").default;                       // 20
const defaultStamp = table.get("created_at").default;              // "now()"

see Column.default for accessing default values without typecast.


# Optional length

length? : undefined | number

Defined in pg-structure/column.ts:211

Length of the column.

  • For data type identified as a character or bit string type, this is the declared maximum length. If column is an array, same rule applies data type of the array.
  • For character arrays or bit string type arrays, this is the declared maximum length of the array's data type.
  • For arrays atttypmod records type-specific data supplied at table creation time (for example, the maximum length of a varchar column). It is passed to type-specific input functions and length coercion functions.
  • This value is undefined for all other data types or if no maximum length was declared.

# name

name: string

Inherited from DbObject.name

Defined in pg-structure/base/db-object.ts:42

Name of the database object.


# notNull

notNull: boolean

Defined in pg-structure/column.ts:96

true if column is not allowed to be null.


# parent

parent: Entity | CompositeType

Defined in pg-structure/column.ts:53

Parent database object this column belongs to.


# Optional precision

precision? : undefined | number

Defined in pg-structure/column.ts:127

  • If data type identifies a numeric type, this contains the (declared or implicit) precision of the type for this column. The precision indicates the number of significant digits.
  • If data type identifies a date, time, timestamp, or interval type, this column contains the (declared or implicit) fractional seconds precision of the type for this attribute, that is, the number of decimal digits maintained following the decimal point in the seconds value.
  • If data type is an array. Same rules apply for the data type of the array, and this value would become precision of the data type of the array.
  • For all other data types, this is undefined. For example: The number 23.5141 has a precision of 6 and a scale of 4.

# Optional scale

scale? : undefined | number

Defined in pg-structure/column.ts:114

  • If data type identifies an exact numeric type, this contains the (declared or implicit) scale of the type for this attribute. The scale indicates the number of significant digits to the right of the decimal point.
  • If data type is an array. Same rule applies for the data type of the array, and this value would become scale of the data type of the array.
  • For all other data types, this is undefined. For example: The number 23.5141 has a precision of 6 and a scale of 4. Integers can be considered to have a scale of zero.

# type

type: Type

Defined in pg-structure/column.ts:99

Data type of the column.

# Accessors

# commentData

get commentData(): JSONData | undefined

Inherited from DbObject.commentData

Defined in pg-structure/base/db-object.ts:102

Data which is extracted from database object's comment. Data is extracted from text between special case-insesitive tag (default: [pg-structure][/pg-structure]) and converted to JavaScript object using JSON5. Token name can be specified by using commentDataToken arguments. For details of JSON5, see it's web site: https://json5.org.

# Example

// "Account details. [pg-structure]{ extraData: 2 }[/pg-structure] Also used for logging."
table.comment;               // "Account details. [pg-structure]{ extraData: 2 }[/pg-structure] Also used for logging."
table.commentWithoutData;    // "Account details.  Also used for logging."
table.commentData;           // { extraData: 2 }
table.commentData.extraData; // 2

Returns: JSONData | undefined


# commentWithoutData

get commentWithoutData(): string | undefined

Inherited from DbObject.commentWithoutData

Defined in pg-structure/base/db-object.ts:85

Description or comment of the database object defined in database. If comment contains {@link DbObject#commentData comment data}, it is removed.

# Example

// "Account details. [pg-structure]{ extraData: 2 }[/pg-structure] Also used for logging."
table.commentWithoutData;    // "Account details.  Also used for logging."

Returns: string | undefined


# db

get db(): Db

Inherited from DbObject.db

Defined in pg-structure/base/db-object.ts:68

Database of the database object.

Returns: Db


# default

get default(): number | boolean | string | null

Defined in pg-structure/column.ts:162

Default value without typecast. Default values includes single quotes except sql functions and numeric values.

Numeric values are returned as string too. Please see: https://github.com/brianc/node-postgres/issues/1300

# Example

const table = db('crm').schema('public').table('contact');
const defaultName = table.get("name").default;                     // "'George'"
const defaultNameWithCast = table.get("name").defaultWithTypeCast; // "'George'::character varying"
const defaultAge = table.get("age").default;                       // 20
const defaultStamp = table.get("created_at").default;              // "now()"

see Column.defaultWithTypeCast for default values with typecast as returned by PostgreSQL

Returns: number | boolean | string | null


# entity

get entity(): Entity | undefined

Defined in pg-structure/column.ts:61

Entity this column belongs to if it belongs to a table or view.

# Example

const entity = column.entity; // Entity instance

Returns: Entity | undefined


# foreignKeys

get foreignKeys(): IndexableArray‹ForeignKey, "name", never, true›

Defined in pg-structure/column.ts:170

[[IndexableArray]] of foreign keys which column is part of.

Returns: IndexableArray‹ForeignKey, "name", never, true›


# fullCatalogName

get fullCatalogName(): string

Inherited from DbObject.fullCatalogName

Defined in pg-structure/base/db-object.ts:35

Full name of the database object including database name.

Returns: string


# fullName

get fullName(): string

Overrides DbObject.fullName

Defined in pg-structure/column.ts:91

Full name of the object with '.' notation including Schema name.

# Example

const fullName = column.fullName; // public.member.name

Returns: string


# indexes

get indexes(): IndexableArray‹Index, "name", never, true›

Defined in pg-structure/column.ts:180

IndexableArray of indexes, which column is part of.

Returns: IndexableArray‹Index, "name", never, true›


# isForeignKey

get isForeignKey(): boolean

Defined in pg-structure/column.ts:191

Whether this column is part of a foreign key. Please note that a foreign key may contain more than one column and a column may part of more than one foreign key.

Returns: boolean


# isPrimaryKey

get isPrimaryKey(): boolean

Defined in pg-structure/column.ts:198

Whether column is part of a primary key. Please note that a primary key may contain more than one column.

Returns: boolean


# isSerial

get isSerial(): boolean

Defined in pg-structure/column.ts:102

Whether this column has nextval() default value or one of serial (auto incremented) types.

Returns: boolean


# nameCaseType

get nameCaseType(): CaseType

Inherited from DbObject.nameCaseType

Defined in pg-structure/base/db-object.ts:54

Letter casing (i.e snakeCase or camelCase) of the database object name.

# Example

const name = entity.name;                        // ProductDetail
const caseType = entity.nameCaseType;            // camelCase

const otherEntity = otherEntity.name;            // member_protocol
const otherCaseType = otherEntity.nameCaseType;  // snakeCase

Returns: CaseType


# referencedColumns

get referencedColumns(): IndexableArray‹Column, "name", never, true›

Defined in pg-structure/column.ts:217

All referenced columns in all foreign keys by this column.

Returns: IndexableArray‹Column, "name", never, true›


# schema

get schema(): Schema

Overrides DbObject.schema

Defined in pg-structure/column.ts:229

Schema this column belongs to.

Returns: Schema


# separator

get separator(): string

Inherited from DbObject.separator

Defined in pg-structure/base/db-object.ts:61

Separator used in database object name. Empty string for came case and underscore for (_) snake case.

Returns: string


# table

get table(): Table | undefined

Defined in pg-structure/column.ts:71

Table this column belongs to if it belongs to a table.

# Example

const table = column.table; // Table instance

Returns: Table | undefined


# uniqueIndexes

get uniqueIndexes(): IndexableArray‹Index, "name", never, true›

Defined in pg-structure/column.ts:251

[[IndexableArray]] of unique indexes, which column is part of. PostgreSQL already creates a unique index for unique constraints. So there is no need to look for unique constraints which will result duplicates.

see Column.uniqueIndexesNoPk for unique indexes excluding primary key indexes.

Returns: IndexableArray‹Index, "name", never, true›


# uniqueIndexesNoPk

get uniqueIndexesNoPk(): IndexableArray‹Index, "name", never, true›

Defined in pg-structure/column.ts:240

[[IndexableArray]] of unique indexes, which column is part of. Excludes primary key indexes. PostgreSQL already creates a unique index for unique constraints. So there is no need to look for unique constraints which will result duplicates.

see Column.uniqueIndexes for all unique indexes including primary key indexes.

Returns: IndexableArray‹Index, "name", never, true›


# view

get view(): View | undefined

Defined in pg-structure/column.ts:81

View this column belongs to if it belongs to a view.

# Example

const table = column.view; // Table instance

Returns: View | undefined