pgerror.go 1.0 KB

123456789101112131415161718192021222324252627282930
  1. // Package pgerror holds SQLSTATE metadata and sentinel errors shared by the
  2. // parser, executor, and protocol servers.
  3. package pgerror
  4. import (
  5. "errors"
  6. "fmt"
  7. )
  8. // SQLSTATE codes used by PizzaSQL's protocol and HTTP surfaces.
  9. const (
  10. CodeFeatureNotSupported = "0A000"
  11. CodeUniqueViolation = "23505"
  12. CodeForeignKeyViolation = "23503"
  13. CodeCheckViolation = "23514"
  14. CodeSerializationFailure = "40001"
  15. CodeSyntaxError = "42601"
  16. CodeInternalError = "XX000"
  17. )
  18. // ErrFeatureNotSupported marks SQL that PizzaSQL intentionally rejects instead
  19. // of accepting with different semantics. Protocol layers map it to SQLSTATE
  20. // 0A000 (feature_not_supported) rather than a generic syntax or internal error.
  21. var ErrFeatureNotSupported = errors.New("feature not supported")
  22. // Unsupported returns an error that wraps ErrFeatureNotSupported with a
  23. // client-facing explanation and migration hint.
  24. func Unsupported(format string, args ...interface{}) error {
  25. return fmt.Errorf("%w: %s", ErrFeatureNotSupported, fmt.Sprintf(format, args...))
  26. }