{"record":{"id":"ec47b5c86a59ee42","repo":"nautechsystems/nautilus_trader","slug":"failed-to-insert-into-quote-table-e","errorCode":null,"errorMessage":"Failed to insert into quote table: {e}","messagePattern":"Failed to insert into quote table: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/infrastructure/src/sql/queries.rs","lineNumber":1313,"sourceCode":"                $1, $2, $3, $4, $5, $6, $7, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP\n            )\n            ON CONFLICT (id)\n            DO UPDATE\n            SET\n                instrument_id = $1, bid_price = $2, ask_price = $3, bid_size = $4, ask_size = $5,\n                ts_event = $6, ts_init = $7, updated_at = CURRENT_TIMESTAMP\n        \"#)\n            .bind(quote.instrument_id.to_string())\n            .bind(quote.bid_price.to_string())\n            .bind(quote.ask_price.to_string())\n            .bind(quote.bid_size.to_string())\n            .bind(quote.ask_size.to_string())\n            .bind(quote.ts_event.to_string())\n            .bind(quote.ts_init.to_string())\n            .execute(pool)\n            .await\n            .map(|_| ())\n            .map_err(|e| anyhow::anyhow!(\"Failed to insert into quote table: {e}\"))\n    }\n\n    /// Loads all `QuoteTick` entries for `instrument_id` via the provided `pool`.\n    ///\n    /// # Errors\n    ///\n    /// Returns an error if the SQL SELECT or deserialization fails.\n    pub async fn load_quotes(\n        pool: &PgPool,\n        instrument_id: &InstrumentId,\n    ) -> anyhow::Result<Vec<QuoteTick>> {\n        sqlx::query_as::<_, QuoteTickRow>(\n            r#\"SELECT * FROM \"quote\" WHERE instrument_id = $1 ORDER BY ts_event ASC\"#,\n        )\n        .bind(instrument_id.to_string())\n        .fetch_all(pool)\n        .await\n        .map(|rows| rows.into_iter().map(|row| row.0).collect())","sourceCodeStart":1295,"sourceCodeEnd":1331,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/infrastructure/src/sql/queries.rs#L1295-L1331","documentation":"Fired when the PostgreSQL upsert of a QuoteTick row into the quote table fails — e.g. connection failure, query execution error, or a constraint/type error from binding the instrument_id, bid/ask price and size, and timestamp values as strings. The write-and-on-conflict-update statement did not complete, so the quote was not persisted.","triggerScenarios":"Calling `add_quote(pool, &quote)` when the `quote` table is missing (no migrations), a bind value cannot be cast to the Postgres column type, a constraint fails, or the connection/pool is broken.","commonSituations":"Schema drift after upgrades (e.g. bid_size/ask_size column changes); missing enum types; DB down or credentials wrong; inserting many quotes in a tight loop with pool exhaustion.","solutions":["Run migrations to create the `quote` table and enum types","Compare the bound quote fields against the current table schema and fix mismatched columns/types","Check the wrapped sqlx error for the concrete constraint or cast failure","Verify pool connectivity and consider batching inserts in a transaction"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"sqlx::query(\"SELECT 1 FROM quote LIMIT 1\").fetch_optional(pool).await.map_err(|e| anyhow::anyhow!(\"quote table check: {e}\"))?;","typeGuard":null,"tryCatchPattern":"if let Err(e) = add_quote(&pool, &quote).await {\n    tracing::error!(\"quote insert failed: {e:#}\");\n    return Err(e.into());\n}","preventionTips":["Migrate schema before writing quotes","Match bound fields to current table columns after upgrades","Batch quotes in a transaction"],"tags":["database","insert","sql","postgres"],"backgroundTag":"database-write-failed","analyzedSha":"18893faf8b356be3320add8de2f861b0b647cf06","analyzedAt":"2026-09-08T20:49:34.690Z","contentChangedAt":"2026-09-08T20:49:34.690Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}