Package org.h2.table

# Class Column

java.lang.Object
org.h2.table.Column

All Implemented Interfaces:
  `ColumnTemplate`, `HasSQL`, `Typed`

public final class Column extends Object implements HasSQL, Typed, ColumnTemplate
This class represents a column in a table.

## Field Summary

Fields
Modifier and Type
Field
Description
`static final int`
`NOT_NULLABLE`
This column is not nullable.
`static final int`
`NULLABLE`
This column is nullable.
`static final int`
`NULLABLE_UNKNOWN`
It is not know whether this column is nullable.
`static final String`
`ROWID`
The name of the rowid pseudo column.

### Fields inherited from interface org.h2.util.HasSQL

`ADD_PLAN_INFORMATION, DEFAULT_SQL_FLAGS, NO_CASTS, QUOTE_ONLY_WHEN_REQUIRED, REPLACE_LOBS_FOR_TRACE, TRACE_SQL_FLAGS`

## Constructor Summary

Constructors
Constructor
Description
`Column(String name, TypeInfo type)`
`Column(String name, TypeInfo type, Table table, int columnId)`

## Method Summary

Modifier and Type
Method
Description
`static ValueRow`
`convert(CastDataProvider provider, Column[] columns, ValueRow valueRow)`
Converts the values in a ValueRow based on the passed column info.
`Value`
`convert(CastDataProvider provider, Value v)`
Convert a value to this column's type without precision and scale checks.
`void`
`copy(Column source)`
Copy the data of the source column into the current column.
`boolean`
`equals(Object o)`
`Column`
`getClone()`
`int`
`getColumnId()`
`String`
`getComment()`
`String`
`getCreateSQL()`
`String`
`getCreateSQL(boolean forMeta)`
Get this columns part of CREATE TABLE SQL statement.
`String`
`getCreateSQLWithoutName()`
`Expression`
`getDefaultExpression()`
`String`
`getDefaultSQL()`
`Domain`
`getDomain()`
`Expression`
`getEffectiveDefaultExpression()`
`Expression`
`getEffectiveOnUpdateExpression()`
`SequenceOptions`
`getIdentityOptions()`
Returns identity column options, or `null` if sequence was already created or this column is not an identity column.
`String`
`getName()`
`Expression`
`getOnUpdateExpression()`
`String`
`getOnUpdateSQL()`
`int`
`getSelectivity()`
Get the selectivity of the column.
`Sequence`
`getSequence()`
`String`
`getSQL(int sqlFlags)`
Get the SQL statement of this expression.
`StringBuilder`
`getSQL(StringBuilder builder, int sqlFlags)`
Appends the SQL statement of this object to the specified builder.
`StringBuilder`
`getSQLWithTable(StringBuilder builder, int sqlFlags)`
Appends the table name and column name to the specified builder.
`Table`
`getTable()`
`TypeInfo`
`getType()`
Returns the data type.
`boolean`
`getVisible()`
`int`
`hashCode()`
`boolean`
`hasIdentityOptions()`
Whether the column has any identity options.
`void`
`initializeSequence(SessionLocal session, Schema schema, int id, boolean temporary)`
Initialize the sequence for this column.
`boolean`
`isDefaultOnNull()`
`boolean`
`isGenerated()`
Returns whether this column is a generated column.
`boolean`
`isGeneratedAlways()`
Returns whether this column is a generated column or always generated identity column.
`boolean`
`isIdentity()`
Returns whether this column is an identity column.
`boolean`
`isNullable()`
`boolean`
`isPrimaryKey()`
`boolean`
`isRowId()`
Returns whether this column is a row identity column.
`boolean`
`isWideningConversion(Column newColumn)`
Check whether the new column is of the same type and not more restricted than this column.
`void`
`prepareExpressions(SessionLocal session)`
Prepare all expressions of this column or domain.
`void`
`rename(String newName)`
Rename the column.
`void`
`setComment(String comment)`
`void`
`setDefaultExpression(SessionLocal session, Expression defaultExpression)`
Set the default expression.
`void`
`setDefaultOnNull(boolean defaultOnNull)`
`void`
`setDomain(Domain domain)`
`void`
`setGeneratedExpression(Expression expression)`
Set the default value in the form of a generated expression of other columns.
`void`
`setIdentityOptions(SequenceOptions identityOptions, boolean generatedAlways)`
Set the identity options of this column.
`void`
`setNullable(boolean b)`
`void`
`setOnUpdateExpression(SessionLocal session, Expression onUpdateExpression)`
Set the on update expression.
`void`
`setPrimaryKey(boolean primaryKey)`
`void`
`setRowId(boolean rowId)`
Set row identity flag.
`void`
`setSelectivity(int selectivity)`
Set the new selectivity of a column.
`void`
`setSequence(Sequence sequence, boolean generatedAlways)`
Set the sequence to generate the value.
`void`
`setTable(Table table, int columnId)`
Set the table and column id.
`void`
`setVisible(boolean b)`
`String`
`toString()`
`static StringBuilder`
`writeColumns(StringBuilder builder, Column[] columns, int sqlFlags)`
Appends the specified columns to the specified builder.
`static StringBuilder`
`writeColumns(StringBuilder builder, Column[] columns, String separator, String suffix, int sqlFlags)`
Appends the specified columns to the specified builder.

### Methods inherited from class java.lang.Object

`clone, finalize, getClass, notify, notifyAll, wait, wait, wait`

### Methods inherited from interface org.h2.util.HasSQL

`getTraceSQL`

## Field Details

### ROWID

public static final String ROWID
The name of the rowid pseudo column.

See Also:
  - Constant Field Values

### NOT_NULLABLE

public static final int NOT_NULLABLE
This column is not nullable.

See Also:
  - Constant Field Values

### NULLABLE

public static final int NULLABLE
This column is nullable.

See Also:
  - Constant Field Values

### NULLABLE_UNKNOWN

public static final int NULLABLE_UNKNOWN
It is not know whether this column is nullable.

See Also:
  - Constant Field Values

## Constructor Details

### Column

public Column(String name, TypeInfo type)

### Column

public Column(String name, TypeInfo type, Table table, int columnId)

## Method Details

### writeColumns

public static StringBuilder writeColumns(StringBuilder builder, Column[] columns, int sqlFlags)
Appends the specified columns to the specified builder.

Parameters:
  `builder` - string builder
  `columns` - columns
  `sqlFlags` - formatting flags
Returns:
  the specified string builder

### writeColumns

public static StringBuilder writeColumns(StringBuilder builder, Column[] columns, String separator, String suffix, int sqlFlags)
Appends the specified columns to the specified builder.

Parameters:
  `builder` - string builder
  `columns` - columns
  `separator` - separator
  `suffix` - additional SQL to append after each column
  `sqlFlags` - formatting flags
Returns:
  the specified string builder

### equals

public boolean equals(Object o)

Overrides:
  `equals` in class `Object`

### hashCode

public int hashCode()

Overrides:
  `hashCode` in class `Object`

### getClone

public Column getClone()

### convert

public Value convert(CastDataProvider provider, Value v)
Convert a value to this column's type without precision and scale checks.

Parameters:
  `provider` - the cast information provider
  `v` - the value
Returns:
  the value

### convert

public static ValueRow convert(CastDataProvider provider, Column[] columns, ValueRow valueRow)
Converts the values in a ValueRow based on the passed column info. Creates a new instance if any of the contained item must be converted. Otherwise, returns the same `valueRow`.

Parameters:
  `provider` - the cast information provider
  `columns` - the column info list used for the conversation
  `valueRow` - the holder of the values
Returns:
  a ValueRow which contains the converted values
See Also:
  - `convert(CastDataProvider, Value)`

### isIdentity

public boolean isIdentity()
Returns whether this column is an identity column.

Returns:
  whether this column is an identity column

### isGenerated

public boolean isGenerated()
Returns whether this column is a generated column.

Returns:
  whether this column is a generated column

### isGeneratedAlways

public boolean isGeneratedAlways()
Returns whether this column is a generated column or always generated identity column.

Returns:
  whether this column is a generated column or always generated identity column

### setGeneratedExpression

public void setGeneratedExpression(Expression expression)
Set the default value in the form of a generated expression of other columns.

Parameters:
  `expression` - the computed expression

### setTable

public void setTable(Table table, int columnId)
Set the table and column id.

Parameters:
  `table` - the table
  `columnId` - the column index

### getTable

public Table getTable()

### setDefaultExpression

public void setDefaultExpression(SessionLocal session, Expression defaultExpression)
Description copied from interface: `ColumnTemplate`
Set the default expression.

Specified by:
  `setDefaultExpression` in interface `ColumnTemplate`
Parameters:
  `session` - the session
  `defaultExpression` - the default expression

### setOnUpdateExpression

public void setOnUpdateExpression(SessionLocal session, Expression onUpdateExpression)
Description copied from interface: `ColumnTemplate`
Set the on update expression.

Specified by:
  `setOnUpdateExpression` in interface `ColumnTemplate`
Parameters:
  `session` - the session
  `onUpdateExpression` - the on update expression

### getColumnId

public int getColumnId()

### getSQL

public String getSQL(int sqlFlags)
Description copied from interface: `HasSQL`
Get the SQL statement of this expression. This may not always be the original SQL statement, specially after optimization.

Specified by:
  `getSQL` in interface `HasSQL`
Parameters:
  `sqlFlags` - formatting flags
Returns:
  the SQL statement

### getSQL

public StringBuilder getSQL(StringBuilder builder, int sqlFlags)
Description copied from interface: `HasSQL`
Appends the SQL statement of this object to the specified builder.

Specified by:
  `getSQL` in interface `HasSQL`
Parameters:
  `builder` - string builder
  `sqlFlags` - formatting flags
Returns:
  the specified string builder

### getSQLWithTable

public StringBuilder getSQLWithTable(StringBuilder builder, int sqlFlags)
Appends the table name and column name to the specified builder.

Parameters:
  `builder` - the string builder
  `sqlFlags` - formatting flags
Returns:
  the specified string builder

### getName

public String getName()

### getType

public TypeInfo getType()
Description copied from interface: `Typed`
Returns the data type.

Specified by:
  `getType` in interface `Typed`
Returns:
  the data type

### setNullable

public void setNullable(boolean b)

### getVisible

public boolean getVisible()

### setVisible

public void setVisible(boolean b)

### getDomain

public Domain getDomain()

Specified by:
  `getDomain` in interface `ColumnTemplate`

### setDomain

public void setDomain(Domain domain)

Specified by:
  `setDomain` in interface `ColumnTemplate`

### isRowId

public boolean isRowId()
Returns whether this column is a row identity column.

Returns:
  true for _ROWID_ column, false otherwise

### setRowId

public void setRowId(boolean rowId)
Set row identity flag.

Parameters:
  `rowId` - true _ROWID_ column, false otherwise

### initializeSequence

public void initializeSequence(SessionLocal session, Schema schema, int id, boolean temporary)
Initialize the sequence for this column.

Parameters:
  `session` - the session
  `schema` - the schema where the sequence should be generated
  `id` - the object id
  `temporary` - true if the sequence is temporary and does not need to be stored

### prepareExpressions

public void prepareExpressions(SessionLocal session)
Description copied from interface: `ColumnTemplate`
Prepare all expressions of this column or domain.

Specified by:
  `prepareExpressions` in interface `ColumnTemplate`
Parameters:
  `session` - the session

### getCreateSQLWithoutName

public String getCreateSQLWithoutName()

### getCreateSQL

public String getCreateSQL()

### getCreateSQL

public String getCreateSQL(boolean forMeta)
Get this columns part of CREATE TABLE SQL statement.

Parameters:
  `forMeta` - whether this is for the metadata table
Returns:
  the SQL statement

### isNullable

public boolean isNullable()

### getDefaultExpression

public Expression getDefaultExpression()

Specified by:
  `getDefaultExpression` in interface `ColumnTemplate`

### getEffectiveDefaultExpression

public Expression getEffectiveDefaultExpression()

Specified by:
  `getEffectiveDefaultExpression` in interface `ColumnTemplate`

### getOnUpdateExpression

public Expression getOnUpdateExpression()

Specified by:
  `getOnUpdateExpression` in interface `ColumnTemplate`

### getEffectiveOnUpdateExpression

public Expression getEffectiveOnUpdateExpression()

Specified by:
  `getEffectiveOnUpdateExpression` in interface `ColumnTemplate`

### hasIdentityOptions

public boolean hasIdentityOptions()
Whether the column has any identity options.

Returns:
  true if yes

### setIdentityOptions

public void setIdentityOptions(SequenceOptions identityOptions, boolean generatedAlways)
Set the identity options of this column.

Parameters:
  `identityOptions` - identity column options
  `generatedAlways` - whether value should be always generated

### getIdentityOptions

public SequenceOptions getIdentityOptions()
Returns identity column options, or `null` if sequence was already created or this column is not an identity column.

Returns:
  identity column options, or `null`

### setDefaultOnNull

public void setDefaultOnNull(boolean defaultOnNull)

### isDefaultOnNull

public boolean isDefaultOnNull()

### rename

public void rename(String newName)
Rename the column. This method will only set the column name to the new value.

Parameters:
  `newName` - the new column name

### setSequence

public void setSequence(Sequence sequence, boolean generatedAlways)
Set the sequence to generate the value.

Parameters:
  `sequence` - the sequence
  `generatedAlways` - whether the value of the sequence is always used

### getSequence

public Sequence getSequence()

### getSelectivity

public int getSelectivity()
Get the selectivity of the column. Selectivity 100 means values are unique, 10 means every distinct value appears 10 times on average.

Returns:
  the selectivity

### setSelectivity

public void setSelectivity(int selectivity)
Set the new selectivity of a column.

Parameters:
  `selectivity` - the new value

### getDefaultSQL

public String getDefaultSQL()

Specified by:
  `getDefaultSQL` in interface `ColumnTemplate`

### getOnUpdateSQL

public String getOnUpdateSQL()

Specified by:
  `getOnUpdateSQL` in interface `ColumnTemplate`

### setComment

public void setComment(String comment)

### getComment

public String getComment()

### setPrimaryKey

public void setPrimaryKey(boolean primaryKey)

### isPrimaryKey

public boolean isPrimaryKey()

### toString

public String toString()

Overrides:
  `toString` in class `Object`

### isWideningConversion

public boolean isWideningConversion(Column newColumn)
Check whether the new column is of the same type and not more restricted than this column.

Parameters:
  `newColumn` - the new (target) column
Returns:
  true if the new column is compatible

### copy

public void copy(Column source)
Copy the data of the source column into the current column.

Parameters:
  `source` - the source column