{"record":{"id":"af77b7185acbebab","repo":"databendlabs/databend","slug":"can-not-use-connection-name-when-create-connection","errorCode":null,"errorMessage":"can not use connection_name when create connection","messagePattern":"can not use connection_name when create connection","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/query/sql/src/planner/binder/location.rs","lineNumber":549,"sourceCode":"            ErrorKind::InvalidInput,\n            anyhow!(\"protocol {protocol} is not supported yet.\"),\n        ));\n    }\n\n    Ok(ParsedUriLocation {\n        root,\n        path,\n        protocol,\n    })\n}\n\npub async fn parse_uri_location(l: &mut UriLocation) -> Result<(StorageParams, String)> {\n    let parts = parse_uri_location_parts(l)?;\n\n    if l.connection.get(\"connection_name\").is_some() {\n        return Err(Error::new(\n            ErrorKind::InvalidInput,\n            anyhow!(\"can not use connection_name when create connection\"),\n        ));\n    }\n\n    parse_uri_location_resolved(l, parts).await\n}\n\npub fn apply_uri_connection(\n    l: &mut UriLocation,\n    name: &str,\n    conn: UserDefinedConnection,\n) -> Result<()> {\n    let protocol = l.protocol.parse::<Scheme>()?;\n    let proto = conn.storage_type.parse::<Scheme>().map_err(|err| {\n        Error::new(\n            ErrorKind::InvalidInput,\n            anyhow!(\"input connection is not a valid protocol: {err:?}\"),\n        )\n    })?;","sourceCodeStart":531,"sourceCodeEnd":567,"githubUrl":"https://github.com/databendlabs/databend/blob/288d84d76e20a2f8f7173bda9691eb6ece301aa9/src/query/sql/src/planner/binder/location.rs#L531-L567","documentation":"parse_uri_location builds storage params directly from inline CONNECTION options and a URI, so referencing a named connection (connection_name) is meaningless and disallowed there. If the connection options include connection_name while creating a connection or resolving a URI location, this InvalidInput error is thrown.","triggerScenarios":"CREATE CONNECTION ... CONNECTION=(CONNECTION_NAME='other') — nesting a connection reference inside connection creation; passing a connection_name option in a stage/connection DDL that resolves URI options inline.","commonSituations":"Confusing named-connection usage (USE CONNECTION / CONNECTION_NAME on stages) with CREATE CONNECTION DDL; templated SQL that always injects CONNECTION_NAME.","solutions":["Remove CONNECTION_NAME from the inline CONNECTION options in CREATE CONNECTION","Specify the actual storage options (endpoint_url, credentials, etc.) inline instead","Use the named connection where allowed (e.g. in stage definitions), not when creating a connection"],"exampleFix":"-- before\nCREATE CONNECTION c CONNECTION=(CONNECTION_NAME='prod_s3');\n-- after\nCREATE CONNECTION c STORAGE_TYPE='s3' ENDPOINT_URL='https://s3.amazonaws.com';","handlingStrategy":"validation","validationCode":"if opts.contains_key(\"connection_name\") && is_create_connection_ddl {\n    return Err(\"CONNECTION_NAME cannot be used inside CREATE CONNECTION\".into());\n}","typeGuard":null,"tryCatchPattern":"match err.kind() { ErrorKind::InvalidInput if msg.contains(\"can not use connection_name\") => /* strip CONNECTION_NAME and inline real options */, _ => return Err(err) }","preventionTips":["Never nest CONNECTION_NAME inside CREATE CONNECTION","Use named connections only where supported (stage definitions)","Generate DDL from templates that exclude connection_name for create-connection paths"],"tags":["sql","connection","validation"],"backgroundTag":"mutually-exclusive-options","analyzedSha":"288d84d76e20a2f8f7173bda9691eb6ece301aa9","analyzedAt":"2026-09-11T11:29:36.208Z","contentChangedAt":"2026-09-11T11:29:36.208Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}