# Class: Column

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

# Hierarchy

# Properties

# Readonly arrayDimension

arrayDimension: number

Defined in src/pg-structure/column.ts:133

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


# Readonly attributeNumber

attributeNumber: number

Defined in src/pg-structure/column.ts:51

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 Readonly comment

comment? : undefined | string

Inherited from MaterializedView.comment

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

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


# Readonly defaultWithTypeCast

defaultWithTypeCast: string | null

Defined in src/pg-structure/column.ts:150

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 Readonly length

length? : undefined | number

Defined in src/pg-structure/column.ts:214

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.

# Readonly name

name: string

Inherited from MaterializedView.name

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

Name of the database object.


# Readonly notNull

notNull: boolean

Defined in src/pg-structure/column.ts:99

true if column is not allowed to be null.


# Readonly parent

parent: Entity | CompositeType

Defined in src/pg-structure/column.ts:56

Parent database object this column belongs to.


# Optional Readonly precision

precision? : undefined | number

Defined in src/pg-structure/column.ts:130

  • 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 Readonly scale

scale? : undefined | number

Defined in src/pg-structure/column.ts:117

  • 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.

# Readonly type

type: Type

Defined in src/pg-structure/column.ts:102

Data type of the column.

# Accessors

# commentData

get commentData(): JSONData | undefined

Inherited from MaterializedView.commentData

Defined in src/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 MaterializedView.commentWithoutData

Defined in src/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 MaterializedView.db

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

Database of the database object.

Returns: Db


# default

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

Defined in src/pg-structure/column.ts:165

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 src/pg-structure/column.ts:64

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 src/pg-structure/column.ts:173

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

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


# fullCatalogName

get fullCatalogName(): string

Inherited from MaterializedView.fullCatalogName

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

Full name of the database object including database name.

Returns: string


# fullName

get fullName(): string

Overrides Constraint.fullName

Defined in src/pg-structure/column.ts:94

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 src/pg-structure/column.ts:183

IndexableArray of indexes, which column is part of.

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


# isForeignKey

get isForeignKey(): boolean

Defined in src/pg-structure/column.ts:194

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 src/pg-structure/column.ts:201

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 src/pg-structure/column.ts:105

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

Returns: boolean


# nameCaseType

get nameCaseType(): CaseType

Inherited from MaterializedView.nameCaseType

Defined in src/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 src/pg-structure/column.ts:220

All referenced columns in all foreign keys by this column.

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


# schema

get schema(): Schema

Overrides Constraint.schema

Defined in src/pg-structure/column.ts:232

Schema this column belongs to.

Returns: Schema


# separator

get separator(): string

Inherited from MaterializedView.separator

Defined in src/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 src/pg-structure/column.ts:74

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 src/pg-structure/column.ts:254

[[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 src/pg-structure/column.ts:243

[[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 src/pg-structure/column.ts:84

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

# Example

const table = column.view; // Table instance

Returns: View | undefined