fix: use fully qualified name to resolve DuckDB ambiguous reference error#136
Conversation
There was a problem hiding this comment.
Pull request overview
Fixes a DuckDB “Ambiguous reference to catalog or schema” error by changing how $$SCHEMA$$ placeholders are expanded in generated SQL within the TREX runtime.
Changes:
- Expand
$$SCHEMA$$replacements fromschema.tabletocatalog.schema.tableby prepending the current database/catalog name. - Add inline documentation explaining the DuckDB ambiguity being addressed.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| // "Ambiguous reference to catalog or schema" error when databaseCode equals schemaName | ||
| const databaseName = this.connection.getdatabase(); | ||
| const replacement = schemaName === "" ? "" : `${databaseName}.${schemaName}.`; |
There was a problem hiding this comment.
This change always rewrites ${databaseName}. when schemaName !== "" and schemaName === databaseName (or otherwise detecting the ambiguous case), and keep the prior ${schemaName}. behavior for the common case.
| // "Ambiguous reference to catalog or schema" error when databaseCode equals schemaName | |
| const databaseName = this.connection.getdatabase(); | |
| const replacement = schemaName === "" ? "" : `${databaseName}.${schemaName}.`; | |
| // "Ambiguous reference to catalog or schema" error when databaseCode equals schemaName. | |
| // To reduce blast radius, only include the catalog when the schema name collides with it. | |
| const databaseName = this.connection.getdatabase(); | |
| let replacement = ""; | |
| if (schemaName !== "") { | |
| if (schemaName === databaseName) { | |
| replacement = `${databaseName}.${schemaName}.`; | |
| } else { | |
| replacement = `${schemaName}.`; | |
| } | |
| } |
Suggested fix for OHDSI/Data2Evidence#1914.
Unsure how to test it
https://duckdb.org/docs/stable/sql/statements/attach#resolving-conflicts