{"record":{"id":"09aa376d5bd785c5","repo":"risingwavelabs/risingwave","slug":"failed-to-prepare-the-statement-0","errorCode":null,"errorMessage":"Failed to prepare the statement: {0}","messagePattern":"Failed to prepare the statement: (.+?)","errorType":"error_code","errorClass":"PsqlError","httpStatus":null,"severity":"error","filePath":"src/utils/pgwire/src/error.rs","lineNumber":51,"sourceCode":"\n    #[error(\"Invalid password\")]\n    PasswordError,\n\n    #[error(\"Protocol violation: {0}\")]\n    ProtocolError(\n        #[source]\n        #[backtrace]\n        ProtocolViolationError,\n    ),\n\n    #[error(\"Failed to run the query: {0}\")]\n    SimpleQueryError(\n        #[source]\n        #[backtrace]\n        BoxedError,\n    ),\n\n    #[error(\"Failed to prepare the statement: {0}\")]\n    ExtendedPrepareError(\n        #[source]\n        #[backtrace]\n        BoxedError,\n    ),\n\n    #[error(\"Failed to execute the statement: {0}\")]\n    ExtendedExecuteError(\n        #[source]\n        #[backtrace]\n        BoxedError,\n    ),\n\n    #[error(transparent)]\n    IoError(#[from] IoError),\n\n    /// Uncategorized error for describe, bind.\n    #[error(transparent)]","sourceCodeStart":33,"sourceCodeEnd":69,"githubUrl":"https://github.com/risingwavelabs/risingwave/blob/6469eb736d691e8e9b8a419a57edd6429ca77417/src/utils/pgwire/src/error.rs#L33-L69","documentation":"pgwire wraps errors from the Parse phase of the extended query protocol into PsqlError::ExtendedPrepareError with this display message. It occurs when preparing (parsing/planning) a statement fails before Bind/Execute can proceed.","triggerScenarios":"A client sends a Parse message (e.g. driver-side prepared statements, PREPARE, or extended protocol usage) and the frontend statement parser or planner returns an error.","commonSituations":"Prepared statement SQL with syntax errors; placeholders/parameter type mismatches the planner cannot resolve; unsupported statements prepared by ORMs or drivers that auto-prepare every query; catalog objects missing at prepare time.","solutions":["Inspect the #[source] BoxedError for the underlying parse/plan error.","Fix the statement SQL or parameter type declarations sent in the Parse message.","Disable automatic server-side prepared statements in the client driver if it prepares unsupported statements (e.g. prefer_simple_protocol / prepareThreshold=0 options).","Verify referenced objects exist and the user has permission to plan the statement."],"exampleFix":"// before: ORM prepares every query\nlet pool = Pool::connect(\"postgres://.../rw\");\n// after: use simple protocol to skip prepare phase\nlet pool = Pool::connect(\"postgres://.../rw?prefer_simple_protocol=true\");","handlingStrategy":"try-catch","validationCode":"// validate statement and parameter type hints before Parse\nif placeholder_count(sql) != param_types.len() { return Err(\"placeholder/type count mismatch\"); }","typeGuard":"fn is_extended_prepare_error(e: &PsqlError) -> bool { matches!(e, PsqlError::ExtendedPrepareError(_)) }","tryCatchPattern":"match client.prepare(sql, &[Type::TEXT]).await {\n    Err(e) if is_extended_prepare_error(&e) => { log::error!(\"prepare failed: {e}; cause: {:?}\", e.source()); fallback_to_simple_query(sql); }\n    other => other,\n}","preventionTips":["Configure drivers that auto-prepare everything to use simple protocol against RisingWave when preparation errors recur.","Declare explicit parameter types matching the planner's expectations.","Test prepared statements against RisingWave-specific SQL support before deploying ORMs."],"tags":["pgwire","sql","prepared-statement","extended-protocol"],"backgroundTag":"sql-query-failed","analyzedSha":"6469eb736d691e8e9b8a419a57edd6429ca77417","analyzedAt":"2026-09-11T21:06:21.487Z","contentChangedAt":"2026-09-11T21:06:21.487Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}