From ed789cfad81f61268b9fd44384caab9d6ac8484f Mon Sep 17 00:00:00 2001 From: Steven Fackler Date: Sun, 21 Feb 2016 13:30:31 -0800 Subject: [PATCH] Use persistent codegen for SqlState and Type Makes it easier to detect changes and speeds up the build. --- .gitignore | 2 +- Cargo.toml | 7 +- codegen/Cargo.toml | 8 + {build => codegen/src}/errcodes.txt | 0 {build => codegen/src}/main.rs | 8 +- {build => codegen/src}/pg_range.h | 0 {build => codegen/src}/pg_type.h | 0 {build => codegen/src}/sqlstate.rs | 9 +- {build => codegen/src}/types.rs | 8 +- src/{error.rs => error/mod.rs} | 2 +- src/error/sqlstate.rs | 1022 ++++++++++++++++++ src/types/mod.rs | 2 +- src/types/types.rs | 1477 +++++++++++++++++++++++++++ 13 files changed, 2519 insertions(+), 26 deletions(-) create mode 100644 codegen/Cargo.toml rename {build => codegen/src}/errcodes.txt (100%) rename {build => codegen/src}/main.rs (82%) rename {build => codegen/src}/pg_range.h (100%) rename {build => codegen/src}/pg_type.h (100%) rename {build => codegen/src}/sqlstate.rs (93%) rename {build => codegen/src}/types.rs (96%) rename src/{error.rs => error/mod.rs} (99%) create mode 100644 src/error/sqlstate.rs create mode 100644 src/types/types.rs diff --git a/.gitignore b/.gitignore index 957a3f8f..b163a8c7 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,3 @@ -/target/ +target/ Cargo.lock .cargo/ diff --git a/Cargo.toml b/Cargo.toml index 88d2a38e..aecf7777 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,8 +8,7 @@ repository = "https://github.com/sfackler/rust-postgres" documentation = "https://sfackler.github.io/rust-postgres/doc/v0.11.3/postgres" readme = "README.md" keywords = ["database", "postgres", "postgresql", "sql"] -build = "build/main.rs" -include = ["src/*", "build/*", "Cargo.toml", "LICENSE", "README.md", "THIRD_PARTY"] +include = ["src/*", "Cargo.toml", "LICENSE", "README.md", "THIRD_PARTY"] [lib] name = "postgres" @@ -21,10 +20,6 @@ bench = false name = "test" path = "tests/test.rs" -[build-dependencies] -phf_codegen = "0.7" -regex = "0.1" - [dependencies] bufstream = "0.1" byteorder = ">= 0.3, < 0.5" diff --git a/codegen/Cargo.toml b/codegen/Cargo.toml new file mode 100644 index 00000000..1d17c33f --- /dev/null +++ b/codegen/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "codegen" +version = "0.1.0" +authors = ["Steven Fackler "] + +[dependencies] +phf_codegen = "0.7" +regex = "0.1" diff --git a/build/errcodes.txt b/codegen/src/errcodes.txt similarity index 100% rename from build/errcodes.txt rename to codegen/src/errcodes.txt diff --git a/build/main.rs b/codegen/src/main.rs similarity index 82% rename from build/main.rs rename to codegen/src/main.rs index 816d668f..affb3749 100644 --- a/build/main.rs +++ b/codegen/src/main.rs @@ -2,15 +2,15 @@ extern crate phf_codegen; extern crate regex; use std::ascii::AsciiExt; +use std::path::Path; mod sqlstate; mod types; fn main() { - sqlstate::build(); - types::build(); - - println!("cargo:rerun-if-changed=build"); + let path = Path::new("../src"); + sqlstate::build(path); + types::build(path); } fn snake_to_camel(s: &str) -> String { diff --git a/build/pg_range.h b/codegen/src/pg_range.h similarity index 100% rename from build/pg_range.h rename to codegen/src/pg_range.h diff --git a/build/pg_type.h b/codegen/src/pg_type.h similarity index 100% rename from build/pg_type.h rename to codegen/src/pg_type.h diff --git a/build/sqlstate.rs b/codegen/src/sqlstate.rs similarity index 93% rename from build/sqlstate.rs rename to codegen/src/sqlstate.rs index 052df048..419778a4 100644 --- a/build/sqlstate.rs +++ b/codegen/src/sqlstate.rs @@ -1,8 +1,6 @@ -use std::env; use std::fs::File; use std::io::{Write, BufWriter}; use std::path::Path; -use std::convert::AsRef; use phf_codegen; use snake_to_camel; @@ -14,11 +12,8 @@ struct Code { variant: String, } -pub fn build() { - let path = env::var_os("OUT_DIR").unwrap(); - let path: &Path = path.as_ref(); - let path = path.join("sqlstate.rs"); - let mut file = BufWriter::new(File::create(&path).unwrap()); +pub fn build(path: &Path) { + let mut file = BufWriter::new(File::create(path.join("error/sqlstate.rs")).unwrap()); let codes = parse_codes(); diff --git a/build/types.rs b/codegen/src/types.rs similarity index 96% rename from build/types.rs rename to codegen/src/types.rs index a00516d8..658acc6e 100644 --- a/build/types.rs +++ b/codegen/src/types.rs @@ -1,7 +1,6 @@ use regex::Regex; use std::ascii::AsciiExt; use std::collections::BTreeMap; -use std::env; use std::fs::File; use std::io::{Write, BufWriter}; use std::path::Path; @@ -19,11 +18,8 @@ struct Type { doc: String, } -pub fn build() { - let path = env::var_os("OUT_DIR").unwrap(); - let path: &Path = path.as_ref(); - let path = path.join("type.rs"); - let mut file = BufWriter::new(File::create(&path).unwrap()); +pub fn build(path: &Path) { + let mut file = BufWriter::new(File::create(path.join("types/types.rs")).unwrap()); let ranges = parse_ranges(); let types = parse_types(&ranges); diff --git a/src/error.rs b/src/error/mod.rs similarity index 99% rename from src/error.rs rename to src/error/mod.rs index 78f555e9..d676c333 100644 --- a/src/error.rs +++ b/src/error/mod.rs @@ -11,7 +11,7 @@ use std::collections::HashMap; use {Result, DbErrorNew}; -include!(concat!(env!("OUT_DIR"), "/sqlstate.rs")); +include!("sqlstate.rs"); /// A Postgres error or notice. #[derive(Clone, PartialEq, Eq)] diff --git a/src/error/sqlstate.rs b/src/error/sqlstate.rs new file mode 100644 index 00000000..a3f38893 --- /dev/null +++ b/src/error/sqlstate.rs @@ -0,0 +1,1022 @@ +/// SQLSTATE error codes +#[derive(PartialEq, Eq, Clone, Debug)] +pub enum SqlState { + /// `00000` + SuccessfulCompletion, + /// `01000` + Warning, + /// `0100C` + DynamicResultSetsReturned, + /// `01008` + ImplicitZeroBitPadding, + /// `01003` + NullValueEliminatedInSetFunction, + /// `01007` + PrivilegeNotGranted, + /// `01006` + PrivilegeNotRevoked, + /// `01004` + WarningStringDataRightTruncation, + /// `01P01` + DeprecatedFeature, + /// `02000` + NoData, + /// `02001` + NoAdditionalDynamicResultSetsReturned, + /// `03000` + SqlStatementNotYetComplete, + /// `08000` + ConnectionException, + /// `08003` + ConnectionDoesNotExist, + /// `08006` + ConnectionFailure, + /// `08001` + SqlclientUnableToEstablishSqlconnection, + /// `08004` + SqlserverRejectedEstablishmentOfSqlconnection, + /// `08007` + TransactionResolutionUnknown, + /// `08P01` + ProtocolViolation, + /// `09000` + TriggeredActionException, + /// `0A000` + FeatureNotSupported, + /// `0B000` + InvalidTransactionInitiation, + /// `0F000` + LocatorException, + /// `0F001` + InvalidLocatorSpecification, + /// `0L000` + InvalidGrantor, + /// `0LP01` + InvalidGrantOperation, + /// `0P000` + InvalidRoleSpecification, + /// `0Z000` + DiagnosticsException, + /// `0Z002` + StackedDiagnosticsAccessedWithoutActiveHandler, + /// `20000` + CaseNotFound, + /// `21000` + CardinalityViolation, + /// `22000` + DataException, + /// `2202E` + ArraySubscriptError, + /// `22021` + CharacterNotInRepertoire, + /// `22008` + DatetimeFieldOverflow, + /// `22012` + DivisionByZero, + /// `22005` + ErrorInAssignment, + /// `2200B` + EscapeCharacterConflict, + /// `22022` + IndicatorOverflow, + /// `22015` + IntervalFieldOverflow, + /// `2201E` + InvalidArgumentForLogarithm, + /// `22014` + InvalidArgumentForNtileFunction, + /// `22016` + InvalidArgumentForNthValueFunction, + /// `2201F` + InvalidArgumentForPowerFunction, + /// `2201G` + InvalidArgumentForWidthBucketFunction, + /// `22018` + InvalidCharacterValueForCast, + /// `22007` + InvalidDatetimeFormat, + /// `22019` + InvalidEscapeCharacter, + /// `2200D` + InvalidEscapeOctet, + /// `22025` + InvalidEscapeSequence, + /// `22P06` + NonstandardUseOfEscapeCharacter, + /// `22010` + InvalidIndicatorParameterValue, + /// `22023` + InvalidParameterValue, + /// `2201B` + InvalidRegularExpression, + /// `2201W` + InvalidRowCountInLimitClause, + /// `2201X` + InvalidRowCountInResultOffsetClause, + /// `2202H` + InvalidTablesampleArgument, + /// `2202G` + InvalidTablesampleRepeat, + /// `22009` + InvalidTimeZoneDisplacementValue, + /// `2200C` + InvalidUseOfEscapeCharacter, + /// `2200G` + MostSpecificTypeMismatch, + /// `22004` + DataNullValueNotAllowed, + /// `22002` + NullValueNoIndicatorParameter, + /// `22003` + NumericValueOutOfRange, + /// `22026` + StringDataLengthMismatch, + /// `22001` + DataStringDataRightTruncation, + /// `22011` + SubstringError, + /// `22027` + TrimError, + /// `22024` + UnterminatedCString, + /// `2200F` + ZeroLengthCharacterString, + /// `22P01` + FloatingPointException, + /// `22P02` + InvalidTextRepresentation, + /// `22P03` + InvalidBinaryRepresentation, + /// `22P04` + BadCopyFileFormat, + /// `22P05` + UntranslatableCharacter, + /// `2200L` + NotAnXmlDocument, + /// `2200M` + InvalidXmlDocument, + /// `2200N` + InvalidXmlContent, + /// `2200S` + InvalidXmlComment, + /// `2200T` + InvalidXmlProcessingInstruction, + /// `23000` + IntegrityConstraintViolation, + /// `23001` + RestrictViolation, + /// `23502` + NotNullViolation, + /// `23503` + ForeignKeyViolation, + /// `23505` + UniqueViolation, + /// `23514` + CheckViolation, + /// `23P01` + ExclusionViolation, + /// `24000` + InvalidCursorState, + /// `25000` + InvalidTransactionState, + /// `25001` + ActiveSqlTransaction, + /// `25002` + BranchTransactionAlreadyActive, + /// `25008` + HeldCursorRequiresSameIsolationLevel, + /// `25003` + InappropriateAccessModeForBranchTransaction, + /// `25004` + InappropriateIsolationLevelForBranchTransaction, + /// `25005` + NoActiveSqlTransactionForBranchTransaction, + /// `25006` + ReadOnlySqlTransaction, + /// `25007` + SchemaAndDataStatementMixingNotSupported, + /// `25P01` + NoActiveSqlTransaction, + /// `25P02` + InFailedSqlTransaction, + /// `26000` + InvalidSqlStatementName, + /// `27000` + TriggeredDataChangeViolation, + /// `28000` + InvalidAuthorizationSpecification, + /// `28P01` + InvalidPassword, + /// `2B000` + DependentPrivilegeDescriptorsStillExist, + /// `2BP01` + DependentObjectsStillExist, + /// `2D000` + InvalidTransactionTermination, + /// `2F000` + SqlRoutineException, + /// `2F005` + FunctionExecutedNoReturnStatement, + /// `2F002` + SqlRoutineModifyingSqlDataNotPermitted, + /// `2F003` + SqlRoutineProhibitedSqlStatementAttempted, + /// `2F004` + SqlRoutineReadingSqlDataNotPermitted, + /// `34000` + InvalidCursorName, + /// `38000` + ExternalRoutineException, + /// `38001` + ContainingSqlNotPermitted, + /// `38002` + ForeignRoutineModifyingSqlDataNotPermitted, + /// `38003` + ForeignRoutineProhibitedSqlStatementAttempted, + /// `38004` + ForeignRoutineReadingSqlDataNotPermitted, + /// `39000` + ExternalRoutineInvocationException, + /// `39001` + InvalidSqlstateReturned, + /// `39004` + ExternalRoutineInvocationNullValueNotAllowed, + /// `39P01` + TriggerProtocolViolated, + /// `39P02` + SrfProtocolViolated, + /// `39P03` + EventTriggerProtocolViolated, + /// `3B000` + SavepointException, + /// `3B001` + InvalidSavepointSpecification, + /// `3D000` + InvalidCatalogName, + /// `3F000` + InvalidSchemaName, + /// `40000` + TransactionRollback, + /// `40002` + TransactionIntegrityConstraintViolation, + /// `40001` + SerializationFailure, + /// `40003` + StatementCompletionUnknown, + /// `40P01` + DeadlockDetected, + /// `42000` + SyntaxErrorOrAccessRuleViolation, + /// `42601` + SyntaxError, + /// `42501` + InsufficientPrivilege, + /// `42846` + CannotCoerce, + /// `42803` + GroupingError, + /// `42P20` + WindowingError, + /// `42P19` + InvalidRecursion, + /// `42830` + InvalidForeignKey, + /// `42602` + InvalidName, + /// `42622` + NameTooLong, + /// `42939` + ReservedName, + /// `42804` + DatatypeMismatch, + /// `42P18` + IndeterminateDatatype, + /// `42P21` + CollationMismatch, + /// `42P22` + IndeterminateCollation, + /// `42809` + WrongObjectType, + /// `42703` + UndefinedColumn, + /// `42883` + UndefinedFunction, + /// `42P01` + UndefinedTable, + /// `42P02` + UndefinedParameter, + /// `42704` + UndefinedObject, + /// `42701` + DuplicateColumn, + /// `42P03` + DuplicateCursor, + /// `42P04` + DuplicateDatabase, + /// `42723` + DuplicateFunction, + /// `42P05` + DuplicatePreparedStatement, + /// `42P06` + DuplicateSchema, + /// `42P07` + DuplicateTable, + /// `42712` + DuplicateAlias, + /// `42710` + DuplicateObject, + /// `42702` + AmbiguousColumn, + /// `42725` + AmbiguousFunction, + /// `42P08` + AmbiguousParameter, + /// `42P09` + AmbiguousAlias, + /// `42P10` + InvalidColumnReference, + /// `42611` + InvalidColumnDefinition, + /// `42P11` + InvalidCursorDefinition, + /// `42P12` + InvalidDatabaseDefinition, + /// `42P13` + InvalidFunctionDefinition, + /// `42P14` + InvalidPreparedStatementDefinition, + /// `42P15` + InvalidSchemaDefinition, + /// `42P16` + InvalidTableDefinition, + /// `42P17` + InvalidObjectDefinition, + /// `44000` + WithCheckOptionViolation, + /// `53000` + InsufficientResources, + /// `53100` + DiskFull, + /// `53200` + OutOfMemory, + /// `53300` + TooManyConnections, + /// `53400` + ConfigurationLimitExceeded, + /// `54000` + ProgramLimitExceeded, + /// `54001` + StatementTooComplex, + /// `54011` + TooManyColumns, + /// `54023` + TooManyArguments, + /// `55000` + ObjectNotInPrerequisiteState, + /// `55006` + ObjectInUse, + /// `55P02` + CantChangeRuntimeParam, + /// `55P03` + LockNotAvailable, + /// `57000` + OperatorIntervention, + /// `57014` + QueryCanceled, + /// `57P01` + AdminShutdown, + /// `57P02` + CrashShutdown, + /// `57P03` + CannotConnectNow, + /// `57P04` + DatabaseDropped, + /// `58000` + SystemError, + /// `58030` + IoError, + /// `58P01` + UndefinedFile, + /// `58P02` + DuplicateFile, + /// `F0000` + ConfigFileError, + /// `F0001` + LockFileExists, + /// `HV000` + FdwError, + /// `HV005` + FdwColumnNameNotFound, + /// `HV002` + FdwDynamicParameterValueNeeded, + /// `HV010` + FdwFunctionSequenceError, + /// `HV021` + FdwInconsistentDescriptorInformation, + /// `HV024` + FdwInvalidAttributeValue, + /// `HV007` + FdwInvalidColumnName, + /// `HV008` + FdwInvalidColumnNumber, + /// `HV004` + FdwInvalidDataType, + /// `HV006` + FdwInvalidDataTypeDescriptors, + /// `HV091` + FdwInvalidDescriptorFieldIdentifier, + /// `HV00B` + FdwInvalidHandle, + /// `HV00C` + FdwInvalidOptionIndex, + /// `HV00D` + FdwInvalidOptionName, + /// `HV090` + FdwInvalidStringLengthOrBufferLength, + /// `HV00A` + FdwInvalidStringFormat, + /// `HV009` + FdwInvalidUseOfNullPointer, + /// `HV014` + FdwTooManyHandles, + /// `HV001` + FdwOutOfMemory, + /// `HV00P` + FdwNoSchemas, + /// `HV00J` + FdwOptionNameNotFound, + /// `HV00K` + FdwReplyHandle, + /// `HV00Q` + FdwSchemaNotFound, + /// `HV00R` + FdwTableNotFound, + /// `HV00L` + FdwUnableToCreateExecution, + /// `HV00M` + FdwUnableToCreateReply, + /// `HV00N` + FdwUnableToEstablishConnection, + /// `P0000` + PlpgsqlError, + /// `P0001` + RaiseException, + /// `P0002` + NoDataFound, + /// `P0003` + TooManyRows, + /// `P0004` + AssertFailure, + /// `XX000` + InternalError, + /// `XX001` + DataCorrupted, + /// `XX002` + IndexCorrupted, + /// An unknown code + Other(String) +} +static SQLSTATE_MAP: phf::Map<&'static str, SqlState> = ::phf::Map { + key: 1897749892740154578, + disps: &[ + (0, 10), + (1, 206), + (0, 38), + (0, 10), + (0, 0), + (1, 2), + (0, 43), + (0, 0), + (2, 4), + (0, 153), + (0, 34), + (0, 8), + (0, 29), + (0, 42), + (0, 52), + (0, 0), + (1, 51), + (2, 198), + (9, 158), + (1, 18), + (0, 19), + (0, 65), + (1, 118), + (1, 125), + (3, 235), + (0, 87), + (0, 21), + (3, 164), + (0, 3), + (4, 117), + (11, 120), + (0, 115), + (40, 222), + (0, 8), + (8, 124), + (1, 142), + (0, 0), + (0, 0), + (10, 78), + (1, 173), + (10, 37), + (2, 209), + (18, 30), + (1, 19), + (0, 10), + (0, 233), + (2, 149), + (0, 105), + ], + entries: &[ + ("42P03", SqlState::DuplicateCursor), + ("22019", SqlState::InvalidEscapeCharacter), + ("22022", SqlState::IndicatorOverflow), + ("25002", SqlState::BranchTransactionAlreadyActive), + ("2F004", SqlState::SqlRoutineReadingSqlDataNotPermitted), + ("23505", SqlState::UniqueViolation), + ("HV00J", SqlState::FdwOptionNameNotFound), + ("42P17", SqlState::InvalidObjectDefinition), + ("25000", SqlState::InvalidTransactionState), + ("08001", SqlState::SqlclientUnableToEstablishSqlconnection), + ("25008", SqlState::HeldCursorRequiresSameIsolationLevel), + ("2201E", SqlState::InvalidArgumentForLogarithm), + ("2200T", SqlState::InvalidXmlProcessingInstruction), + ("2200F", SqlState::ZeroLengthCharacterString), + ("HV002", SqlState::FdwDynamicParameterValueNeeded), + ("2201B", SqlState::InvalidRegularExpression), + ("22007", SqlState::InvalidDatetimeFormat), + ("3B001", SqlState::InvalidSavepointSpecification), + ("54023", SqlState::TooManyArguments), + ("25P02", SqlState::InFailedSqlTransaction), + ("2201X", SqlState::InvalidRowCountInResultOffsetClause), + ("23P01", SqlState::ExclusionViolation), + ("42P13", SqlState::InvalidFunctionDefinition), + ("42712", SqlState::DuplicateAlias), + ("39P02", SqlState::SrfProtocolViolated), + ("23503", SqlState::ForeignKeyViolation), + ("42P16", SqlState::InvalidTableDefinition), + ("42000", SqlState::SyntaxErrorOrAccessRuleViolation), + ("23000", SqlState::IntegrityConstraintViolation), + ("53400", SqlState::ConfigurationLimitExceeded), + ("38001", SqlState::ContainingSqlNotPermitted), + ("2200D", SqlState::InvalidEscapeOctet), + ("0B000", SqlState::InvalidTransactionInitiation), + ("HV007", SqlState::FdwInvalidColumnName), + ("42P15", SqlState::InvalidSchemaDefinition), + ("HV00A", SqlState::FdwInvalidStringFormat), + ("22026", SqlState::StringDataLengthMismatch), + ("22011", SqlState::SubstringError), + ("39P03", SqlState::EventTriggerProtocolViolated), + ("42P02", SqlState::UndefinedParameter), + ("XX000", SqlState::InternalError), + ("2200S", SqlState::InvalidXmlComment), + ("25007", SqlState::SchemaAndDataStatementMixingNotSupported), + ("42710", SqlState::DuplicateObject), + ("25P01", SqlState::NoActiveSqlTransaction), + ("2200N", SqlState::InvalidXmlContent), + ("01004", SqlState::WarningStringDataRightTruncation), + ("42703", SqlState::UndefinedColumn), + ("42P07", SqlState::DuplicateTable), + ("26000", SqlState::InvalidSqlStatementName), + ("01003", SqlState::NullValueEliminatedInSetFunction), + ("22001", SqlState::DataStringDataRightTruncation), + ("22012", SqlState::DivisionByZero), + ("2F005", SqlState::FunctionExecutedNoReturnStatement), + ("55P02", SqlState::CantChangeRuntimeParam), + ("39P01", SqlState::TriggerProtocolViolated), + ("3F000", SqlState::InvalidSchemaName), + ("42501", SqlState::InsufficientPrivilege), + ("22P01", SqlState::FloatingPointException), + ("22004", SqlState::DataNullValueNotAllowed), + ("HV00C", SqlState::FdwInvalidOptionIndex), + ("HV00Q", SqlState::FdwSchemaNotFound), + ("22P03", SqlState::InvalidBinaryRepresentation), + ("22002", SqlState::NullValueNoIndicatorParameter), + ("01007", SqlState::PrivilegeNotGranted), + ("HV021", SqlState::FdwInconsistentDescriptorInformation), + ("42P05", SqlState::DuplicatePreparedStatement), + ("53000", SqlState::InsufficientResources), + ("HV008", SqlState::FdwInvalidColumnNumber), + ("42602", SqlState::InvalidName), + ("40001", SqlState::SerializationFailure), + ("25006", SqlState::ReadOnlySqlTransaction), + ("00000", SqlState::SuccessfulCompletion), + ("HV005", SqlState::FdwColumnNameNotFound), + ("42939", SqlState::ReservedName), + ("22P04", SqlState::BadCopyFileFormat), + ("22015", SqlState::IntervalFieldOverflow), + ("42P14", SqlState::InvalidPreparedStatementDefinition), + ("01P01", SqlState::DeprecatedFeature), + ("2200G", SqlState::MostSpecificTypeMismatch), + ("HV001", SqlState::FdwOutOfMemory), + ("08004", SqlState::SqlserverRejectedEstablishmentOfSqlconnection), + ("42809", SqlState::WrongObjectType), + ("HV009", SqlState::FdwInvalidUseOfNullPointer), + ("58P02", SqlState::DuplicateFile), + ("0Z000", SqlState::DiagnosticsException), + ("08P01", SqlState::ProtocolViolation), + ("42723", SqlState::DuplicateFunction), + ("P0002", SqlState::NoDataFound), + ("22021", SqlState::CharacterNotInRepertoire), + ("01006", SqlState::PrivilegeNotRevoked), + ("0LP01", SqlState::InvalidGrantOperation), + ("P0004", SqlState::AssertFailure), + ("0F000", SqlState::LocatorException), + ("42611", SqlState::InvalidColumnDefinition), + ("2200L", SqlState::NotAnXmlDocument), + ("2200C", SqlState::InvalidUseOfEscapeCharacter), + ("40003", SqlState::StatementCompletionUnknown), + ("HV091", SqlState::FdwInvalidDescriptorFieldIdentifier), + ("XX002", SqlState::IndexCorrupted), + ("44000", SqlState::WithCheckOptionViolation), + ("22P02", SqlState::InvalidTextRepresentation), + ("54000", SqlState::ProgramLimitExceeded), + ("24000", SqlState::InvalidCursorState), + ("HV000", SqlState::FdwError), + ("2201W", SqlState::InvalidRowCountInLimitClause), + ("42P09", SqlState::AmbiguousAlias), + ("F0001", SqlState::LockFileExists), + ("57P01", SqlState::AdminShutdown), + ("23001", SqlState::RestrictViolation), + ("42P11", SqlState::InvalidCursorDefinition), + ("22027", SqlState::TrimError), + ("42725", SqlState::AmbiguousFunction), + ("0L000", SqlState::InvalidGrantor), + ("22003", SqlState::NumericValueOutOfRange), + ("42702", SqlState::AmbiguousColumn), + ("42830", SqlState::InvalidForeignKey), + ("21000", SqlState::CardinalityViolation), + ("58000", SqlState::SystemError), + ("2BP01", SqlState::DependentObjectsStillExist), + ("2201F", SqlState::InvalidArgumentForPowerFunction), + ("0A000", SqlState::FeatureNotSupported), + ("42P20", SqlState::WindowingError), + ("28P01", SqlState::InvalidPassword), + ("25003", SqlState::InappropriateAccessModeForBranchTransaction), + ("01000", SqlState::Warning), + ("08006", SqlState::ConnectionFailure), + ("2200M", SqlState::InvalidXmlDocument), + ("0100C", SqlState::DynamicResultSetsReturned), + ("03000", SqlState::SqlStatementNotYetComplete), + ("3D000", SqlState::InvalidCatalogName), + ("2202E", SqlState::ArraySubscriptError), + ("HV006", SqlState::FdwInvalidDataTypeDescriptors), + ("42704", SqlState::UndefinedObject), + ("HV004", SqlState::FdwInvalidDataType), + ("HV00B", SqlState::FdwInvalidHandle), + ("54001", SqlState::StatementTooComplex), + ("2202G", SqlState::InvalidTablesampleRepeat), + ("HV024", SqlState::FdwInvalidAttributeValue), + ("2F002", SqlState::SqlRoutineModifyingSqlDataNotPermitted), + ("F0000", SqlState::ConfigFileError), + ("2D000", SqlState::InvalidTransactionTermination), + ("25004", SqlState::InappropriateIsolationLevelForBranchTransaction), + ("22P06", SqlState::NonstandardUseOfEscapeCharacter), + ("53100", SqlState::DiskFull), + ("42P10", SqlState::InvalidColumnReference), + ("58030", SqlState::IoError), + ("0P000", SqlState::InvalidRoleSpecification), + ("08007", SqlState::TransactionResolutionUnknown), + ("HV090", SqlState::FdwInvalidStringLengthOrBufferLength), + ("27000", SqlState::TriggeredDataChangeViolation), + ("0F001", SqlState::InvalidLocatorSpecification), + ("22023", SqlState::InvalidParameterValue), + ("22005", SqlState::ErrorInAssignment), + ("57000", SqlState::OperatorIntervention), + ("55P03", SqlState::LockNotAvailable), + ("3B000", SqlState::SavepointException), + ("09000", SqlState::TriggeredActionException), + ("23502", SqlState::NotNullViolation), + ("HV00D", SqlState::FdwInvalidOptionName), + ("58P01", SqlState::UndefinedFile), + ("40002", SqlState::TransactionIntegrityConstraintViolation), + ("25005", SqlState::NoActiveSqlTransactionForBranchTransaction), + ("42601", SqlState::SyntaxError), + ("22024", SqlState::UnterminatedCString), + ("22025", SqlState::InvalidEscapeSequence), + ("22018", SqlState::InvalidCharacterValueForCast), + ("42P22", SqlState::IndeterminateCollation), + ("P0001", SqlState::RaiseException), + ("42P04", SqlState::DuplicateDatabase), + ("2202H", SqlState::InvalidTablesampleArgument), + ("2F003", SqlState::SqlRoutineProhibitedSqlStatementAttempted), + ("22014", SqlState::InvalidArgumentForNtileFunction), + ("HV00M", SqlState::FdwUnableToCreateReply), + ("HV014", SqlState::FdwTooManyHandles), + ("08003", SqlState::ConnectionDoesNotExist), + ("42P01", SqlState::UndefinedTable), + ("57P04", SqlState::DatabaseDropped), + ("42P21", SqlState::CollationMismatch), + ("22009", SqlState::InvalidTimeZoneDisplacementValue), + ("42804", SqlState::DatatypeMismatch), + ("22016", SqlState::InvalidArgumentForNthValueFunction), + ("57014", SqlState::QueryCanceled), + ("42701", SqlState::DuplicateColumn), + ("P0003", SqlState::TooManyRows), + ("57P03", SqlState::CannotConnectNow), + ("20000", SqlState::CaseNotFound), + ("XX001", SqlState::DataCorrupted), + ("42883", SqlState::UndefinedFunction), + ("38000", SqlState::ExternalRoutineException), + ("39004", SqlState::ExternalRoutineInvocationNullValueNotAllowed), + ("P0000", SqlState::PlpgsqlError), + ("2B000", SqlState::DependentPrivilegeDescriptorsStillExist), + ("55006", SqlState::ObjectInUse), + ("40P01", SqlState::DeadlockDetected), + ("HV00R", SqlState::FdwTableNotFound), + ("39000", SqlState::ExternalRoutineInvocationException), + ("23514", SqlState::CheckViolation), + ("22000", SqlState::DataException), + ("22010", SqlState::InvalidIndicatorParameterValue), + ("53300", SqlState::TooManyConnections), + ("42P08", SqlState::AmbiguousParameter), + ("HV00K", SqlState::FdwReplyHandle), + ("22P05", SqlState::UntranslatableCharacter), + ("2F000", SqlState::SqlRoutineException), + ("HV010", SqlState::FdwFunctionSequenceError), + ("42846", SqlState::CannotCoerce), + ("25001", SqlState::ActiveSqlTransaction), + ("38004", SqlState::ForeignRoutineReadingSqlDataNotPermitted), + ("42P12", SqlState::InvalidDatabaseDefinition), + ("53200", SqlState::OutOfMemory), + ("42P19", SqlState::InvalidRecursion), + ("42803", SqlState::GroupingError), + ("54011", SqlState::TooManyColumns), + ("39001", SqlState::InvalidSqlstateReturned), + ("38003", SqlState::ForeignRoutineProhibitedSqlStatementAttempted), + ("34000", SqlState::InvalidCursorName), + ("42P18", SqlState::IndeterminateDatatype), + ("2200B", SqlState::EscapeCharacterConflict), + ("HV00N", SqlState::FdwUnableToEstablishConnection), + ("HV00P", SqlState::FdwNoSchemas), + ("42P06", SqlState::DuplicateSchema), + ("02001", SqlState::NoAdditionalDynamicResultSetsReturned), + ("HV00L", SqlState::FdwUnableToCreateExecution), + ("57P02", SqlState::CrashShutdown), + ("08000", SqlState::ConnectionException), + ("2201G", SqlState::InvalidArgumentForWidthBucketFunction), + ("42622", SqlState::NameTooLong), + ("55000", SqlState::ObjectNotInPrerequisiteState), + ("40000", SqlState::TransactionRollback), + ("38002", SqlState::ForeignRoutineModifyingSqlDataNotPermitted), + ("22008", SqlState::DatetimeFieldOverflow), + ("01008", SqlState::ImplicitZeroBitPadding), + ("28000", SqlState::InvalidAuthorizationSpecification), + ("0Z002", SqlState::StackedDiagnosticsAccessedWithoutActiveHandler), + ("02000", SqlState::NoData), + ] +}; + +impl SqlState { + /// Creates a `SqlState` from its error code. + pub fn from_code(s: String) -> SqlState { + match SQLSTATE_MAP.get(&*s) { + Some(state) => state.clone(), + None => SqlState::Other(s) + } + } + + /// Returns the error code corresponding to the `SqlState`. + pub fn code(&self) -> &str { + match *self { + SqlState::SuccessfulCompletion => "00000", + SqlState::Warning => "01000", + SqlState::DynamicResultSetsReturned => "0100C", + SqlState::ImplicitZeroBitPadding => "01008", + SqlState::NullValueEliminatedInSetFunction => "01003", + SqlState::PrivilegeNotGranted => "01007", + SqlState::PrivilegeNotRevoked => "01006", + SqlState::WarningStringDataRightTruncation => "01004", + SqlState::DeprecatedFeature => "01P01", + SqlState::NoData => "02000", + SqlState::NoAdditionalDynamicResultSetsReturned => "02001", + SqlState::SqlStatementNotYetComplete => "03000", + SqlState::ConnectionException => "08000", + SqlState::ConnectionDoesNotExist => "08003", + SqlState::ConnectionFailure => "08006", + SqlState::SqlclientUnableToEstablishSqlconnection => "08001", + SqlState::SqlserverRejectedEstablishmentOfSqlconnection => "08004", + SqlState::TransactionResolutionUnknown => "08007", + SqlState::ProtocolViolation => "08P01", + SqlState::TriggeredActionException => "09000", + SqlState::FeatureNotSupported => "0A000", + SqlState::InvalidTransactionInitiation => "0B000", + SqlState::LocatorException => "0F000", + SqlState::InvalidLocatorSpecification => "0F001", + SqlState::InvalidGrantor => "0L000", + SqlState::InvalidGrantOperation => "0LP01", + SqlState::InvalidRoleSpecification => "0P000", + SqlState::DiagnosticsException => "0Z000", + SqlState::StackedDiagnosticsAccessedWithoutActiveHandler => "0Z002", + SqlState::CaseNotFound => "20000", + SqlState::CardinalityViolation => "21000", + SqlState::DataException => "22000", + SqlState::ArraySubscriptError => "2202E", + SqlState::CharacterNotInRepertoire => "22021", + SqlState::DatetimeFieldOverflow => "22008", + SqlState::DivisionByZero => "22012", + SqlState::ErrorInAssignment => "22005", + SqlState::EscapeCharacterConflict => "2200B", + SqlState::IndicatorOverflow => "22022", + SqlState::IntervalFieldOverflow => "22015", + SqlState::InvalidArgumentForLogarithm => "2201E", + SqlState::InvalidArgumentForNtileFunction => "22014", + SqlState::InvalidArgumentForNthValueFunction => "22016", + SqlState::InvalidArgumentForPowerFunction => "2201F", + SqlState::InvalidArgumentForWidthBucketFunction => "2201G", + SqlState::InvalidCharacterValueForCast => "22018", + SqlState::InvalidDatetimeFormat => "22007", + SqlState::InvalidEscapeCharacter => "22019", + SqlState::InvalidEscapeOctet => "2200D", + SqlState::InvalidEscapeSequence => "22025", + SqlState::NonstandardUseOfEscapeCharacter => "22P06", + SqlState::InvalidIndicatorParameterValue => "22010", + SqlState::InvalidParameterValue => "22023", + SqlState::InvalidRegularExpression => "2201B", + SqlState::InvalidRowCountInLimitClause => "2201W", + SqlState::InvalidRowCountInResultOffsetClause => "2201X", + SqlState::InvalidTablesampleArgument => "2202H", + SqlState::InvalidTablesampleRepeat => "2202G", + SqlState::InvalidTimeZoneDisplacementValue => "22009", + SqlState::InvalidUseOfEscapeCharacter => "2200C", + SqlState::MostSpecificTypeMismatch => "2200G", + SqlState::DataNullValueNotAllowed => "22004", + SqlState::NullValueNoIndicatorParameter => "22002", + SqlState::NumericValueOutOfRange => "22003", + SqlState::StringDataLengthMismatch => "22026", + SqlState::DataStringDataRightTruncation => "22001", + SqlState::SubstringError => "22011", + SqlState::TrimError => "22027", + SqlState::UnterminatedCString => "22024", + SqlState::ZeroLengthCharacterString => "2200F", + SqlState::FloatingPointException => "22P01", + SqlState::InvalidTextRepresentation => "22P02", + SqlState::InvalidBinaryRepresentation => "22P03", + SqlState::BadCopyFileFormat => "22P04", + SqlState::UntranslatableCharacter => "22P05", + SqlState::NotAnXmlDocument => "2200L", + SqlState::InvalidXmlDocument => "2200M", + SqlState::InvalidXmlContent => "2200N", + SqlState::InvalidXmlComment => "2200S", + SqlState::InvalidXmlProcessingInstruction => "2200T", + SqlState::IntegrityConstraintViolation => "23000", + SqlState::RestrictViolation => "23001", + SqlState::NotNullViolation => "23502", + SqlState::ForeignKeyViolation => "23503", + SqlState::UniqueViolation => "23505", + SqlState::CheckViolation => "23514", + SqlState::ExclusionViolation => "23P01", + SqlState::InvalidCursorState => "24000", + SqlState::InvalidTransactionState => "25000", + SqlState::ActiveSqlTransaction => "25001", + SqlState::BranchTransactionAlreadyActive => "25002", + SqlState::HeldCursorRequiresSameIsolationLevel => "25008", + SqlState::InappropriateAccessModeForBranchTransaction => "25003", + SqlState::InappropriateIsolationLevelForBranchTransaction => "25004", + SqlState::NoActiveSqlTransactionForBranchTransaction => "25005", + SqlState::ReadOnlySqlTransaction => "25006", + SqlState::SchemaAndDataStatementMixingNotSupported => "25007", + SqlState::NoActiveSqlTransaction => "25P01", + SqlState::InFailedSqlTransaction => "25P02", + SqlState::InvalidSqlStatementName => "26000", + SqlState::TriggeredDataChangeViolation => "27000", + SqlState::InvalidAuthorizationSpecification => "28000", + SqlState::InvalidPassword => "28P01", + SqlState::DependentPrivilegeDescriptorsStillExist => "2B000", + SqlState::DependentObjectsStillExist => "2BP01", + SqlState::InvalidTransactionTermination => "2D000", + SqlState::SqlRoutineException => "2F000", + SqlState::FunctionExecutedNoReturnStatement => "2F005", + SqlState::SqlRoutineModifyingSqlDataNotPermitted => "2F002", + SqlState::SqlRoutineProhibitedSqlStatementAttempted => "2F003", + SqlState::SqlRoutineReadingSqlDataNotPermitted => "2F004", + SqlState::InvalidCursorName => "34000", + SqlState::ExternalRoutineException => "38000", + SqlState::ContainingSqlNotPermitted => "38001", + SqlState::ForeignRoutineModifyingSqlDataNotPermitted => "38002", + SqlState::ForeignRoutineProhibitedSqlStatementAttempted => "38003", + SqlState::ForeignRoutineReadingSqlDataNotPermitted => "38004", + SqlState::ExternalRoutineInvocationException => "39000", + SqlState::InvalidSqlstateReturned => "39001", + SqlState::ExternalRoutineInvocationNullValueNotAllowed => "39004", + SqlState::TriggerProtocolViolated => "39P01", + SqlState::SrfProtocolViolated => "39P02", + SqlState::EventTriggerProtocolViolated => "39P03", + SqlState::SavepointException => "3B000", + SqlState::InvalidSavepointSpecification => "3B001", + SqlState::InvalidCatalogName => "3D000", + SqlState::InvalidSchemaName => "3F000", + SqlState::TransactionRollback => "40000", + SqlState::TransactionIntegrityConstraintViolation => "40002", + SqlState::SerializationFailure => "40001", + SqlState::StatementCompletionUnknown => "40003", + SqlState::DeadlockDetected => "40P01", + SqlState::SyntaxErrorOrAccessRuleViolation => "42000", + SqlState::SyntaxError => "42601", + SqlState::InsufficientPrivilege => "42501", + SqlState::CannotCoerce => "42846", + SqlState::GroupingError => "42803", + SqlState::WindowingError => "42P20", + SqlState::InvalidRecursion => "42P19", + SqlState::InvalidForeignKey => "42830", + SqlState::InvalidName => "42602", + SqlState::NameTooLong => "42622", + SqlState::ReservedName => "42939", + SqlState::DatatypeMismatch => "42804", + SqlState::IndeterminateDatatype => "42P18", + SqlState::CollationMismatch => "42P21", + SqlState::IndeterminateCollation => "42P22", + SqlState::WrongObjectType => "42809", + SqlState::UndefinedColumn => "42703", + SqlState::UndefinedFunction => "42883", + SqlState::UndefinedTable => "42P01", + SqlState::UndefinedParameter => "42P02", + SqlState::UndefinedObject => "42704", + SqlState::DuplicateColumn => "42701", + SqlState::DuplicateCursor => "42P03", + SqlState::DuplicateDatabase => "42P04", + SqlState::DuplicateFunction => "42723", + SqlState::DuplicatePreparedStatement => "42P05", + SqlState::DuplicateSchema => "42P06", + SqlState::DuplicateTable => "42P07", + SqlState::DuplicateAlias => "42712", + SqlState::DuplicateObject => "42710", + SqlState::AmbiguousColumn => "42702", + SqlState::AmbiguousFunction => "42725", + SqlState::AmbiguousParameter => "42P08", + SqlState::AmbiguousAlias => "42P09", + SqlState::InvalidColumnReference => "42P10", + SqlState::InvalidColumnDefinition => "42611", + SqlState::InvalidCursorDefinition => "42P11", + SqlState::InvalidDatabaseDefinition => "42P12", + SqlState::InvalidFunctionDefinition => "42P13", + SqlState::InvalidPreparedStatementDefinition => "42P14", + SqlState::InvalidSchemaDefinition => "42P15", + SqlState::InvalidTableDefinition => "42P16", + SqlState::InvalidObjectDefinition => "42P17", + SqlState::WithCheckOptionViolation => "44000", + SqlState::InsufficientResources => "53000", + SqlState::DiskFull => "53100", + SqlState::OutOfMemory => "53200", + SqlState::TooManyConnections => "53300", + SqlState::ConfigurationLimitExceeded => "53400", + SqlState::ProgramLimitExceeded => "54000", + SqlState::StatementTooComplex => "54001", + SqlState::TooManyColumns => "54011", + SqlState::TooManyArguments => "54023", + SqlState::ObjectNotInPrerequisiteState => "55000", + SqlState::ObjectInUse => "55006", + SqlState::CantChangeRuntimeParam => "55P02", + SqlState::LockNotAvailable => "55P03", + SqlState::OperatorIntervention => "57000", + SqlState::QueryCanceled => "57014", + SqlState::AdminShutdown => "57P01", + SqlState::CrashShutdown => "57P02", + SqlState::CannotConnectNow => "57P03", + SqlState::DatabaseDropped => "57P04", + SqlState::SystemError => "58000", + SqlState::IoError => "58030", + SqlState::UndefinedFile => "58P01", + SqlState::DuplicateFile => "58P02", + SqlState::ConfigFileError => "F0000", + SqlState::LockFileExists => "F0001", + SqlState::FdwError => "HV000", + SqlState::FdwColumnNameNotFound => "HV005", + SqlState::FdwDynamicParameterValueNeeded => "HV002", + SqlState::FdwFunctionSequenceError => "HV010", + SqlState::FdwInconsistentDescriptorInformation => "HV021", + SqlState::FdwInvalidAttributeValue => "HV024", + SqlState::FdwInvalidColumnName => "HV007", + SqlState::FdwInvalidColumnNumber => "HV008", + SqlState::FdwInvalidDataType => "HV004", + SqlState::FdwInvalidDataTypeDescriptors => "HV006", + SqlState::FdwInvalidDescriptorFieldIdentifier => "HV091", + SqlState::FdwInvalidHandle => "HV00B", + SqlState::FdwInvalidOptionIndex => "HV00C", + SqlState::FdwInvalidOptionName => "HV00D", + SqlState::FdwInvalidStringLengthOrBufferLength => "HV090", + SqlState::FdwInvalidStringFormat => "HV00A", + SqlState::FdwInvalidUseOfNullPointer => "HV009", + SqlState::FdwTooManyHandles => "HV014", + SqlState::FdwOutOfMemory => "HV001", + SqlState::FdwNoSchemas => "HV00P", + SqlState::FdwOptionNameNotFound => "HV00J", + SqlState::FdwReplyHandle => "HV00K", + SqlState::FdwSchemaNotFound => "HV00Q", + SqlState::FdwTableNotFound => "HV00R", + SqlState::FdwUnableToCreateExecution => "HV00L", + SqlState::FdwUnableToCreateReply => "HV00M", + SqlState::FdwUnableToEstablishConnection => "HV00N", + SqlState::PlpgsqlError => "P0000", + SqlState::RaiseException => "P0001", + SqlState::NoDataFound => "P0002", + SqlState::TooManyRows => "P0003", + SqlState::AssertFailure => "P0004", + SqlState::InternalError => "XX000", + SqlState::DataCorrupted => "XX001", + SqlState::IndexCorrupted => "XX002", + SqlState::Other(ref s) => s, + } + } +} diff --git a/src/types/mod.rs b/src/types/mod.rs index 7964c6ca..dd6b9d83 100644 --- a/src/types/mod.rs +++ b/src/types/mod.rs @@ -149,7 +149,7 @@ impl FieldNew for Field { } } -include!(concat!(env!("OUT_DIR"), "/type.rs")); +include!("types.rs"); /// Information about an unknown type. #[derive(PartialEq, Eq, Clone)] diff --git a/src/types/types.rs b/src/types/types.rs new file mode 100644 index 00000000..9ff82c44 --- /dev/null +++ b/src/types/types.rs @@ -0,0 +1,1477 @@ +/// A Postgres type. +#[derive(PartialEq, Eq, Clone, Debug)] +pub enum Type { + /// BOOL - boolean, 'true'/'false' + Bool, + /// BYTEA - variable-length string, binary values escaped + Bytea, + /// CHAR - single character + Char, + /// NAME - 63-byte type for storing system identifiers + Name, + /// INT8 - ~18 digit integer, 8-byte storage + Int8, + /// INT2 - -32 thousand to 32 thousand, 2-byte storage + Int2, + /// INT2VECTOR - array of int2, used in system tables + Int2Vector, + /// INT4 - -2 billion to 2 billion integer, 4-byte storage + Int4, + /// REGPROC - registered procedure + Regproc, + /// TEXT - variable-length string, no limit specified + Text, + /// OID - object identifier(oid), maximum 4 billion + Oid, + /// TID - (block, offset), physical location of tuple + Tid, + /// XID - transaction id + Xid, + /// CID - command identifier type, sequence in transaction id + Cid, + /// OIDVECTOR - array of oids, used in system tables + OidVector, + /// PG_DDL_COMMAND - internal type for passing CollectedCommand + PgDdlCommand, + /// JSON + Json, + /// XML - XML content + Xml, + /// XML[] + XmlArray, + /// PG_NODE_TREE - string representing an internal node tree + PgNodeTree, + /// JSON[] + JsonArray, + /// SMGR - storage manager + Smgr, + /// POINT - geometric point '(x, y)' + Point, + /// LSEG - geometric line segment '(pt1,pt2)' + Lseg, + /// PATH - geometric path '(pt1,...)' + Path, + /// BOX - geometric box '(lower left,upper right)' + Box, + /// POLYGON - geometric polygon '(pt1,...)' + Polygon, + /// LINE - geometric line + Line, + /// LINE[] + LineArray, + /// CIDR - network IP address/netmask, network address + Cidr, + /// CIDR[] + CidrArray, + /// FLOAT4 - single-precision floating point number, 4-byte storage + Float4, + /// FLOAT8 - double-precision floating point number, 8-byte storage + Float8, + /// ABSTIME - absolute, limited-range date and time (Unix system time) + Abstime, + /// RELTIME - relative, limited-range time interval (Unix delta time) + Reltime, + /// TINTERVAL - (abstime,abstime), time interval + Tinterval, + /// UNKNOWN + Unknown, + /// CIRCLE - geometric circle '(center,radius)' + Circle, + /// CIRCLE[] + CircleArray, + /// MONEY - monetary amounts, $d,ddd.cc + Money, + /// MONEY[] + MoneyArray, + /// MACADDR - XX:XX:XX:XX:XX:XX, MAC address + Macaddr, + /// INET - IP address/netmask, host address, netmask optional + Inet, + /// BOOL[] + BoolArray, + /// BYTEA[] + ByteaArray, + /// CHAR[] + CharArray, + /// NAME[] + NameArray, + /// INT2[] + Int2Array, + /// INT2VECTOR[] + Int2VectorArray, + /// INT4[] + Int4Array, + /// REGPROC[] + RegprocArray, + /// TEXT[] + TextArray, + /// TID[] + TidArray, + /// XID[] + XidArray, + /// CID[] + CidArray, + /// OIDVECTOR[] + OidVectorArray, + /// BPCHAR[] + BpcharArray, + /// VARCHAR[] + VarcharArray, + /// INT8[] + Int8Array, + /// POINT[] + PointArray, + /// LSEG[] + LsegArray, + /// PATH[] + PathArray, + /// BOX[] + BoxArray, + /// FLOAT4[] + Float4Array, + /// FLOAT8[] + Float8Array, + /// ABSTIME[] + AbstimeArray, + /// RELTIME[] + ReltimeArray, + /// TINTERVAL[] + TintervalArray, + /// POLYGON[] + PolygonArray, + /// OID[] + OidArray, + /// ACLITEM - access control list + Aclitem, + /// ACLITEM[] + AclitemArray, + /// MACADDR[] + MacaddrArray, + /// INET[] + InetArray, + /// BPCHAR - char(length), blank-padded string, fixed storage length + Bpchar, + /// VARCHAR - varchar(length), non-blank-padded string, variable storage length + Varchar, + /// DATE - date + Date, + /// TIME - time of day + Time, + /// TIMESTAMP - date and time + Timestamp, + /// TIMESTAMP[] + TimestampArray, + /// DATE[] + DateArray, + /// TIME[] + TimeArray, + /// TIMESTAMPTZ - date and time with time zone + Timestamptz, + /// TIMESTAMPTZ[] + TimestamptzArray, + /// INTERVAL - @ , time interval + Interval, + /// INTERVAL[] + IntervalArray, + /// NUMERIC[] + NumericArray, + /// CSTRING[] + CstringArray, + /// TIMETZ - time of day with time zone + Timetz, + /// TIMETZ[] + TimetzArray, + /// BIT - fixed-length bit string + Bit, + /// BIT[] + BitArray, + /// VARBIT - variable-length bit string + Varbit, + /// VARBIT[] + VarbitArray, + /// NUMERIC - numeric(precision, decimal), arbitrary precision number + Numeric, + /// REFCURSOR - reference to cursor (portal name) + Refcursor, + /// REFCURSOR[] + RefcursorArray, + /// REGPROCEDURE - registered procedure (with args) + Regprocedure, + /// REGOPER - registered operator + Regoper, + /// REGOPERATOR - registered operator (with args) + Regoperator, + /// REGCLASS - registered class + Regclass, + /// REGTYPE - registered type + Regtype, + /// REGPROCEDURE[] + RegprocedureArray, + /// REGOPER[] + RegoperArray, + /// REGOPERATOR[] + RegoperatorArray, + /// REGCLASS[] + RegclassArray, + /// REGTYPE[] + RegtypeArray, + /// RECORD + Record, + /// CSTRING + Cstring, + /// ANY + Any, + /// ANYARRAY + Anyarray, + /// VOID + Void, + /// TRIGGER + Trigger, + /// LANGUAGE_HANDLER + LanguageHandler, + /// INTERNAL + Internal, + /// OPAQUE + Opaque, + /// ANYELEMENT + Anyelement, + /// RECORD[] + RecordArray, + /// ANYNONARRAY + Anynonarray, + /// TXID_SNAPSHOT[] + TxidSnapshotArray, + /// UUID - UUID datatype + Uuid, + /// UUID[] + UuidArray, + /// TXID_SNAPSHOT - txid snapshot + TxidSnapshot, + /// FDW_HANDLER + FdwHandler, + /// PG_LSN - PostgreSQL LSN datatype + PgLsn, + /// PG_LSN[] + PgLsnArray, + /// TSM_HANDLER + TsmHandler, + /// ANYENUM + Anyenum, + /// TSVECTOR - text representation for text search + TsVector, + /// TSQUERY - query representation for text search + Tsquery, + /// GTSVECTOR - GiST index internal text representation for text search + GtsVector, + /// TSVECTOR[] + TsVectorArray, + /// GTSVECTOR[] + GtsVectorArray, + /// TSQUERY[] + TsqueryArray, + /// REGCONFIG - registered text search configuration + Regconfig, + /// REGCONFIG[] + RegconfigArray, + /// REGDICTIONARY - registered text search dictionary + Regdictionary, + /// REGDICTIONARY[] + RegdictionaryArray, + /// JSONB - Binary JSON + Jsonb, + /// JSONB[] + JsonbArray, + /// ANYRANGE + Anyrange, + /// EVENT_TRIGGER + EventTrigger, + /// INT4RANGE - range of integers + Int4Range, + /// INT4RANGE[] + Int4RangeArray, + /// NUMRANGE - range of numerics + NumRange, + /// NUMRANGE[] + NumRangeArray, + /// TSRANGE - range of timestamps without time zone + TsRange, + /// TSRANGE[] + TsRangeArray, + /// TSTZRANGE - range of timestamps with time zone + TstzRange, + /// TSTZRANGE[] + TstzRangeArray, + /// DATERANGE - range of dates + DateRange, + /// DATERANGE[] + DateRangeArray, + /// INT8RANGE - range of bigints + Int8Range, + /// INT8RANGE[] + Int8RangeArray, + /// REGNAMESPACE - registered namespace + Regnamespace, + /// REGNAMESPACE[] + RegnamespaceArray, + /// REGROLE - registered role + Regrole, + /// REGROLE[] + RegroleArray, + /// An unknown type. + Other(Other), +} + +impl fmt::Display for Type { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + match self.schema() { + "public" | "pg_catalog" => {} + schema => try!(write!(fmt, "{}.", schema)), + } + fmt.write_str(self.name()) + } +} + +impl Type { + /// Returns the `Type` corresponding to the provided `Oid` if it + /// corresponds to a built-in type. + pub fn from_oid(oid: Oid) -> Option { + match oid { + 16 => Some(Type::Bool), + 17 => Some(Type::Bytea), + 18 => Some(Type::Char), + 19 => Some(Type::Name), + 20 => Some(Type::Int8), + 21 => Some(Type::Int2), + 22 => Some(Type::Int2Vector), + 23 => Some(Type::Int4), + 24 => Some(Type::Regproc), + 25 => Some(Type::Text), + 26 => Some(Type::Oid), + 27 => Some(Type::Tid), + 28 => Some(Type::Xid), + 29 => Some(Type::Cid), + 30 => Some(Type::OidVector), + 32 => Some(Type::PgDdlCommand), + 114 => Some(Type::Json), + 142 => Some(Type::Xml), + 143 => Some(Type::XmlArray), + 194 => Some(Type::PgNodeTree), + 199 => Some(Type::JsonArray), + 210 => Some(Type::Smgr), + 600 => Some(Type::Point), + 601 => Some(Type::Lseg), + 602 => Some(Type::Path), + 603 => Some(Type::Box), + 604 => Some(Type::Polygon), + 628 => Some(Type::Line), + 629 => Some(Type::LineArray), + 650 => Some(Type::Cidr), + 651 => Some(Type::CidrArray), + 700 => Some(Type::Float4), + 701 => Some(Type::Float8), + 702 => Some(Type::Abstime), + 703 => Some(Type::Reltime), + 704 => Some(Type::Tinterval), + 705 => Some(Type::Unknown), + 718 => Some(Type::Circle), + 719 => Some(Type::CircleArray), + 790 => Some(Type::Money), + 791 => Some(Type::MoneyArray), + 829 => Some(Type::Macaddr), + 869 => Some(Type::Inet), + 1000 => Some(Type::BoolArray), + 1001 => Some(Type::ByteaArray), + 1002 => Some(Type::CharArray), + 1003 => Some(Type::NameArray), + 1005 => Some(Type::Int2Array), + 1006 => Some(Type::Int2VectorArray), + 1007 => Some(Type::Int4Array), + 1008 => Some(Type::RegprocArray), + 1009 => Some(Type::TextArray), + 1010 => Some(Type::TidArray), + 1011 => Some(Type::XidArray), + 1012 => Some(Type::CidArray), + 1013 => Some(Type::OidVectorArray), + 1014 => Some(Type::BpcharArray), + 1015 => Some(Type::VarcharArray), + 1016 => Some(Type::Int8Array), + 1017 => Some(Type::PointArray), + 1018 => Some(Type::LsegArray), + 1019 => Some(Type::PathArray), + 1020 => Some(Type::BoxArray), + 1021 => Some(Type::Float4Array), + 1022 => Some(Type::Float8Array), + 1023 => Some(Type::AbstimeArray), + 1024 => Some(Type::ReltimeArray), + 1025 => Some(Type::TintervalArray), + 1027 => Some(Type::PolygonArray), + 1028 => Some(Type::OidArray), + 1033 => Some(Type::Aclitem), + 1034 => Some(Type::AclitemArray), + 1040 => Some(Type::MacaddrArray), + 1041 => Some(Type::InetArray), + 1042 => Some(Type::Bpchar), + 1043 => Some(Type::Varchar), + 1082 => Some(Type::Date), + 1083 => Some(Type::Time), + 1114 => Some(Type::Timestamp), + 1115 => Some(Type::TimestampArray), + 1182 => Some(Type::DateArray), + 1183 => Some(Type::TimeArray), + 1184 => Some(Type::Timestamptz), + 1185 => Some(Type::TimestamptzArray), + 1186 => Some(Type::Interval), + 1187 => Some(Type::IntervalArray), + 1231 => Some(Type::NumericArray), + 1263 => Some(Type::CstringArray), + 1266 => Some(Type::Timetz), + 1270 => Some(Type::TimetzArray), + 1560 => Some(Type::Bit), + 1561 => Some(Type::BitArray), + 1562 => Some(Type::Varbit), + 1563 => Some(Type::VarbitArray), + 1700 => Some(Type::Numeric), + 1790 => Some(Type::Refcursor), + 2201 => Some(Type::RefcursorArray), + 2202 => Some(Type::Regprocedure), + 2203 => Some(Type::Regoper), + 2204 => Some(Type::Regoperator), + 2205 => Some(Type::Regclass), + 2206 => Some(Type::Regtype), + 2207 => Some(Type::RegprocedureArray), + 2208 => Some(Type::RegoperArray), + 2209 => Some(Type::RegoperatorArray), + 2210 => Some(Type::RegclassArray), + 2211 => Some(Type::RegtypeArray), + 2249 => Some(Type::Record), + 2275 => Some(Type::Cstring), + 2276 => Some(Type::Any), + 2277 => Some(Type::Anyarray), + 2278 => Some(Type::Void), + 2279 => Some(Type::Trigger), + 2280 => Some(Type::LanguageHandler), + 2281 => Some(Type::Internal), + 2282 => Some(Type::Opaque), + 2283 => Some(Type::Anyelement), + 2287 => Some(Type::RecordArray), + 2776 => Some(Type::Anynonarray), + 2949 => Some(Type::TxidSnapshotArray), + 2950 => Some(Type::Uuid), + 2951 => Some(Type::UuidArray), + 2970 => Some(Type::TxidSnapshot), + 3115 => Some(Type::FdwHandler), + 3220 => Some(Type::PgLsn), + 3221 => Some(Type::PgLsnArray), + 3310 => Some(Type::TsmHandler), + 3500 => Some(Type::Anyenum), + 3614 => Some(Type::TsVector), + 3615 => Some(Type::Tsquery), + 3642 => Some(Type::GtsVector), + 3643 => Some(Type::TsVectorArray), + 3644 => Some(Type::GtsVectorArray), + 3645 => Some(Type::TsqueryArray), + 3734 => Some(Type::Regconfig), + 3735 => Some(Type::RegconfigArray), + 3769 => Some(Type::Regdictionary), + 3770 => Some(Type::RegdictionaryArray), + 3802 => Some(Type::Jsonb), + 3807 => Some(Type::JsonbArray), + 3831 => Some(Type::Anyrange), + 3838 => Some(Type::EventTrigger), + 3904 => Some(Type::Int4Range), + 3905 => Some(Type::Int4RangeArray), + 3906 => Some(Type::NumRange), + 3907 => Some(Type::NumRangeArray), + 3908 => Some(Type::TsRange), + 3909 => Some(Type::TsRangeArray), + 3910 => Some(Type::TstzRange), + 3911 => Some(Type::TstzRangeArray), + 3912 => Some(Type::DateRange), + 3913 => Some(Type::DateRangeArray), + 3926 => Some(Type::Int8Range), + 3927 => Some(Type::Int8RangeArray), + 4089 => Some(Type::Regnamespace), + 4090 => Some(Type::RegnamespaceArray), + 4096 => Some(Type::Regrole), + 4097 => Some(Type::RegroleArray), + _ => None, + } + } + + /// Returns the OID of the `Type`. + pub fn oid(&self) -> Oid { + match *self { + Type::Bool => 16, + Type::Bytea => 17, + Type::Char => 18, + Type::Name => 19, + Type::Int8 => 20, + Type::Int2 => 21, + Type::Int2Vector => 22, + Type::Int4 => 23, + Type::Regproc => 24, + Type::Text => 25, + Type::Oid => 26, + Type::Tid => 27, + Type::Xid => 28, + Type::Cid => 29, + Type::OidVector => 30, + Type::PgDdlCommand => 32, + Type::Json => 114, + Type::Xml => 142, + Type::XmlArray => 143, + Type::PgNodeTree => 194, + Type::JsonArray => 199, + Type::Smgr => 210, + Type::Point => 600, + Type::Lseg => 601, + Type::Path => 602, + Type::Box => 603, + Type::Polygon => 604, + Type::Line => 628, + Type::LineArray => 629, + Type::Cidr => 650, + Type::CidrArray => 651, + Type::Float4 => 700, + Type::Float8 => 701, + Type::Abstime => 702, + Type::Reltime => 703, + Type::Tinterval => 704, + Type::Unknown => 705, + Type::Circle => 718, + Type::CircleArray => 719, + Type::Money => 790, + Type::MoneyArray => 791, + Type::Macaddr => 829, + Type::Inet => 869, + Type::BoolArray => 1000, + Type::ByteaArray => 1001, + Type::CharArray => 1002, + Type::NameArray => 1003, + Type::Int2Array => 1005, + Type::Int2VectorArray => 1006, + Type::Int4Array => 1007, + Type::RegprocArray => 1008, + Type::TextArray => 1009, + Type::TidArray => 1010, + Type::XidArray => 1011, + Type::CidArray => 1012, + Type::OidVectorArray => 1013, + Type::BpcharArray => 1014, + Type::VarcharArray => 1015, + Type::Int8Array => 1016, + Type::PointArray => 1017, + Type::LsegArray => 1018, + Type::PathArray => 1019, + Type::BoxArray => 1020, + Type::Float4Array => 1021, + Type::Float8Array => 1022, + Type::AbstimeArray => 1023, + Type::ReltimeArray => 1024, + Type::TintervalArray => 1025, + Type::PolygonArray => 1027, + Type::OidArray => 1028, + Type::Aclitem => 1033, + Type::AclitemArray => 1034, + Type::MacaddrArray => 1040, + Type::InetArray => 1041, + Type::Bpchar => 1042, + Type::Varchar => 1043, + Type::Date => 1082, + Type::Time => 1083, + Type::Timestamp => 1114, + Type::TimestampArray => 1115, + Type::DateArray => 1182, + Type::TimeArray => 1183, + Type::Timestamptz => 1184, + Type::TimestamptzArray => 1185, + Type::Interval => 1186, + Type::IntervalArray => 1187, + Type::NumericArray => 1231, + Type::CstringArray => 1263, + Type::Timetz => 1266, + Type::TimetzArray => 1270, + Type::Bit => 1560, + Type::BitArray => 1561, + Type::Varbit => 1562, + Type::VarbitArray => 1563, + Type::Numeric => 1700, + Type::Refcursor => 1790, + Type::RefcursorArray => 2201, + Type::Regprocedure => 2202, + Type::Regoper => 2203, + Type::Regoperator => 2204, + Type::Regclass => 2205, + Type::Regtype => 2206, + Type::RegprocedureArray => 2207, + Type::RegoperArray => 2208, + Type::RegoperatorArray => 2209, + Type::RegclassArray => 2210, + Type::RegtypeArray => 2211, + Type::Record => 2249, + Type::Cstring => 2275, + Type::Any => 2276, + Type::Anyarray => 2277, + Type::Void => 2278, + Type::Trigger => 2279, + Type::LanguageHandler => 2280, + Type::Internal => 2281, + Type::Opaque => 2282, + Type::Anyelement => 2283, + Type::RecordArray => 2287, + Type::Anynonarray => 2776, + Type::TxidSnapshotArray => 2949, + Type::Uuid => 2950, + Type::UuidArray => 2951, + Type::TxidSnapshot => 2970, + Type::FdwHandler => 3115, + Type::PgLsn => 3220, + Type::PgLsnArray => 3221, + Type::TsmHandler => 3310, + Type::Anyenum => 3500, + Type::TsVector => 3614, + Type::Tsquery => 3615, + Type::GtsVector => 3642, + Type::TsVectorArray => 3643, + Type::GtsVectorArray => 3644, + Type::TsqueryArray => 3645, + Type::Regconfig => 3734, + Type::RegconfigArray => 3735, + Type::Regdictionary => 3769, + Type::RegdictionaryArray => 3770, + Type::Jsonb => 3802, + Type::JsonbArray => 3807, + Type::Anyrange => 3831, + Type::EventTrigger => 3838, + Type::Int4Range => 3904, + Type::Int4RangeArray => 3905, + Type::NumRange => 3906, + Type::NumRangeArray => 3907, + Type::TsRange => 3908, + Type::TsRangeArray => 3909, + Type::TstzRange => 3910, + Type::TstzRangeArray => 3911, + Type::DateRange => 3912, + Type::DateRangeArray => 3913, + Type::Int8Range => 3926, + Type::Int8RangeArray => 3927, + Type::Regnamespace => 4089, + Type::RegnamespaceArray => 4090, + Type::Regrole => 4096, + Type::RegroleArray => 4097, + Type::Other(ref u) => u.oid(), + } + } + + /// Returns the kind of this type. + pub fn kind(&self) -> &Kind { + match *self { + Type::Bool => { + const V: &'static Kind = &Kind::Simple; + V + } + Type::Bytea => { + const V: &'static Kind = &Kind::Simple; + V + } + Type::Char => { + const V: &'static Kind = &Kind::Simple; + V + } + Type::Name => { + const V: &'static Kind = &Kind::Simple; + V + } + Type::Int8 => { + const V: &'static Kind = &Kind::Simple; + V + } + Type::Int2 => { + const V: &'static Kind = &Kind::Simple; + V + } + Type::Int2Vector => { + const V: &'static Kind = &Kind::Array(Type::Int2); + V + } + Type::Int4 => { + const V: &'static Kind = &Kind::Simple; + V + } + Type::Regproc => { + const V: &'static Kind = &Kind::Simple; + V + } + Type::Text => { + const V: &'static Kind = &Kind::Simple; + V + } + Type::Oid => { + const V: &'static Kind = &Kind::Simple; + V + } + Type::Tid => { + const V: &'static Kind = &Kind::Simple; + V + } + Type::Xid => { + const V: &'static Kind = &Kind::Simple; + V + } + Type::Cid => { + const V: &'static Kind = &Kind::Simple; + V + } + Type::OidVector => { + const V: &'static Kind = &Kind::Array(Type::Oid); + V + } + Type::PgDdlCommand => { + const V: &'static Kind = &Kind::Pseudo; + V + } + Type::Json => { + const V: &'static Kind = &Kind::Simple; + V + } + Type::Xml => { + const V: &'static Kind = &Kind::Simple; + V + } + Type::XmlArray => { + const V: &'static Kind = &Kind::Array(Type::Xml); + V + } + Type::PgNodeTree => { + const V: &'static Kind = &Kind::Simple; + V + } + Type::JsonArray => { + const V: &'static Kind = &Kind::Array(Type::Json); + V + } + Type::Smgr => { + const V: &'static Kind = &Kind::Simple; + V + } + Type::Point => { + const V: &'static Kind = &Kind::Simple; + V + } + Type::Lseg => { + const V: &'static Kind = &Kind::Simple; + V + } + Type::Path => { + const V: &'static Kind = &Kind::Simple; + V + } + Type::Box => { + const V: &'static Kind = &Kind::Simple; + V + } + Type::Polygon => { + const V: &'static Kind = &Kind::Simple; + V + } + Type::Line => { + const V: &'static Kind = &Kind::Simple; + V + } + Type::LineArray => { + const V: &'static Kind = &Kind::Array(Type::Line); + V + } + Type::Cidr => { + const V: &'static Kind = &Kind::Simple; + V + } + Type::CidrArray => { + const V: &'static Kind = &Kind::Array(Type::Cidr); + V + } + Type::Float4 => { + const V: &'static Kind = &Kind::Simple; + V + } + Type::Float8 => { + const V: &'static Kind = &Kind::Simple; + V + } + Type::Abstime => { + const V: &'static Kind = &Kind::Simple; + V + } + Type::Reltime => { + const V: &'static Kind = &Kind::Simple; + V + } + Type::Tinterval => { + const V: &'static Kind = &Kind::Simple; + V + } + Type::Unknown => { + const V: &'static Kind = &Kind::Simple; + V + } + Type::Circle => { + const V: &'static Kind = &Kind::Simple; + V + } + Type::CircleArray => { + const V: &'static Kind = &Kind::Array(Type::Circle); + V + } + Type::Money => { + const V: &'static Kind = &Kind::Simple; + V + } + Type::MoneyArray => { + const V: &'static Kind = &Kind::Array(Type::Money); + V + } + Type::Macaddr => { + const V: &'static Kind = &Kind::Simple; + V + } + Type::Inet => { + const V: &'static Kind = &Kind::Simple; + V + } + Type::BoolArray => { + const V: &'static Kind = &Kind::Array(Type::Bool); + V + } + Type::ByteaArray => { + const V: &'static Kind = &Kind::Array(Type::Bytea); + V + } + Type::CharArray => { + const V: &'static Kind = &Kind::Array(Type::Char); + V + } + Type::NameArray => { + const V: &'static Kind = &Kind::Array(Type::Name); + V + } + Type::Int2Array => { + const V: &'static Kind = &Kind::Array(Type::Int2); + V + } + Type::Int2VectorArray => { + const V: &'static Kind = &Kind::Array(Type::Int2Vector); + V + } + Type::Int4Array => { + const V: &'static Kind = &Kind::Array(Type::Int4); + V + } + Type::RegprocArray => { + const V: &'static Kind = &Kind::Array(Type::Regproc); + V + } + Type::TextArray => { + const V: &'static Kind = &Kind::Array(Type::Text); + V + } + Type::TidArray => { + const V: &'static Kind = &Kind::Array(Type::Tid); + V + } + Type::XidArray => { + const V: &'static Kind = &Kind::Array(Type::Xid); + V + } + Type::CidArray => { + const V: &'static Kind = &Kind::Array(Type::Cid); + V + } + Type::OidVectorArray => { + const V: &'static Kind = &Kind::Array(Type::OidVector); + V + } + Type::BpcharArray => { + const V: &'static Kind = &Kind::Array(Type::Bpchar); + V + } + Type::VarcharArray => { + const V: &'static Kind = &Kind::Array(Type::Varchar); + V + } + Type::Int8Array => { + const V: &'static Kind = &Kind::Array(Type::Int8); + V + } + Type::PointArray => { + const V: &'static Kind = &Kind::Array(Type::Point); + V + } + Type::LsegArray => { + const V: &'static Kind = &Kind::Array(Type::Lseg); + V + } + Type::PathArray => { + const V: &'static Kind = &Kind::Array(Type::Path); + V + } + Type::BoxArray => { + const V: &'static Kind = &Kind::Array(Type::Box); + V + } + Type::Float4Array => { + const V: &'static Kind = &Kind::Array(Type::Float4); + V + } + Type::Float8Array => { + const V: &'static Kind = &Kind::Array(Type::Float8); + V + } + Type::AbstimeArray => { + const V: &'static Kind = &Kind::Array(Type::Abstime); + V + } + Type::ReltimeArray => { + const V: &'static Kind = &Kind::Array(Type::Reltime); + V + } + Type::TintervalArray => { + const V: &'static Kind = &Kind::Array(Type::Tinterval); + V + } + Type::PolygonArray => { + const V: &'static Kind = &Kind::Array(Type::Polygon); + V + } + Type::OidArray => { + const V: &'static Kind = &Kind::Array(Type::Oid); + V + } + Type::Aclitem => { + const V: &'static Kind = &Kind::Simple; + V + } + Type::AclitemArray => { + const V: &'static Kind = &Kind::Array(Type::Aclitem); + V + } + Type::MacaddrArray => { + const V: &'static Kind = &Kind::Array(Type::Macaddr); + V + } + Type::InetArray => { + const V: &'static Kind = &Kind::Array(Type::Inet); + V + } + Type::Bpchar => { + const V: &'static Kind = &Kind::Simple; + V + } + Type::Varchar => { + const V: &'static Kind = &Kind::Simple; + V + } + Type::Date => { + const V: &'static Kind = &Kind::Simple; + V + } + Type::Time => { + const V: &'static Kind = &Kind::Simple; + V + } + Type::Timestamp => { + const V: &'static Kind = &Kind::Simple; + V + } + Type::TimestampArray => { + const V: &'static Kind = &Kind::Array(Type::Timestamp); + V + } + Type::DateArray => { + const V: &'static Kind = &Kind::Array(Type::Date); + V + } + Type::TimeArray => { + const V: &'static Kind = &Kind::Array(Type::Time); + V + } + Type::Timestamptz => { + const V: &'static Kind = &Kind::Simple; + V + } + Type::TimestamptzArray => { + const V: &'static Kind = &Kind::Array(Type::Timestamptz); + V + } + Type::Interval => { + const V: &'static Kind = &Kind::Simple; + V + } + Type::IntervalArray => { + const V: &'static Kind = &Kind::Array(Type::Interval); + V + } + Type::NumericArray => { + const V: &'static Kind = &Kind::Array(Type::Numeric); + V + } + Type::CstringArray => { + const V: &'static Kind = &Kind::Array(Type::Cstring); + V + } + Type::Timetz => { + const V: &'static Kind = &Kind::Simple; + V + } + Type::TimetzArray => { + const V: &'static Kind = &Kind::Array(Type::Timetz); + V + } + Type::Bit => { + const V: &'static Kind = &Kind::Simple; + V + } + Type::BitArray => { + const V: &'static Kind = &Kind::Array(Type::Bit); + V + } + Type::Varbit => { + const V: &'static Kind = &Kind::Simple; + V + } + Type::VarbitArray => { + const V: &'static Kind = &Kind::Array(Type::Varbit); + V + } + Type::Numeric => { + const V: &'static Kind = &Kind::Simple; + V + } + Type::Refcursor => { + const V: &'static Kind = &Kind::Simple; + V + } + Type::RefcursorArray => { + const V: &'static Kind = &Kind::Array(Type::Refcursor); + V + } + Type::Regprocedure => { + const V: &'static Kind = &Kind::Simple; + V + } + Type::Regoper => { + const V: &'static Kind = &Kind::Simple; + V + } + Type::Regoperator => { + const V: &'static Kind = &Kind::Simple; + V + } + Type::Regclass => { + const V: &'static Kind = &Kind::Simple; + V + } + Type::Regtype => { + const V: &'static Kind = &Kind::Simple; + V + } + Type::RegprocedureArray => { + const V: &'static Kind = &Kind::Array(Type::Regprocedure); + V + } + Type::RegoperArray => { + const V: &'static Kind = &Kind::Array(Type::Regoper); + V + } + Type::RegoperatorArray => { + const V: &'static Kind = &Kind::Array(Type::Regoperator); + V + } + Type::RegclassArray => { + const V: &'static Kind = &Kind::Array(Type::Regclass); + V + } + Type::RegtypeArray => { + const V: &'static Kind = &Kind::Array(Type::Regtype); + V + } + Type::Record => { + const V: &'static Kind = &Kind::Pseudo; + V + } + Type::Cstring => { + const V: &'static Kind = &Kind::Pseudo; + V + } + Type::Any => { + const V: &'static Kind = &Kind::Pseudo; + V + } + Type::Anyarray => { + const V: &'static Kind = &Kind::Pseudo; + V + } + Type::Void => { + const V: &'static Kind = &Kind::Pseudo; + V + } + Type::Trigger => { + const V: &'static Kind = &Kind::Pseudo; + V + } + Type::LanguageHandler => { + const V: &'static Kind = &Kind::Pseudo; + V + } + Type::Internal => { + const V: &'static Kind = &Kind::Pseudo; + V + } + Type::Opaque => { + const V: &'static Kind = &Kind::Pseudo; + V + } + Type::Anyelement => { + const V: &'static Kind = &Kind::Pseudo; + V + } + Type::RecordArray => { + const V: &'static Kind = &Kind::Pseudo; + V + } + Type::Anynonarray => { + const V: &'static Kind = &Kind::Pseudo; + V + } + Type::TxidSnapshotArray => { + const V: &'static Kind = &Kind::Array(Type::TxidSnapshot); + V + } + Type::Uuid => { + const V: &'static Kind = &Kind::Simple; + V + } + Type::UuidArray => { + const V: &'static Kind = &Kind::Array(Type::Uuid); + V + } + Type::TxidSnapshot => { + const V: &'static Kind = &Kind::Simple; + V + } + Type::FdwHandler => { + const V: &'static Kind = &Kind::Pseudo; + V + } + Type::PgLsn => { + const V: &'static Kind = &Kind::Simple; + V + } + Type::PgLsnArray => { + const V: &'static Kind = &Kind::Array(Type::PgLsn); + V + } + Type::TsmHandler => { + const V: &'static Kind = &Kind::Pseudo; + V + } + Type::Anyenum => { + const V: &'static Kind = &Kind::Pseudo; + V + } + Type::TsVector => { + const V: &'static Kind = &Kind::Simple; + V + } + Type::Tsquery => { + const V: &'static Kind = &Kind::Simple; + V + } + Type::GtsVector => { + const V: &'static Kind = &Kind::Simple; + V + } + Type::TsVectorArray => { + const V: &'static Kind = &Kind::Array(Type::TsVector); + V + } + Type::GtsVectorArray => { + const V: &'static Kind = &Kind::Array(Type::GtsVector); + V + } + Type::TsqueryArray => { + const V: &'static Kind = &Kind::Array(Type::Tsquery); + V + } + Type::Regconfig => { + const V: &'static Kind = &Kind::Simple; + V + } + Type::RegconfigArray => { + const V: &'static Kind = &Kind::Array(Type::Regconfig); + V + } + Type::Regdictionary => { + const V: &'static Kind = &Kind::Simple; + V + } + Type::RegdictionaryArray => { + const V: &'static Kind = &Kind::Array(Type::Regdictionary); + V + } + Type::Jsonb => { + const V: &'static Kind = &Kind::Simple; + V + } + Type::JsonbArray => { + const V: &'static Kind = &Kind::Array(Type::Jsonb); + V + } + Type::Anyrange => { + const V: &'static Kind = &Kind::Pseudo; + V + } + Type::EventTrigger => { + const V: &'static Kind = &Kind::Pseudo; + V + } + Type::Int4Range => { + const V: &'static Kind = &Kind::Range(Type::Int4); + V + } + Type::Int4RangeArray => { + const V: &'static Kind = &Kind::Array(Type::Int4Range); + V + } + Type::NumRange => { + const V: &'static Kind = &Kind::Range(Type::Numeric); + V + } + Type::NumRangeArray => { + const V: &'static Kind = &Kind::Array(Type::NumRange); + V + } + Type::TsRange => { + const V: &'static Kind = &Kind::Range(Type::Timestamp); + V + } + Type::TsRangeArray => { + const V: &'static Kind = &Kind::Array(Type::TsRange); + V + } + Type::TstzRange => { + const V: &'static Kind = &Kind::Range(Type::Timestamptz); + V + } + Type::TstzRangeArray => { + const V: &'static Kind = &Kind::Array(Type::TstzRange); + V + } + Type::DateRange => { + const V: &'static Kind = &Kind::Range(Type::Date); + V + } + Type::DateRangeArray => { + const V: &'static Kind = &Kind::Array(Type::DateRange); + V + } + Type::Int8Range => { + const V: &'static Kind = &Kind::Range(Type::Int8); + V + } + Type::Int8RangeArray => { + const V: &'static Kind = &Kind::Array(Type::Int8Range); + V + } + Type::Regnamespace => { + const V: &'static Kind = &Kind::Simple; + V + } + Type::RegnamespaceArray => { + const V: &'static Kind = &Kind::Array(Type::Regnamespace); + V + } + Type::Regrole => { + const V: &'static Kind = &Kind::Simple; + V + } + Type::RegroleArray => { + const V: &'static Kind = &Kind::Array(Type::Regrole); + V + } + Type::Other(ref u) => u.kind(), + } + } + + /// Returns the schema of this type. + pub fn schema(&self) -> &str { + match *self { + Type::Other(ref u) => u.schema(), + _ => "pg_catalog", + } + } + + /// Returns the name of this type. + pub fn name(&self) -> &str { + match *self { + Type::Bool => "bool", + Type::Bytea => "bytea", + Type::Char => "char", + Type::Name => "name", + Type::Int8 => "int8", + Type::Int2 => "int2", + Type::Int2Vector => "int2vector", + Type::Int4 => "int4", + Type::Regproc => "regproc", + Type::Text => "text", + Type::Oid => "oid", + Type::Tid => "tid", + Type::Xid => "xid", + Type::Cid => "cid", + Type::OidVector => "oidvector", + Type::PgDdlCommand => "pg_ddl_command", + Type::Json => "json", + Type::Xml => "xml", + Type::XmlArray => "_xml", + Type::PgNodeTree => "pg_node_tree", + Type::JsonArray => "_json", + Type::Smgr => "smgr", + Type::Point => "point", + Type::Lseg => "lseg", + Type::Path => "path", + Type::Box => "box", + Type::Polygon => "polygon", + Type::Line => "line", + Type::LineArray => "_line", + Type::Cidr => "cidr", + Type::CidrArray => "_cidr", + Type::Float4 => "float4", + Type::Float8 => "float8", + Type::Abstime => "abstime", + Type::Reltime => "reltime", + Type::Tinterval => "tinterval", + Type::Unknown => "unknown", + Type::Circle => "circle", + Type::CircleArray => "_circle", + Type::Money => "money", + Type::MoneyArray => "_money", + Type::Macaddr => "macaddr", + Type::Inet => "inet", + Type::BoolArray => "_bool", + Type::ByteaArray => "_bytea", + Type::CharArray => "_char", + Type::NameArray => "_name", + Type::Int2Array => "_int2", + Type::Int2VectorArray => "_int2vector", + Type::Int4Array => "_int4", + Type::RegprocArray => "_regproc", + Type::TextArray => "_text", + Type::TidArray => "_tid", + Type::XidArray => "_xid", + Type::CidArray => "_cid", + Type::OidVectorArray => "_oidvector", + Type::BpcharArray => "_bpchar", + Type::VarcharArray => "_varchar", + Type::Int8Array => "_int8", + Type::PointArray => "_point", + Type::LsegArray => "_lseg", + Type::PathArray => "_path", + Type::BoxArray => "_box", + Type::Float4Array => "_float4", + Type::Float8Array => "_float8", + Type::AbstimeArray => "_abstime", + Type::ReltimeArray => "_reltime", + Type::TintervalArray => "_tinterval", + Type::PolygonArray => "_polygon", + Type::OidArray => "_oid", + Type::Aclitem => "aclitem", + Type::AclitemArray => "_aclitem", + Type::MacaddrArray => "_macaddr", + Type::InetArray => "_inet", + Type::Bpchar => "bpchar", + Type::Varchar => "varchar", + Type::Date => "date", + Type::Time => "time", + Type::Timestamp => "timestamp", + Type::TimestampArray => "_timestamp", + Type::DateArray => "_date", + Type::TimeArray => "_time", + Type::Timestamptz => "timestamptz", + Type::TimestamptzArray => "_timestamptz", + Type::Interval => "interval", + Type::IntervalArray => "_interval", + Type::NumericArray => "_numeric", + Type::CstringArray => "_cstring", + Type::Timetz => "timetz", + Type::TimetzArray => "_timetz", + Type::Bit => "bit", + Type::BitArray => "_bit", + Type::Varbit => "varbit", + Type::VarbitArray => "_varbit", + Type::Numeric => "numeric", + Type::Refcursor => "refcursor", + Type::RefcursorArray => "_refcursor", + Type::Regprocedure => "regprocedure", + Type::Regoper => "regoper", + Type::Regoperator => "regoperator", + Type::Regclass => "regclass", + Type::Regtype => "regtype", + Type::RegprocedureArray => "_regprocedure", + Type::RegoperArray => "_regoper", + Type::RegoperatorArray => "_regoperator", + Type::RegclassArray => "_regclass", + Type::RegtypeArray => "_regtype", + Type::Record => "record", + Type::Cstring => "cstring", + Type::Any => "any", + Type::Anyarray => "anyarray", + Type::Void => "void", + Type::Trigger => "trigger", + Type::LanguageHandler => "language_handler", + Type::Internal => "internal", + Type::Opaque => "opaque", + Type::Anyelement => "anyelement", + Type::RecordArray => "_record", + Type::Anynonarray => "anynonarray", + Type::TxidSnapshotArray => "_txid_snapshot", + Type::Uuid => "uuid", + Type::UuidArray => "_uuid", + Type::TxidSnapshot => "txid_snapshot", + Type::FdwHandler => "fdw_handler", + Type::PgLsn => "pg_lsn", + Type::PgLsnArray => "_pg_lsn", + Type::TsmHandler => "tsm_handler", + Type::Anyenum => "anyenum", + Type::TsVector => "tsvector", + Type::Tsquery => "tsquery", + Type::GtsVector => "gtsvector", + Type::TsVectorArray => "_tsvector", + Type::GtsVectorArray => "_gtsvector", + Type::TsqueryArray => "_tsquery", + Type::Regconfig => "regconfig", + Type::RegconfigArray => "_regconfig", + Type::Regdictionary => "regdictionary", + Type::RegdictionaryArray => "_regdictionary", + Type::Jsonb => "jsonb", + Type::JsonbArray => "_jsonb", + Type::Anyrange => "anyrange", + Type::EventTrigger => "event_trigger", + Type::Int4Range => "int4range", + Type::Int4RangeArray => "_int4range", + Type::NumRange => "numrange", + Type::NumRangeArray => "_numrange", + Type::TsRange => "tsrange", + Type::TsRangeArray => "_tsrange", + Type::TstzRange => "tstzrange", + Type::TstzRangeArray => "_tstzrange", + Type::DateRange => "daterange", + Type::DateRangeArray => "_daterange", + Type::Int8Range => "int8range", + Type::Int8RangeArray => "_int8range", + Type::Regnamespace => "regnamespace", + Type::RegnamespaceArray => "_regnamespace", + Type::Regrole => "regrole", + Type::RegroleArray => "_regrole", + Type::Other(ref u) => u.name(), + } + } +}