# ColumnInfo

Artifact: [androidx.room:room-common](https://developer.android.com/jetpack/androidx/releases/room) [View Source](https://cs.android.com/search?q=file:androidx/room/ColumnInfo.kt+class:androidx.room.ColumnInfo) Added in [2.0.0](https://developer.android.com/jetpack/androidx/releases/room#2.0.0)

*** ** * ** ***

Common/AllAndroid/JVMNative/C/iOSJavaScript
- Cmn

  ```
  @Target(allowedTargets = [AnnotationTarget.FIELD, AnnotationTarget.FUNCTION])
  @Retention(value = AnnotationRetention.BINARY)
  annotation ColumnInfo
  ```

*** ** * ** ***

Allows specific customization about the column associated with this property.

For example, you can specify a column name for the property or change the column's type affinity.

## Summary

| ### Nested types |
|---|
| `@https://developer.android.com/reference/kotlin/androidx/annotation/IntDef(value = [1, 2, 3, 4, 5, 6]) @https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.annotation/-retention/index.html(value = https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.annotation/-annotation-retention/-b-i-n-a-r-y/index.html) annotation https://developer.android.com/reference/kotlin/androidx/room/ColumnInfo.Collate` |
| `@https://developer.android.com/reference/kotlin/androidx/annotation/IntDef(value = [1, 2, 3, 4, 5]) @https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.annotation/-retention/index.html(value = https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.annotation/-annotation-retention/-b-i-n-a-r-y/index.html) annotation https://developer.android.com/reference/kotlin/androidx/room/ColumnInfo.SQLiteTypeAffinity` The SQLite column type constants that can be used in typeAffinity() |

| ### Constants |
|---|---|---|
| `const https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/room/ColumnInfo#BINARY() = 2` Collation sequence for case-sensitive match. | Cmn |
| `const https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/room/ColumnInfo#BLOB() = 5` Column affinity constant for binary data. | Cmn |
| `const https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html` | `https://developer.android.com/reference/kotlin/androidx/room/ColumnInfo#INHERIT_FIELD_NAME()` Constant to let Room inherit the property name as the column name. | Cmn |
| `const https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/room/ColumnInfo#INTEGER() = 3` Column affinity constant for integers or booleans. | Cmn |
| `const https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/room/ColumnInfo#LOCALIZED() = 5` Collation sequence that uses system's current locale. | Cmn |
| `const https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/room/ColumnInfo#NOCASE() = 3` Collation sequence for case-insensitive match. | Cmn |
| `const https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/room/ColumnInfo#REAL() = 4` Column affinity constant for floats or doubles. | Cmn |
| `const https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/room/ColumnInfo#RTRIM() = 4` Collation sequence for case-sensitive match except that trailing space characters are ignored. | Cmn |
| `const https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/room/ColumnInfo#TEXT() = 2` Column affinity constant for strings. | Cmn |
| `const https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/room/ColumnInfo#UNDEFINED() = 1` Undefined type affinity. | Cmn |
| `const https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/room/ColumnInfo#UNICODE() = 6` Collation sequence that uses Unicode Collation Algorithm. | Cmn |
| `const https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/room/ColumnInfo#UNSPECIFIED() = 1` Collation sequence is not specified. | Cmn |
| `const https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html` | `https://developer.android.com/reference/kotlin/androidx/room/ColumnInfo#VALUE_UNSPECIFIED()` A constant for defaultValue() that makes the column to have no default value. | Cmn |

| ### Public constructors |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/room/ColumnInfo#ColumnInfo(kotlin.String,kotlin.Int,kotlin.Boolean,kotlin.Int,kotlin.String)( name: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html, typeAffinity: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, index: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html, collate: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, defaultValue: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html )` | Cmn |

| ### Public properties |
|---|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/room/ColumnInfo#collate()` The collation sequence for the column, which will be used when constructing the database. | Cmn |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html` | `https://developer.android.com/reference/kotlin/androidx/room/ColumnInfo#defaultValue()` The default value for this column. | Cmn |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/room/ColumnInfo#index()` Convenience method to index the property. | Cmn |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html` | `https://developer.android.com/reference/kotlin/androidx/room/ColumnInfo#name()` Name of the column in the database. | Cmn |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/room/ColumnInfo#typeAffinity()` The type affinity for the column, which will be used when constructing the database. | Cmn |

## Constants

### BINARY

Cmn Added in [2.5.0](https://developer.android.com/jetpack/androidx/releases/room#2.5.0)

```
const val BINARY = 2: Int
```

Collation sequence for case-sensitive match.

| See also |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/room/ColumnInfo#collate()` | () |

### BLOB

Cmn Added in [2.5.0](https://developer.android.com/jetpack/androidx/releases/room#2.5.0)

```
const val BLOB = 5: Int
```

Column affinity constant for binary data.

| See also |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/room/ColumnInfo#typeAffinity()` | () |

### INHERIT_FIELD_NAME

Cmn Added in [2.5.0](https://developer.android.com/jetpack/androidx/releases/room#2.5.0)

```
const val INHERIT_FIELD_NAME: String
```

Constant to let Room inherit the property name as the column name. If used, Room will use the property name as the column name.

### INTEGER

Cmn Added in [2.5.0](https://developer.android.com/jetpack/androidx/releases/room#2.5.0)

```
const val INTEGER = 3: Int
```

Column affinity constant for integers or booleans.

| See also |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/room/ColumnInfo#typeAffinity()` | () |

### LOCALIZED

Cmn Added in [2.5.0](https://developer.android.com/jetpack/androidx/releases/room#2.5.0)

```
const val LOCALIZED = 5: Int
```

Collation sequence that uses system's current locale.

| See also |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/room/ColumnInfo#collate()` | () |

### NOCASE

Cmn Added in [2.5.0](https://developer.android.com/jetpack/androidx/releases/room#2.5.0)

```
const val NOCASE = 3: Int
```

Collation sequence for case-insensitive match.

| See also |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/room/ColumnInfo#collate()` | () |

### REAL

Cmn Added in [2.5.0](https://developer.android.com/jetpack/androidx/releases/room#2.5.0)

```
const val REAL = 4: Int
```

Column affinity constant for floats or doubles.

| See also |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/room/ColumnInfo#typeAffinity()` | () |

### RTRIM

Cmn Added in [2.5.0](https://developer.android.com/jetpack/androidx/releases/room#2.5.0)

```
const val RTRIM = 4: Int
```

Collation sequence for case-sensitive match except that trailing space characters are ignored.

| See also |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/room/ColumnInfo#collate()` | () |

### TEXT

Cmn Added in [2.5.0](https://developer.android.com/jetpack/androidx/releases/room#2.5.0)

```
const val TEXT = 2: Int
```

Column affinity constant for strings.

| See also |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/room/ColumnInfo#typeAffinity()` | () |

### UNDEFINED

Cmn Added in [2.5.0](https://developer.android.com/jetpack/androidx/releases/room#2.5.0)

```
const val UNDEFINED = 1: Int
```

Undefined type affinity. Will be resolved based on the type.

| See also |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/room/ColumnInfo#typeAffinity()` | () |

### UNICODE

Cmn Added in [2.5.0](https://developer.android.com/jetpack/androidx/releases/room#2.5.0)

```
const val UNICODE = 6: Int
```

Collation sequence that uses Unicode Collation Algorithm.

| See also |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/room/ColumnInfo#collate()` | () |

### UNSPECIFIED

Cmn Added in [2.5.0](https://developer.android.com/jetpack/androidx/releases/room#2.5.0)

```
const val UNSPECIFIED = 1: Int
```

Collation sequence is not specified. The match will behave like `https://developer.android.com/reference/kotlin/androidx/room/ColumnInfo#BINARY()`.

| See also |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/room/ColumnInfo#collate()` | () |

### VALUE_UNSPECIFIED

Cmn Added in [2.5.0](https://developer.android.com/jetpack/androidx/releases/room#2.5.0)

```
const val VALUE_UNSPECIFIED: String
```

A constant for defaultValue() that makes the column to have no default value.

## Public constructors

### ColumnInfo

Cmn Added in [2.8.5](https://developer.android.com/jetpack/androidx/releases/room#2.8.5)

```
ColumnInfo(
    name: String = INHERIT_FIELD_NAME,
    typeAffinity: Int = UNDEFINED,
    index: Boolean = false,
    collate: Int = UNSPECIFIED,
    defaultValue: String = VALUE_UNSPECIFIED
)
```

## Public properties

### collate

Cmn

```
val collate: Int
```

The collation sequence for the column, which will be used when constructing the database.

The default value is `https://developer.android.com/reference/kotlin/androidx/room/ColumnInfo#UNSPECIFIED()`. In that case, Room does not add any collation sequence to the column, and SQLite treats it like `https://developer.android.com/reference/kotlin/androidx/room/ColumnInfo#BINARY()`.

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | The collation sequence of the column. This is either `https://developer.android.com/reference/kotlin/androidx/room/ColumnInfo#UNSPECIFIED()`, `https://developer.android.com/reference/kotlin/androidx/room/ColumnInfo#BINARY()`, `https://developer.android.com/reference/kotlin/androidx/room/ColumnInfo#NOCASE()`, `https://developer.android.com/reference/kotlin/androidx/room/ColumnInfo#RTRIM()`, `https://developer.android.com/reference/kotlin/androidx/room/ColumnInfo#LOCALIZED()` or `https://developer.android.com/reference/kotlin/androidx/room/ColumnInfo#UNICODE()`. |

### defaultValue

Cmn

```
val defaultValue: String
```

The default value for this column.

```kotlin
@ColumnInfo(defaultValue = "No name")
public name: String

@ColumnInfo(defaultValue = "0")
public flag: Int
```

Note that the default value you specify here will *NOT* be used if you simply insert the `https://developer.android.com/reference/kotlin/androidx/room/Entity` with `https://developer.android.com/reference/kotlin/androidx/room/Insert`. In that case, any value assigned in Java/Kotlin will be used. Use `https://developer.android.com/reference/kotlin/androidx/room/Query` with an `INSERT` statement and skip this column there in order to use this default value.

NULL, CURRENT_TIMESTAMP and other SQLite constant values are interpreted as such. If you want to use them as strings for some reason, surround them with single-quotes.

```kotlin
@ColumnInfo(defaultValue = "NULL")
public description: String?

@ColumnInfo(defaultValue = "'NULL'")
public name: String
```

You can also use constant expressions by surrounding them with parentheses.

```kotlin
@ColumnInfo(defaultValue = "('Created at' || CURRENT_TIMESTAMP)")
public notice: String
```

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html` | The default value for this column. |

| See also |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/room/ColumnInfo#VALUE_UNSPECIFIED()` |   |

### index

Cmn

```
val index: Boolean
```

Convenience method to index the property.

If you would like to create a composite index instead, see: `https://developer.android.com/reference/kotlin/androidx/room`.

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | True if this property should be indexed, false otherwise. Defaults to false. |

### name

Cmn

```
val name: String
```

Name of the column in the database. Defaults to the property name if not set.

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html` | Name of the column in the database. |

### typeAffinity

Cmn

```
val typeAffinity: Int
```

The type affinity for the column, which will be used when constructing the database.

If it is not specified, the value defaults to `https://developer.android.com/reference/kotlin/androidx/room/ColumnInfo#UNDEFINED()` and Room resolves it based on the property's type and available TypeConverters.

See [SQLite types documentation](https://www.sqlite.org/datatype3.html) for details.

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | The type affinity of the column. This is either `https://developer.android.com/reference/kotlin/androidx/room/ColumnInfo#UNDEFINED()`, `https://developer.android.com/reference/kotlin/androidx/room/ColumnInfo#TEXT()`, `https://developer.android.com/reference/kotlin/androidx/room/ColumnInfo#INTEGER()`, `https://developer.android.com/reference/kotlin/androidx/room/ColumnInfo#REAL()`, or `https://developer.android.com/reference/kotlin/androidx/room/ColumnInfo#BLOB()`. |