# ColumnInfo

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

*** ** * ** ***


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

<br />

*** ** * ** ***

Allows specific customization about the column associated with the annotated 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/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) public annotation https://developer.android.com/reference/androidx/room3/ColumnInfo.Collate` |
| `@https://developer.android.com/reference/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) public annotation https://developer.android.com/reference/androidx/room3/ColumnInfo.SQLiteTypeAffinity` The SQLite column type constants that can be used in `https://developer.android.com/reference/androidx/room3/ColumnInfo#typeAffinity()` |

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

| ### Public methods |
|---|---|
| `final int` | `@https://developer.android.com/reference/androidx/room3/ColumnInfo.Collate https://developer.android.com/reference/androidx/room3/ColumnInfo#getCollate()()` The collation sequence for the column, which will be used when constructing the database. |
| `final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/String.html` | `https://developer.android.com/reference/androidx/room3/ColumnInfo#getDefaultValue()()` The default value for this column. |
| `final boolean` | `https://developer.android.com/reference/androidx/room3/ColumnInfo#getIndex()()` Convenience value to index the property. |
| `final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/String.html` | `https://developer.android.com/reference/androidx/room3/ColumnInfo#getName()()` Name of the column in the database. |
| `final int` | `@https://developer.android.com/reference/androidx/room3/ColumnInfo.SQLiteTypeAffinity https://developer.android.com/reference/androidx/room3/ColumnInfo#getTypeAffinity()()` The type affinity for the column, which will be used when constructing the database. |

## Constants

### BINARY

Added in [3.0.0](https://developer.android.com/jetpack/androidx/releases/room3#3.0.0)

```
public static final int BINARY = 2
```

Collation sequence for case-sensitive match.

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

### BLOB

Added in [3.0.0](https://developer.android.com/jetpack/androidx/releases/room3#3.0.0)

```
public static final int BLOB = 5
```

Column affinity constant for binary data.

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

### INHERIT_FIELD_NAME

Added in [3.0.0](https://developer.android.com/jetpack/androidx/releases/room3#3.0.0)

```
public static final @NonNull String INHERIT_FIELD_NAME
```

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

Added in [3.0.0](https://developer.android.com/jetpack/androidx/releases/room3#3.0.0)

```
public static final int INTEGER = 3
```

Column affinity constant for integers or booleans.

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

### LOCALIZED

Added in [3.0.0](https://developer.android.com/jetpack/androidx/releases/room3#3.0.0)

```
public static final int LOCALIZED = 5
```

Collation sequence that uses system's current locale.

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

### NOCASE

Added in [3.0.0](https://developer.android.com/jetpack/androidx/releases/room3#3.0.0)

```
public static final int NOCASE = 3
```

Collation sequence for case-insensitive match.

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

### REAL

Added in [3.0.0](https://developer.android.com/jetpack/androidx/releases/room3#3.0.0)

```
public static final int REAL = 4
```

Column affinity constant for floats or doubles.

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

### RTRIM

Added in [3.0.0](https://developer.android.com/jetpack/androidx/releases/room3#3.0.0)

```
public static final int RTRIM = 4
```

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

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

### TEXT

Added in [3.0.0](https://developer.android.com/jetpack/androidx/releases/room3#3.0.0)

```
public static final int TEXT = 2
```

Column affinity constant for strings.

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

### UNDEFINED

Added in [3.0.0](https://developer.android.com/jetpack/androidx/releases/room3#3.0.0)

```
public static final int UNDEFINED = 1
```

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

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

### UNICODE

Added in [3.0.0](https://developer.android.com/jetpack/androidx/releases/room3#3.0.0)

```
public static final int UNICODE = 6
```

Collation sequence that uses Unicode Collation Algorithm.

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

### UNSPECIFIED

Added in [3.0.0](https://developer.android.com/jetpack/androidx/releases/room3#3.0.0)

```
public static final int UNSPECIFIED = 1
```

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

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

### VALUE_UNSPECIFIED

Added in [3.0.0](https://developer.android.com/jetpack/androidx/releases/room3#3.0.0)

```
public static final @NonNull String VALUE_UNSPECIFIED
```

A constant for `https://developer.android.com/reference/androidx/room3/ColumnInfo#defaultValue()` that makes the column to have no default value.

## Public methods

### getCollate

```
@ColumnInfo.Collate
public final int getCollate()
```

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

The default value is `https://developer.android.com/reference/androidx/room3/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/androidx/room3/ColumnInfo#BINARY()`.

Value is one of the following:

- `1`
- `2`
- `3`
- `4`
- `5`
- `6`

<br />

| Returns |
|---|---|
| `int` | The collation sequence of the column. This is either `https://developer.android.com/reference/androidx/room3/ColumnInfo#UNSPECIFIED()`, `https://developer.android.com/reference/androidx/room3/ColumnInfo#BINARY()`, `https://developer.android.com/reference/androidx/room3/ColumnInfo#NOCASE()`, `https://developer.android.com/reference/androidx/room3/ColumnInfo#RTRIM()`, `https://developer.android.com/reference/androidx/room3/ColumnInfo#LOCALIZED()` or `https://developer.android.com/reference/androidx/room3/ColumnInfo#UNICODE()`. |

### getDefaultValue

```
public final @NonNull String getDefaultValue()
```

The default value for this column.

```
@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/androidx/room3/Entity` with `https://developer.android.com/reference/androidx/room3/Insert`. In that case, the value of the object at runtime will be used. Use `https://developer.android.com/reference/androidx/room3/Query` with an `INSERT` statement and skip this column in the statement in order to use this default value. Alternative, if a 'partial entity' is used as parameter of the `https://developer.android.com/reference/androidx/room3/Insert` along with specifying the target entity via `https://developer.android.com/reference/androidx/room3/Insert#entity()`, the default value will be used if the data object class of the parameter does not define a property for this column.

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

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

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

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

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

| Returns |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/String.html` | The default value for this column. |

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

### getIndex

```
public final boolean getIndex()
```

Convenience value to index the property.

If you would like to create a composite index instead use the `https://developer.android.com/reference/androidx/room3` annotation.

| Returns |
|---|---|
| `boolean` | True if this property should be indexed, false otherwise. Defaults to false. |

### getName

```
public final @NonNull String getName()
```

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

| Returns |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/String.html` | Name of the column in the database. |

### getTypeAffinity

```
@ColumnInfo.SQLiteTypeAffinity
public final int getTypeAffinity()
```

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/androidx/room3/ColumnInfo#UNDEFINED()` and Room resolves it based on the property's type and available `https://developer.android.com/reference/androidx/room3/ColumnTypeConverters`.

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

Value is one of the following:

- `1`
- `2`
- `3`
- `4`
- `5`

<br />

| Returns |
|---|---|
| `int` | The type affinity of the column. This is either `https://developer.android.com/reference/androidx/room3/ColumnInfo#UNDEFINED()`, `https://developer.android.com/reference/androidx/room3/ColumnInfo#TEXT()`, `https://developer.android.com/reference/androidx/room3/ColumnInfo#INTEGER()`, `https://developer.android.com/reference/androidx/room3/ColumnInfo#REAL()`, or `https://developer.android.com/reference/androidx/room3/ColumnInfo#BLOB()`. |