SeaQL/sea-orm · error

Not Postgres Connection

Error message

Not Postgres Connection

What it means

`get_postgres_connection_pool()` unwraps the inner `SqlxPostgresPoolConnection` to return the raw `sqlx::PgPool`; all other `DatabaseConnectionType` variants fall into the `_ =>` arm and panic. It is only valid on a live PostgreSQL connection. `support_returning` on the Postgres pool path is where callers have hit it when the handle is not actually Postgres.

Source

Thrown at src/database/db_connection.rs:844

    /// Panics if [DbConn] is not a MySQL connection.
    #[cfg(feature = "sqlx-mysql")]
    pub fn get_mysql_connection_pool(&self) -> &sqlx::MySqlPool {
        match &self.inner {
            DatabaseConnectionType::SqlxMySqlPoolConnection(conn) => &conn.pool,
            _ => panic!("Not MySQL Connection"),
        }
    }

    /// Get [sqlx::PgPool]
    ///
    /// # Panics
    ///
    /// Panics if [DbConn] is not a Postgres connection.
    #[cfg(feature = "sqlx-postgres")]
    pub fn get_postgres_connection_pool(&self) -> &sqlx::PgPool {
        match &self.inner {
            DatabaseConnectionType::SqlxPostgresPoolConnection(conn) => &conn.pool,
            _ => panic!("Not Postgres Connection"),
        }
    }

    /// Get [sqlx::SqlitePool]
    ///
    /// # Panics
    ///
    /// Panics if [DbConn] is not a SQLite connection.
    #[cfg(feature = "sqlx-sqlite")]
    pub fn get_sqlite_connection_pool(&self) -> &sqlx::SqlitePool {
        match &self.inner {
            DatabaseConnectionType::SqlxSqlitePoolConnection(conn) => &conn.pool,
            _ => panic!("Not SQLite Connection"),
        }
    }
}

impl DbBackend {

View on GitHub (pinned to e29bcd1b41)

Solutions

  1. Guard with `if db.get_database_backend() == DbBackend::Postgres` before extracting the pool.
  2. Correct the `DATABASE_URL`/config so the app actually connects to PostgreSQL.
  3. Move Postgres-specific logic (e.g. RETURNING clauses) behind a backend check instead of assuming the pool type.
  4. Keep mock/disconnected handles away from backend-specific extraction methods.

Example fix

// before
let pool = db.get_postgres_connection_pool(); // panics on non-PG backends

// after
if db.get_database_backend() == DbBackend::Postgres {
    let pool = db.get_postgres_connection_pool();
} else {
    return Err(anyhow!("Postgres connection required"));
}
Defensive patterns

Strategy: type-guard

Validate before calling

if conn.get_database_backend() != DbBackend::Postgres {
    return Err(anyhow!("get_postgres_connection_pool requires a Postgres backend"));
}

Type guard

fn as_pg_pool(conn: &DatabaseConnection) -> Option<&sqlx::PgPool> {
    (conn.get_database_backend() == DbBackend::Postgres)
        .then(|| conn.get_postgres_connection_pool())
}

Try / catch

std::panic::catch_unwind(|| conn.get_postgres_connection_pool()) // last resort; prefer backend check

Prevention

When it happens

Trigger: Calling `db.get_postgres_connection_pool()` (directly or via Postgres-only paths like RETURNING support checks) on a MySQL/SQLite/mock/disconnected connection.

Common situations: Backend-agnostic code that calls Postgres-specific APIs; CI environment variables pointing at MySQL while the code assumes Postgres; swapping the database URL for a local SQLite dev DB.

Understand the failure class

Background: "is not a compatible type" / "cannot merge" errors: when a value's type doesn't match what the library requires — this error's family across 65 libraries.

Related errors


AI-assisted analysis of SeaQL/sea-orm@e29bcd1b41 (2026-09-10). Data as JSON: /api/errors/ac8fe19fb21aceb8. Report an issue: GitHub.