ページの先頭行へ戻る
Enterprise Postgres 15 アプリケーション開発ガイド

4.4.2 アプリケーションのデータ型とデータベースのデータ型の関係

SQLのデータ型に対して、使用できるデータタイプは以下のとおりです。  

読み取りマッピング

PostgreSQL

データ型

標準.NET

データ型

非標準.NET
データ型

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

(IPAddress, int)

NpgsqlInet

inet

IPAddress

NpgsqlInet, (IPAddress, int)

macaddr

PhysicalAddress

tsquery

NpgsqlTsQuery

tsvector

NpgsqlTsVector

bit(1)

bool

BitArray

bit(n)

BitArray

bit varying

BitArray

point

NpgsqlPoint

lseg

NpgsqlLSeg

path

NpgsqlPath

polygon

NpgsqlPolygon

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

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) Npgsql.EnableLegacyTimestampBehaviorが有効な場合、timestamp with time zoneを読み込むとUtcではなくLocal DateTimeが返されます。

注2) Npgsql.EnableLegacyTimestampBehaviorが有効な場合、timestamp with time zoneをDateTimeOffsetとして読み込むと、Npgsqlが実行されているサーバーのタイムゾーンに基づいたローカルオフセットが返されます。

注3) PostgreSQLのintervalのうち、月または年の要素を持つものはTimeSpanとして読み込むことができません。NodaTimeのPeriodタイプ、またはNpgsqlIntervalの使用を検討してください。

書き込みマッピング

PostgreSQL

データ型

標準.NET

データ型

非標準.NET

データ型

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 without time zone

DateTime (Utc)(注1), DateTimeOffset

TimestampTz

DateTime(注2), DateTimeOffset

timestamp with 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はtimestamp with time zoneとして書き込まれ、Local/Unspecified DateTimesはtimestamp without time zoneとして書き込まれます。Npgsql.EnableLegacyTimestampBehaviorが有効な場合、DateTimeは常にtimestamp without time zoneとして書き込まれます。

注2) Npgsql.EnableLegacyTimestampBehaviorが有効な場合、DbType.DateTimeはtimestamp without time zoneにマップされます。