using System; using Npgsql; using Npgsql.TypeMapping; #pragma warning disable CA1720 // ReSharper disable once CheckNamespace namespace NpgsqlTypes; /// /// Represents a PostgreSQL data type that can be written or read to the database. /// Used in places such as to unambiguously specify /// how to encode or decode values. /// /// /// See https://www.postgresql.org/docs/current/static/datatype.html. /// // Source for PG OIDs: public enum NpgsqlDbType { // Note that it's important to never change the numeric values of this enum, since user applications // compile them in. #region Numeric Types /// /// Corresponds to the PostgreSQL 8-byte "bigint" type. /// /// See https://www.postgresql.org/docs/current/static/datatype-numeric.html [BuiltInPostgresType("int8", baseOID: 20, arrayOID: 1016, rangeName: "int8range", rangeOID: 3926, multirangeName: "int8multirange", multirangeOID: 4536)] Bigint = 1, /// /// Corresponds to the PostgreSQL 8-byte floating-point "double" type. /// /// See https://www.postgresql.org/docs/current/static/datatype-numeric.html [BuiltInPostgresType("float8", baseOID: 701, arrayOID: 1022)] Double = 8, /// /// Corresponds to the PostgreSQL 4-byte "integer" type. /// /// See https://www.postgresql.org/docs/current/static/datatype-numeric.html [BuiltInPostgresType("int4", baseOID: 23, arrayOID: 1007, rangeName: "int4range", rangeOID: 3904, multirangeName: "int4multirange", multirangeOID: 4451)] Integer = 9, /// /// Corresponds to the PostgreSQL arbitrary-precision "numeric" type. /// /// See https://www.postgresql.org/docs/current/static/datatype-numeric.html [BuiltInPostgresType("numeric", baseOID: 1700, arrayOID: 1231, rangeName: "numrange", rangeOID: 3906, multirangeName: "nummultirange", multirangeOID: 4532)] Numeric = 13, /// /// Corresponds to the PostgreSQL floating-point "real" type. /// /// See https://www.postgresql.org/docs/current/static/datatype-numeric.html [BuiltInPostgresType("float4", baseOID: 700, arrayOID: 1021)] Real = 17, /// /// Corresponds to the PostgreSQL 2-byte "smallint" type. /// /// See https://www.postgresql.org/docs/current/static/datatype-numeric.html [BuiltInPostgresType("int2", baseOID: 21, arrayOID: 1005)] Smallint = 18, /// /// Corresponds to the PostgreSQL "money" type. /// /// See https://www.postgresql.org/docs/current/static/datatype-money.html [BuiltInPostgresType("money", baseOID: 790, arrayOID: 791)] Money = 12, #endregion #region Boolean Type /// /// Corresponds to the PostgreSQL "boolean" type. /// /// See https://www.postgresql.org/docs/current/static/datatype-boolean.html [BuiltInPostgresType("bool", baseOID: 16, arrayOID: 1000)] Boolean = 2, #endregion #region Geometric types /// /// Corresponds to the PostgreSQL geometric "box" type. /// /// See https://www.postgresql.org/docs/current/static/datatype-geometric.html [BuiltInPostgresType("box", baseOID: 603, arrayOID: 1020)] Box = 3, /// /// Corresponds to the PostgreSQL geometric "circle" type. /// /// See https://www.postgresql.org/docs/current/static/datatype-geometric.html [BuiltInPostgresType("circle", baseOID: 718, arrayOID: 719)] Circle = 5, /// /// Corresponds to the PostgreSQL geometric "line" type. /// /// See https://www.postgresql.org/docs/current/static/datatype-geometric.html [BuiltInPostgresType("line", baseOID: 628, arrayOID: 629)] Line = 10, /// /// Corresponds to the PostgreSQL geometric "lseg" type. /// /// See https://www.postgresql.org/docs/current/static/datatype-geometric.html [BuiltInPostgresType("lseg", baseOID: 601, arrayOID: 1018)] LSeg = 11, /// /// Corresponds to the PostgreSQL geometric "path" type. /// /// See https://www.postgresql.org/docs/current/static/datatype-geometric.html [BuiltInPostgresType("path", baseOID: 602, arrayOID: 1019)] Path = 14, /// /// Corresponds to the PostgreSQL geometric "point" type. /// /// See https://www.postgresql.org/docs/current/static/datatype-geometric.html [BuiltInPostgresType("point", baseOID: 600, arrayOID: 1017)] Point = 15, /// /// Corresponds to the PostgreSQL geometric "polygon" type. /// /// See https://www.postgresql.org/docs/current/static/datatype-geometric.html [BuiltInPostgresType("polygon", baseOID: 604, arrayOID: 1027)] Polygon = 16, #endregion #region Character Types /// /// Corresponds to the PostgreSQL "char(n)" type. /// /// See https://www.postgresql.org/docs/current/static/datatype-character.html [BuiltInPostgresType("bpchar", baseOID: 1042, arrayOID: 1014)] Char = 6, /// /// Corresponds to the PostgreSQL "text" type. /// /// See https://www.postgresql.org/docs/current/static/datatype-character.html [BuiltInPostgresType("text", baseOID: 25, arrayOID: 1009)] Text = 19, /// /// Corresponds to the PostgreSQL "varchar" type. /// /// See https://www.postgresql.org/docs/current/static/datatype-character.html [BuiltInPostgresType("varchar", baseOID: 1043, arrayOID: 1015)] Varchar = 22, /// /// Corresponds to the PostgreSQL internal "name" type. /// /// See https://www.postgresql.org/docs/current/static/datatype-character.html [BuiltInPostgresType("name", baseOID: 19, arrayOID: 1003)] Name = 32, /// /// Corresponds to the PostgreSQL "citext" type for the citext module. /// /// See https://www.postgresql.org/docs/current/static/citext.html Citext = 51, // Extension type /// /// Corresponds to the PostgreSQL "char" type. /// /// /// This is an internal field and should normally not be used for regular applications. /// /// See https://www.postgresql.org/docs/current/static/datatype-text.html /// [BuiltInPostgresType("char", baseOID: 18, arrayOID: 1002)] InternalChar = 38, #endregion #region Binary Data Types /// /// Corresponds to the PostgreSQL "bytea" type, holding a raw byte string. /// /// See https://www.postgresql.org/docs/current/static/datatype-binary.html [BuiltInPostgresType("bytea", baseOID: 17, arrayOID: 1001)] Bytea = 4, #endregion #region Date/Time Types /// /// Corresponds to the PostgreSQL "date" type. /// /// See https://www.postgresql.org/docs/current/static/datatype-datetime.html [BuiltInPostgresType("date", baseOID: 1082, arrayOID: 1182, rangeName: "daterange", rangeOID: 3912, multirangeName: "datemultirange", multirangeOID: 4535)] Date = 7, /// /// Corresponds to the PostgreSQL "time" type. /// /// See https://www.postgresql.org/docs/current/static/datatype-datetime.html [BuiltInPostgresType("time", baseOID: 1083, arrayOID: 1183)] Time = 20, /// /// Corresponds to the PostgreSQL "timestamp" type. /// /// See https://www.postgresql.org/docs/current/static/datatype-datetime.html [BuiltInPostgresType("timestamp", baseOID: 1114, arrayOID: 1115, rangeName: "tsrange", rangeOID: 3908, multirangeName: "tsmultirange", multirangeOID: 4533)] Timestamp = 21, /// /// Corresponds to the PostgreSQL "timestamp with time zone" type. /// /// See https://www.postgresql.org/docs/current/static/datatype-datetime.html [Obsolete("Use TimestampTz instead")] // NOTE: Don't remove this (see #1694) TimestampTZ = TimestampTz, /// /// Corresponds to the PostgreSQL "timestamp with time zone" type. /// /// See https://www.postgresql.org/docs/current/static/datatype-datetime.html [BuiltInPostgresType("timestamptz", baseOID: 1184, arrayOID: 1185, rangeName: "tstzrange", rangeOID: 3910, multirangeName: "tstzmultirange", multirangeOID: 4534)] TimestampTz = 26, /// /// Corresponds to the PostgreSQL "interval" type. /// /// See https://www.postgresql.org/docs/current/static/datatype-datetime.html [BuiltInPostgresType("interval", baseOID: 1186, arrayOID: 1187)] Interval = 30, /// /// Corresponds to the PostgreSQL "time with time zone" type. /// /// See https://www.postgresql.org/docs/current/static/datatype-datetime.html [Obsolete("Use TimeTz instead")] // NOTE: Don't remove this (see #1694) TimeTZ = TimeTz, /// /// Corresponds to the PostgreSQL "time with time zone" type. /// /// See https://www.postgresql.org/docs/current/static/datatype-datetime.html [BuiltInPostgresType("timetz", baseOID: 1266, arrayOID: 1270)] TimeTz = 31, /// /// Corresponds to the obsolete PostgreSQL "abstime" type. /// /// See https://www.postgresql.org/docs/current/static/datatype-datetime.html [Obsolete("The PostgreSQL abstime time is obsolete.")] Abstime = 33, #endregion #region Network Address Types /// /// Corresponds to the PostgreSQL "inet" type. /// /// See https://www.postgresql.org/docs/current/static/datatype-net-types.html [BuiltInPostgresType("inet", baseOID: 869, arrayOID: 1041)] Inet = 24, /// /// Corresponds to the PostgreSQL "cidr" type, a field storing an IPv4 or IPv6 network. /// /// See https://www.postgresql.org/docs/current/static/datatype-net-types.html [BuiltInPostgresType("cidr", baseOID: 650, arrayOID: 651)] Cidr = 44, /// /// Corresponds to the PostgreSQL "macaddr" type, a field storing a 6-byte physical address. /// /// See https://www.postgresql.org/docs/current/static/datatype-net-types.html [BuiltInPostgresType("macaddr", baseOID: 829, arrayOID: 1040)] MacAddr = 34, /// /// Corresponds to the PostgreSQL "macaddr8" type, a field storing a 6-byte or 8-byte physical address. /// /// See https://www.postgresql.org/docs/current/static/datatype-net-types.html [BuiltInPostgresType("macaddr8", baseOID: 774, arrayOID: 775)] MacAddr8 = 54, #endregion #region Bit String Types /// /// Corresponds to the PostgreSQL "bit" type. /// /// See https://www.postgresql.org/docs/current/static/datatype-bit.html [BuiltInPostgresType("bit", baseOID: 1560, arrayOID: 1561)] Bit = 25, /// /// Corresponds to the PostgreSQL "varbit" type, a field storing a variable-length string of bits. /// /// See https://www.postgresql.org/docs/current/static/datatype-boolean.html [BuiltInPostgresType("varbit", baseOID: 1562, arrayOID: 1563)] Varbit = 39, #endregion #region Text Search Types /// /// Corresponds to the PostgreSQL "tsvector" type. /// /// See https://www.postgresql.org/docs/current/static/datatype-textsearch.html [BuiltInPostgresType("tsvector", baseOID: 3614, arrayOID: 3643)] TsVector = 45, /// /// Corresponds to the PostgreSQL "tsquery" type. /// /// See https://www.postgresql.org/docs/current/static/datatype-textsearch.html [BuiltInPostgresType("tsquery", baseOID: 3615, arrayOID: 3645)] TsQuery = 46, /// /// Corresponds to the PostgreSQL "regconfig" type. /// /// See https://www.postgresql.org/docs/current/static/datatype-textsearch.html [BuiltInPostgresType("regconfig", baseOID: 3734, arrayOID: 3735)] Regconfig = 56, #endregion #region UUID Type /// /// Corresponds to the PostgreSQL "uuid" type. /// /// See https://www.postgresql.org/docs/current/static/datatype-uuid.html [BuiltInPostgresType("uuid", baseOID: 2950, arrayOID: 2951)] Uuid = 27, #endregion #region XML Type /// /// Corresponds to the PostgreSQL "xml" type. /// /// See https://www.postgresql.org/docs/current/static/datatype-xml.html [BuiltInPostgresType("xml", baseOID: 142, arrayOID: 143)] Xml = 28, #endregion #region JSON Types /// /// Corresponds to the PostgreSQL "json" type, a field storing JSON in text format. /// /// See https://www.postgresql.org/docs/current/static/datatype-json.html /// [BuiltInPostgresType("json", baseOID: 114, arrayOID: 199)] Json = 35, /// /// Corresponds to the PostgreSQL "jsonb" type, a field storing JSON in an optimized binary. /// format. /// /// /// Supported since PostgreSQL 9.4. /// See https://www.postgresql.org/docs/current/static/datatype-json.html /// [BuiltInPostgresType("jsonb", baseOID: 3802, arrayOID: 3807)] Jsonb = 36, /// /// Corresponds to the PostgreSQL "jsonpath" type, a field storing JSON path in text format. /// format. /// /// /// Supported since PostgreSQL 12. /// See https://www.postgresql.org/docs/current/datatype-json.html#DATATYPE-JSONPATH /// [BuiltInPostgresType("jsonpath", baseOID: 4072, arrayOID: 4073)] JsonPath = 57, #endregion #region HSTORE Type /// /// Corresponds to the PostgreSQL "hstore" type, a dictionary of string key-value pairs. /// /// See https://www.postgresql.org/docs/current/static/hstore.html Hstore = 37, // Extension type #endregion #region Internal Types /// /// Corresponds to the PostgreSQL "refcursor" type. /// [BuiltInPostgresType("refcursor", baseOID: 1790, arrayOID: 2201)] Refcursor = 23, /// /// Corresponds to the PostgreSQL internal "oidvector" type. /// /// See https://www.postgresql.org/docs/current/static/datatype-oid.html [BuiltInPostgresType("oidvector", baseOID: 30, arrayOID: 1013)] Oidvector = 29, /// /// Corresponds to the PostgreSQL internal "int2vector" type. /// [BuiltInPostgresType("int2vector", baseOID: 22, arrayOID: 1006)] Int2Vector = 52, /// /// Corresponds to the PostgreSQL "oid" type. /// /// See https://www.postgresql.org/docs/current/static/datatype-oid.html [BuiltInPostgresType("oid", baseOID: 26, arrayOID: 1028)] Oid = 41, /// /// Corresponds to the PostgreSQL "xid" type, an internal transaction identifier. /// /// See https://www.postgresql.org/docs/current/static/datatype-oid.html [BuiltInPostgresType("xid", baseOID: 28, arrayOID: 1011)] Xid = 42, /// /// Corresponds to the PostgreSQL "xid8" type, an internal transaction identifier. /// /// See https://www.postgresql.org/docs/current/static/datatype-oid.html [BuiltInPostgresType("xid8", baseOID: 5069, arrayOID: 271)] Xid8 = 64, /// /// Corresponds to the PostgreSQL "cid" type, an internal command identifier. /// /// See https://www.postgresql.org/docs/current/static/datatype-oid.html [BuiltInPostgresType("cid", baseOID: 29, arrayOID: 1012)] Cid = 43, /// /// Corresponds to the PostgreSQL "regtype" type, a numeric (OID) ID of a type in the pg_type table. /// [BuiltInPostgresType("regtype", baseOID: 2206, arrayOID: 2211)] Regtype = 49, /// /// Corresponds to the PostgreSQL "tid" type, a tuple id identifying the physical location of a row within its table. /// [BuiltInPostgresType("tid", baseOID: 27, arrayOID: 1010)] Tid = 53, /// /// Corresponds to the PostgreSQL "pg_lsn" type, which can be used to store LSN (Log Sequence Number) data which /// is a pointer to a location in the WAL. /// /// /// See: https://www.postgresql.org/docs/current/datatype-pg-lsn.html and /// https://git.postgresql.org/gitweb/?p=postgresql.git;a=commit;h=7d03a83f4d0736ba869fa6f93973f7623a27038a /// [BuiltInPostgresType("pg_lsn", baseOID: 3220, arrayOID: 3221)] PgLsn = 59, #endregion #region Special /// /// A special value that can be used to send parameter values to the database without /// specifying their type, allowing the database to cast them to another value based on context. /// The value will be converted to a string and send as text. /// /// /// This value shouldn't ordinarily be used, and makes sense only when sending a data type /// unsupported by Npgsql. /// [BuiltInPostgresType("unknown", baseOID: 705, arrayOID: 0)] Unknown = 40, #endregion #region PostGIS /// /// The geometry type for PostgreSQL spatial extension PostGIS. /// Geometry = 50, // Extension type /// /// The geography (geodetic) type for PostgreSQL spatial extension PostGIS. /// Geography = 55, // Extension type #endregion #region Label tree types /// /// The PostgreSQL ltree type, each value is a label path "a.label.tree.value", forming a tree in a set. /// /// See https://www.postgresql.org/docs/current/static/ltree.html LTree = 60, // Extension type /// /// The PostgreSQL lquery type for PostgreSQL extension ltree /// /// See https://www.postgresql.org/docs/current/static/ltree.html LQuery = 61, // Extension type /// /// The PostgreSQL ltxtquery type for PostgreSQL extension ltree /// /// See https://www.postgresql.org/docs/current/static/ltree.html LTxtQuery = 62, // Extension type #endregion #region Range types /// /// Corresponds to the PostgreSQL "int4range" type. /// IntegerRange = Range | Integer, /// /// Corresponds to the PostgreSQL "int8range" type. /// BigIntRange = Range | Bigint, /// /// Corresponds to the PostgreSQL "numrange" type. /// NumericRange = Range | Numeric, /// /// Corresponds to the PostgreSQL "tsrange" type. /// TimestampRange = Range | Timestamp, /// /// Corresponds to the PostgreSQL "tstzrange" type. /// TimestampTzRange = Range | TimestampTz, /// /// Corresponds to the PostgreSQL "daterange" type. /// DateRange = Range | Date, #endregion Range types #region Multirange types /// /// Corresponds to the PostgreSQL "int4multirange" type. /// IntegerMultirange = Multirange | Integer, /// /// Corresponds to the PostgreSQL "int8multirange" type. /// BigIntMultirange = Multirange | Bigint, /// /// Corresponds to the PostgreSQL "nummultirange" type. /// NumericMultirange = Multirange | Numeric, /// /// Corresponds to the PostgreSQL "tsmultirange" type. /// TimestampMultirange = Multirange | Timestamp, /// /// Corresponds to the PostgreSQL "tstzmultirange" type. /// TimestampTzMultirange = Multirange | TimestampTz, /// /// Corresponds to the PostgreSQL "datemultirange" type. /// DateMultirange = Multirange | Date, #endregion Multirange types #region Composables /// /// Corresponds to the PostgreSQL "array" type, a variable-length multidimensional array of /// another type. This value must be combined with another value from /// via a bit OR (e.g. NpgsqlDbType.Array | NpgsqlDbType.Integer) /// /// See https://www.postgresql.org/docs/current/static/arrays.html Array = int.MinValue, /// /// Corresponds to the PostgreSQL "range" type, continuous range of values of specific type. /// This value must be combined with another value from /// via a bit OR (e.g. NpgsqlDbType.Range | NpgsqlDbType.Integer) /// /// /// Supported since PostgreSQL 9.2. /// See https://www.postgresql.org/docs/current/static/rangetypes.html /// Range = 0x40000000, /// /// Corresponds to the PostgreSQL "multirange" type, continuous range of values of specific type. /// This value must be combined with another value from /// via a bit OR (e.g. NpgsqlDbType.Multirange | NpgsqlDbType.Integer) /// /// /// Supported since PostgreSQL 14. /// See https://www.postgresql.org/docs/current/static/rangetypes.html /// Multirange = 0x20000000, #endregion } /// /// Represents a built-in PostgreSQL type as it appears in pg_type, including its name and OID. /// Extension types with variable OIDs are not represented. /// class BuiltInPostgresType : Attribute { internal string Name { get; } internal uint BaseOID { get; } internal uint ArrayOID { get; } internal string? RangeName { get; } internal uint RangeOID { get; } internal string? MultirangeName { get; } internal uint MultirangeOID { get; } internal BuiltInPostgresType(string name, uint baseOID, uint arrayOID) { Name = name; BaseOID = baseOID; ArrayOID = arrayOID; } internal BuiltInPostgresType( string name, uint baseOID, uint arrayOID, string rangeName, uint rangeOID, string multirangeName, uint multirangeOID) { Name = name; BaseOID = baseOID; ArrayOID = arrayOID; RangeName = rangeName; RangeOID = rangeOID; MultirangeName = multirangeName; MultirangeOID = multirangeOID; } }