Data Type Mappings Between Golang And PostgreSQL

2021/08/22

PostgreSQL数据库中的基本数据类型一共是41种,实际应用中,数据库使用类型、数据库实现类型、Go语言承载类型,如何做一一对应,这下子就清楚了。

数据库基本类型数据库实现类型Go语言承载类型
bigintINT8int64
bigserialINT8int64
bit(4)BITinterface{}
bit varying(4)VARBITinterface{}
booleanBOOLbool
boxBOXinterface{}
byteaBYTEA[]uint8
character(4)BPCHARinterface{}
character varying(4)VARCHARinterface{}
cidrCIDRinterface{}
circleCIRCLEinterface{}
dateDATEtime.Time
double precisionFLOAT8interface{}
inetINETinterface{}
integerINT4int32
intervalINTERVALinterface{}
jsonJSONinterface{}
jsonbJSONBinterface{}
lineLINEinterface{}
lsegLSEGinterface{}
macaddrMACADDRinterface{}
moneyMONEYinterface{}
numericNUMERICinterface{}
pathPATHinterface{}
pg_lsnPG_LSNinterface{}
pointPOINTinterface{}
polygonPOLYGONinterface{}
realFLOAT4interface{}
smallintINT2int16
smallserialINT2int16
serialINT4int32
textTEXTstring
time without time zoneTIMEtime.Time
time with time zoneTIMETZtime.Time
timestamp without time zoneTIMESTAMPtime.Time
timestamp with time zoneTIMESTAMPTZtime.Time
tsqueryTSQUERYinterface{}
tsvectorTSVECTORinterface{}
txid_snapshotTXID_SNAPSHOTinterface{}
uuidUUIDinterface{}
xmlXMLinterface{}