【问题标题】:PostgreSQL and C# DatatypesPostgreSQL 和 C# 数据类型
【发布时间】:2010-10-25 03:10:44
【问题描述】:

我搜索了 PostgreSQL 和 C# 之间的类型转换表,但我找不到任何东西。 如果我有时间,我会研究上表的空单元格。 但是如果你知道有这些信息的网页,我非常适合你的帮助。

Postgre Type --->C# Type

bigint --->Int64

bigserial --->

bit [ (n) ] --->Byte[]

bit varying [ (n) ] --->Byte

boolean --->Boolean

box --->

bytea --->Byte[]

character varying [ (n) ] ---> String

character --->String

cidr

circle 

date --->DateTime

double precision --->Double

inet

integer --->Int32

interval [ (p) ] --->TimeSpan

line 

lseg 

macaddr

money

numeric [ (p, s) ] --->Decimal

decimal [ (p, s) ] --->Decimal

path  

point 

polygon 

real --->Single

smallint --->Int16

serial 

text --->String

time [ (p) ] [ without time zone ] --->

time [ (p) ] with time zone --->

timestamp [ (p) ] [ without time zone ] --->

timestamp [ (p) ] with time zone --->

tsquery 

tsvector 

txid_snapshot

uuid --->Guid

xml   

【问题讨论】:

    标签: c# postgresql types


    【解决方案1】:

    也许你可以通过查看文档找到一些东西 Npgsql,它是用于 PostgreSQL 的 .NET 数据提供程序的实现。

    This page of the documentation 实际上包含您要查找的内容的完整表格。搜索“4. Current Npgsql Status” - “支持的数据类型”。有一个很好的表,其中包含所有 PostgreSQL 数据类型及其在 .NET 中的对应关系。

    Postgresql NpgsqlDbType System.DbType Enum .Net 系统类型 ---------- ------------ ------ ---------- ------ int8 Bigint Int64 Int64 bool 布尔值 布尔值 布尔值 bytea Bytea 二进制字节[] 日期日期日期日期时间 float8 双 双 双 双 int4 整数 Int32 Int32 钱 钱 十进制 十进制 数字 数字 十进制 十进制 float4 实单单单 int2 Smallint Int16 Int16 文本 文本 字符串 字符串 时间 时间 时间 日期时间 timetz 时间 时间 日期时间 时间戳 时间戳 日期时间 日期时间 timestamptz TimestampTZ DateTime DateTime 间隔间隔对象时间跨度 varchar varchar String 字符串 inet Inet 对象 IP 地址 位 位 布尔 布尔 uuid Uuid Guid Guid 数组数组对象数组

    【讨论】:

    • 不确定这是否过时,但我在将 DateTime 对象转换为 Postgresql“时间”类型时遇到了一些麻烦。 stackoverflow.com/questions/6129558/…。我需要使用 TimeSpan 对象将其保存为 Postgresql 时间对象。
    • @Spilarix 谢谢。修复了链接。
    • 这张表是错误的,数据库类型TIME可以是负数,实际上它是SQL推荐的存储一个时间戳减去另一个时间戳的结果的类型 - 即它是存储时间跨度的推荐类型。 DB TIME 必须映射到 C# TimeSpan,因为 C# DateTime 不能保存负值,因此无法转换。 DB Time 被指定为既用于存储绝对时间又用于存储相对时间,并且有效范围从 -hh:mm 到 +hh:mm,我相信 hh 大约是 850 小时,但我不记得我的头顶。
    • 嗨! jsonb postgresql 类型呢?我有一个类型为 jsonb 的数据列。我将它映射到一个字符串属性。似乎不正确,因为我遇到此错误 Npgsql.PostgresException : 42804: column "data" is of type jsonb but expression is of type text.
    猜你喜欢
    • 2014-03-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-05-15
    • 1970-01-01
    • 2017-09-29
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多