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
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", PostgresTypeOIDs.Int8)]
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", PostgresTypeOIDs.Float8)]
Double = 8,
///
/// Corresponds to the PostgreSQL 4-byte "integer" type.
///
/// See https://www.postgresql.org/docs/current/static/datatype-numeric.html
[BuiltInPostgresType("int4", PostgresTypeOIDs.Int4)]
Integer = 9,
///
/// Corresponds to the PostgreSQL arbitrary-precision "numeric" type.
///
/// See https://www.postgresql.org/docs/current/static/datatype-numeric.html
[BuiltInPostgresType("numeric", PostgresTypeOIDs.Numeric)]
Numeric = 13,
///
/// Corresponds to the PostgreSQL floating-point "real" type.
///
/// See https://www.postgresql.org/docs/current/static/datatype-numeric.html
[BuiltInPostgresType("float4", PostgresTypeOIDs.Float4)]
Real = 17,
///
/// Corresponds to the PostgreSQL 2-byte "smallint" type.
///
/// See https://www.postgresql.org/docs/current/static/datatype-numeric.html
[BuiltInPostgresType("int2", PostgresTypeOIDs.Int2)]
Smallint = 18,
///
/// Corresponds to the PostgreSQL "money" type.
///
/// See https://www.postgresql.org/docs/current/static/datatype-money.html
[BuiltInPostgresType("money", PostgresTypeOIDs.Money)]
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", PostgresTypeOIDs.Bool)]
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", PostgresTypeOIDs.Box)]
Box = 3,
///
/// Corresponds to the PostgreSQL geometric "circle" type.
///
/// See https://www.postgresql.org/docs/current/static/datatype-geometric.html
[BuiltInPostgresType("circle", PostgresTypeOIDs.Circle)]
Circle = 5,
///
/// Corresponds to the PostgreSQL geometric "line" type.
///
/// See https://www.postgresql.org/docs/current/static/datatype-geometric.html
[BuiltInPostgresType("line", PostgresTypeOIDs.Line)]
Line = 10,
///
/// Corresponds to the PostgreSQL geometric "lseg" type.
///
/// See https://www.postgresql.org/docs/current/static/datatype-geometric.html
[BuiltInPostgresType("lseg", PostgresTypeOIDs.LSeg)]
LSeg = 11,
///
/// Corresponds to the PostgreSQL geometric "path" type.
///
/// See https://www.postgresql.org/docs/current/static/datatype-geometric.html
[BuiltInPostgresType("path", PostgresTypeOIDs.Path)]
Path = 14,
///
/// Corresponds to the PostgreSQL geometric "point" type.
///
/// See https://www.postgresql.org/docs/current/static/datatype-geometric.html
[BuiltInPostgresType("point", PostgresTypeOIDs.Point)]
Point = 15,
///
/// Corresponds to the PostgreSQL geometric "polygon" type.
///
/// See https://www.postgresql.org/docs/current/static/datatype-geometric.html
[BuiltInPostgresType("polygon", PostgresTypeOIDs.Polygon)]
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", PostgresTypeOIDs.BPChar)]
Char = 6,
///
/// Corresponds to the PostgreSQL "text" type.
///
/// See https://www.postgresql.org/docs/current/static/datatype-character.html
[BuiltInPostgresType("text", PostgresTypeOIDs.Text)]
Text = 19,
///
/// Corresponds to the PostgreSQL "varchar" type.
///
/// See https://www.postgresql.org/docs/current/static/datatype-character.html
[BuiltInPostgresType("varchar", PostgresTypeOIDs.Varchar)]
Varchar = 22,
///
/// Corresponds to the PostgreSQL internal "name" type.
///
/// See https://www.postgresql.org/docs/current/static/datatype-character.html
[BuiltInPostgresType("name", PostgresTypeOIDs.Name)]
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", PostgresTypeOIDs.Char)]
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", PostgresTypeOIDs.Bytea)]
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", PostgresTypeOIDs.Date)]
Date = 7,
///
/// Corresponds to the PostgreSQL "time" type.
///
/// See https://www.postgresql.org/docs/current/static/datatype-datetime.html
[BuiltInPostgresType("time", PostgresTypeOIDs.Time)]
Time = 20,
///
/// Corresponds to the PostgreSQL "timestamp" type.
///
/// See https://www.postgresql.org/docs/current/static/datatype-datetime.html
[BuiltInPostgresType("timestamp", PostgresTypeOIDs.Timestamp)]
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", PostgresTypeOIDs.TimestampTz)]
TimestampTz = 26,
///
/// Corresponds to the PostgreSQL "interval" type.
///
/// See https://www.postgresql.org/docs/current/static/datatype-datetime.html
[BuiltInPostgresType("interval", PostgresTypeOIDs.Interval)]
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", PostgresTypeOIDs.TimeTz)]
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.")]
[BuiltInPostgresType("abstime", PostgresTypeOIDs.Abstime)]
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", PostgresTypeOIDs.Inet)]
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", PostgresTypeOIDs.Cidr)]
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", PostgresTypeOIDs.Macaddr)]
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", PostgresTypeOIDs.Macaddr8)]
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", PostgresTypeOIDs.Bit)]
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", PostgresTypeOIDs.Varbit)]
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", PostgresTypeOIDs.TsVector)]
TsVector = 45,
///
/// Corresponds to the PostgreSQL "tsquery" type.
///
/// See https://www.postgresql.org/docs/current/static/datatype-textsearch.html
[BuiltInPostgresType("tsquery", PostgresTypeOIDs.TsQuery)]
TsQuery = 46,
///
/// Corresponds to the PostgreSQL "regconfig" type.
///
/// See https://www.postgresql.org/docs/current/static/datatype-textsearch.html
[BuiltInPostgresType("regconfig", PostgresTypeOIDs.Regconfig)]
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", PostgresTypeOIDs.Uuid)]
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", PostgresTypeOIDs.Xml)]
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", PostgresTypeOIDs.Json)]
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", PostgresTypeOIDs.Jsonb)]
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", PostgresTypeOIDs.JsonPath)]
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", PostgresTypeOIDs.Refcursor)]
Refcursor = 23,
///
/// Corresponds to the PostgreSQL internal "oidvector" type.
///
/// See https://www.postgresql.org/docs/current/static/datatype-oid.html
[BuiltInPostgresType("oidvector", PostgresTypeOIDs.Oidvector)]
Oidvector = 29,
///
/// Corresponds to the PostgreSQL internal "int2vector" type.
///
[BuiltInPostgresType("int2vector", PostgresTypeOIDs.Int2vector)]
Int2Vector = 52,
///
/// Corresponds to the PostgreSQL "oid" type.
///
/// See https://www.postgresql.org/docs/current/static/datatype-oid.html
[BuiltInPostgresType("oid", PostgresTypeOIDs.Oid)]
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", PostgresTypeOIDs.Xid)]
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", PostgresTypeOIDs.Xid8)]
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", PostgresTypeOIDs.Cid)]
Cid = 43,
///
/// Corresponds to the PostgreSQL "regtype" type, a numeric (OID) ID of a type in the pg_type table.
///
[BuiltInPostgresType("regtype", PostgresTypeOIDs.Regtype)]
Regtype = 49,
///
/// Corresponds to the PostgreSQL "tid" type, a tuple id identifying the physical location of a row within its table.
///
[BuiltInPostgresType("tid", PostgresTypeOIDs.Tid)]
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", PostgresTypeOIDs.PgLsn)]
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", PostgresTypeOIDs.Unknown)]
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 http://www.postgresql.org/docs/current/static/ltree.html
LTree = 60, // Extension type
///
/// The PostgreSQL lquery type for PostgreSQL extension ltree
///
/// See http://www.postgresql.org/docs/current/static/ltree.html
LQuery = 61, // Extension type
///
/// The PostgreSQL ltxtquery type for PostgreSQL extension ltree
///
/// See http://www.postgresql.org/docs/current/static/ltree.html
LTxtQuery = 62, // Extension type
#endregion
#region Range types
///
/// Corresponds to the PostgreSQL "int4range" type.
///
[BuiltInPostgresType("int4range", PostgresTypeOIDs.Int4Range)]
IntegerRange = Range | Integer,
///
/// Corresponds to the PostgreSQL "int8range" type.
///
[BuiltInPostgresType("int8range", PostgresTypeOIDs.Int8Range)]
BigIntRange = Range | Bigint,
///
/// Corresponds to the PostgreSQL "numrange" type.
///
[BuiltInPostgresType("numrange", PostgresTypeOIDs.NumRange)]
NumericRange = Range | Numeric,
///
/// Corresponds to the PostgreSQL "tsrange" type.
///
[BuiltInPostgresType("tsrange", PostgresTypeOIDs.TsRange)]
TimestampRange = Range | Timestamp,
///
/// Corresponds to the PostgreSQL "tstzrange" type.
///
[BuiltInPostgresType("tstzrange", PostgresTypeOIDs.TsTzRange)]
TimestampTzRange = Range | TimestampTz,
///
/// Corresponds to the PostgreSQL "daterange" type.
///
[BuiltInPostgresType("daterange", PostgresTypeOIDs.DateRange)]
DateRange = Range | Date,
#endregion Range types
#region Multirange types
///
/// Corresponds to the PostgreSQL "int4multirange" type.
///
[BuiltInPostgresType("int4multirange", PostgresTypeOIDs.Int4Multirange)]
IntegerMultirange = Multirange | Integer,
///
/// Corresponds to the PostgreSQL "int8multirange" type.
///
[BuiltInPostgresType("int8multirange", PostgresTypeOIDs.Int8Multirange)]
BigIntMultirange = Multirange | Bigint,
///
/// Corresponds to the PostgreSQL "nummultirange" type.
///
[BuiltInPostgresType("nummultirange", PostgresTypeOIDs.NumMultirange)]
NumericMultirange = Multirange | Numeric,
///
/// Corresponds to the PostgreSQL "tsmultirange" type.
///
[BuiltInPostgresType("tsmultirange", PostgresTypeOIDs.TsMultirange)]
TimestampMultirange = Multirange | Timestamp,
///
/// Corresponds to the PostgreSQL "tstzmultirange" type.
///
[BuiltInPostgresType("tstzmultirange", PostgresTypeOIDs.TsTzMultirange)]
TimestampTzMultirange = Multirange | TimestampTz,
///
/// Corresponds to the PostgreSQL "datemultirange" type.
///
[BuiltInPostgresType("datemultirange", PostgresTypeOIDs.DateMultirange)]
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 OID { get; }
internal BuiltInPostgresType(string name, uint oid)
{
Name = name;
OID = oid;
}
}