Skip to content

Types conversion

Eugene Kabanov edited this page Jun 29, 2016 · 1 revision

Supported type conversions

Primitive types

Nim type PostgreSQL type PostgreSQL OID
bool bool 16
char char 18
int8 char 18
uint8 char 18
int16 int2 21
uint16 int2 21
int32 int4 23
uint32 int4 23
int64 int8 20
uint64 int8 20
float32 float4 700
float64 float8 701
float float8 701
int* int2, int4, int8 21, 23, 20
uint* int2, int4, int8 21, 23, 20
string text 25
cstring text 25

Arrays and Sequences

Nim type PostgreSQL type PostgreSQL OID
seq or array of [bool] ARRAY[bool] 1000
seq or array of [char] BYTEA 17
seq or array of [int8] BYTEA 17
seq or array of [uint8] BYTEA 17
seq or array of [int16] ARRAY[int2] 1005
seq or array of [uint16] ARRAY[int2] 1005
seq or array of [int32] ARRAY[int4] 1007
seq or array of [uint32] ARRAY[int4] 1007
seq or array of [int64] ARRAY[int8] 1016
seq or array of [uint64] ARRAY[uint8] 1016
seq or array of [float32] ARRAY[float4] 1021
seq or array of [float64] ARRAY[float8] 1022
seq or array of [float] ARRAY[float8] 1022
seq or array of [int]* ARRAY[int2, int4, int8] 1005, 1007, 1016
seq or array of [uint]* ARRAY[int2, int4, int8] 1005, 1007, 1016
seq or array of [string] ARRAY[text] 1009
seq or array of [cstring] ARRAY[text] 1009
  • Size of int/uint types in Nim language depends on platform architecture, so if your platform 64bit, int/uint will be converted to PostgreSQL's type int8, if your platform 32bit, int/uint will be converted to PosgreSQL's type int4 and if your platform supports only 16bit integers, int/uint will be converted to PostgreSQL's type int2.

Custom types

Nim type PostgreSQL type PostgreSQL OID
JsonNode json 114
Json* json 114
JsonB* jsonb 3802
  • Json and JsonB types declared only to allow simple conversion of Nim's JsonNode object to PostgreSQL's json (114) and jsonb (3802) respectively. So you can use Json(JsonNode) to store JsonNode object as PostgreSQL's json object, or JsonB(JsonNode) to store JsonNode object as PostgreSQL's jsonb object.
Clone this wiki locally