Top
Enterprise Postgres 17 SP1 Application Development Guide

4.4.2 Relationship between Application Data Types and Database Data Types

The data types available for SQL data types are as follows:

Read mappings

PostgreSQL
Type

Default.NET
Type

Non-default
Type

boolean

bool

smallint

short

byte, sbyte, int, long, float, double, decimal

integer

int

byte, short, long, float, double, decimal

bigint

long

long, byte, short, int, float, double, decimal

real

float

double

double precision

double

numeric

decimal

byte, short, int, long, float, double, BigInteger

money

decimal

text

string

char[]

character varying

string

char[]

character

string

char[]

national character varying

string

char[]

national character

string

char[]

citext

string

char[]

json

string

char[]

jsonb

string

char[]

xml

string

char[]

uuid

Guid

bytea

byte[]

timestamp without time zone

DateTime (Unspecified)

timestamp with time zone

DateTime (Utc)(*1)

DateTimeOffset (Offset=0)(*2)

date

DateTime

DateOnly

time without time zone

TimeSpan

TimeOnly

time with time zone

DateTimeOffset

interval

TimeSpan(*3)

NpgsqlInterval

cidr

NpgsqlCidr

inet

IPAddress

NpgsqlInet

macaddr

PhysicalAddress

tsquery

NpgsqlTsQuery

tsvector

NpgsqlTsVector

bit(1)

bool

BitArray

bit(n)

BitArray

bit varying

BitArray

point

NpgsqlPoint

lseg

NpgsqlLSeg

path

NpgsqlPath

polygon

NpgsqlPolygon

line

NpgsqlLine

circle

NpgsqlCircle

box

NpgsqlBox

hstore

Dictionary<string, string>

oid

uint

xid

uint

cid

uint

oidvector

uint[]

name

string

char[]

(internal) char

char

byte, short, int, long

geometry (PostGIS)

PostgisGeometry

record

object[]

composite types

T

range types

NpgsqlRange<TElement>

multirange types (PG14)

NpgsqlRange<TElement>[]

enum types

TEnum

array types

Array (of element type)

*1: When Npgsql.EnableLegacyTimestampBehavior is enabled, reading a timestamp with time zone returns a Local DateTime instead of Utc.

*2: When Npgsql.EnableLegacyTimestampBehavior is enabled, reading a timestamp with time zone as a DateTimeOffset returns a local offset based on the timezone of the server where Npgsql is running.

*3: PostgreSQL intervals with month or year components cannot be read as TimeSpan. Consider using NodaTime's Period type, or NpgsqlInterval.

Write mappings

PostgreSQL
Type

Default.NET
Type

Non-default.NET
Type

NpgsqlDbType

DbType

boolean

bool

Boolean

Boolean

smallint

short, byte, sbyte

Smallint

Int16

integer

int

Integer

Int32

bigint

long

Bigint

Int64

real

float

Real

Single

double precision

double

Double

Double

numeric

decimal, BigInteger

Numeric

Decimal, VarNumeric

money

decimal

Money

Currency

text

string, char[], char

Text

String, StringFixedLength, AnsiString, AnsiStringFixedLength

character varying

string, char[], char

Varchar

character

string, char[], char

Char

citext

string, char[], char

Citext

json

string, char[], char

Json

jsonb

string, char[], char

Jsonb

xml

string, char[], char

Xml

uuid

Guid

Uuid

bytea

byte[]

ArraySegment<byte>

Bytea

Binary

timestamp with time zone

DateTime (Utc)(*1), DateTimeOffset

TimestampTz

DateTime(*2), DateTimeOffset

timestamp without time zone

DateTime (Local/Unspecified)(*1)

Timestamp

DateTime2

date

DateOnly

DateTime

Date

Date

time without time zone

TimeOnly

TimeSpan

Time

Time

time with time zone

DateTimeOffset

TimeTz

interval

TimeSpan

NpgsqlInterval

Interval

cidr

ValueTuple<IPAddress, int>, IPAddress

Cidr

inet

IPAddress

ValueTuple<IPAddress, int>

Inet

macaddr

PhysicalAddress

MacAddr

tsquery

NpgsqlTsQuery

TsQuery

tsvector

NpgsqlTsVector

TsVector

bit

bool, BitArray, string

Bit

bit varying

BitArray

bool, BitArray, string

Varbit

point

NpgsqlPoint

Point

lseg

NpgsqlLSeg

LSeg

path

NpgsqlPath

Path

polygon

NpgsqlPolygon

Polygon

line

NpgsqlLine

Line

circle

NpgsqlCircle

Circle

box

NpgsqlBox

Box

hstore

IDictionary<string, string>

Hstore

oid

uint

Oid

xid

uint

Xid

cid

uint

Cid

oidvector

uint[]

Oidvector

name

string, char[], char

Name

(internal) char

byte

InternalChar

composite types

Pre-mapped type

Composite

range types

NpgsqlRange<TSubtype>

Range | NpgsqlDbType

enum types

Pre-mapped type

Enum

array types

T[], List<T>

Array | NpgsqlDbType

*1: UTC DateTime is written as timestamp with time zone, Local/Unspecified DateTimes are written as timestamp without time zone. When Npgsql.EnableLegacyTimestampBehavior is enabled, DateTime is always written as timestamp without time zone.

*2: When Npgsql.EnableLegacyTimestampBehavior is enabled, DbType.DateTime is mapped to timestamp without time zone.