08. Data type mapping

1. Supported data types

pldotnet fully supports 38 PostgreSQL data types via exactly the same type mapping as Npgsql. All those types are Nullable when the PostgreSQL function is created without STRICT. Furthermore, all supported data types also support arrays of that type, be they single-dimensional or multi-dimensional.

PostgreSQL data type pl/dotnet data type
BIT BitArray
BOOL bool
BOX NpgsqlBox
BPCHAR string
BYTEA byte[]
CIDR (IPAddress Address, int Netmask)
CIRCLE NpgsqlCircle
DATE DateOlny
DATERANGE NpgsqlRange<DateOnly>
FLOAT4 float
FLOAT8 double
INET (IPAddress Address, int Netmask)
INT2 short
INT4 int
INT4RANGE NpgsqlRange<int>
INT8 long
INT8RANGE NpgsqlRange<long>
INTERVAL NpgsqlInterval
JSON string
LINE NpgsqlLine
LSEG NpgsqlLSeg
MACADDR PhysicalAddress
MACADDR8 PhysicalAddress
MONEY decimal
PATH NpgsqlPath
POINT NpgsqlPoint
POLYGON NpgsqlPolygon
TEXT string
TIME TimeOnly
TIMESTAMP DateTime
TIMESTAMPTZ DateTime
TIMETZ DateTimeOffset
TSRANGE NpgsqlRange<DateTime>
TSTZRANGE NpgsqlRange<DateTime>
UUID Guid
VARBIT BitArray
VARCHAR string
XML string

2. F# exceptions

In F#, some basic types have different names compared to C#. You can find a description of these basic F# types on the Microsoft page here.

PostgreSQL data type C# data type F# data type
CIDR IPAddress Address, int Netmask struct(IPAddress*int)
FLOAT4 float float32
INET IPAddress Address, int Netmask struct(IPAddress*int)
INT2 short int16
INT8 long int64
INT8RANGE NpgsqlRange<long> NpgsqlRange<int64>

The CIDR and INET data types are mapped using struct tuples. You can find a comparison between reference and struct tuples here.