Quoting of database name appears to be broken in get_tables_by_pattern_sql
- Dominant language
- Makefile
- Stars
- 1.8k
- Forks
- 632
- PR merge metrics
- No merged PRs in 30d
Description
### Describe the bug
`get_relations_by_prefix()` appears to be broken on Postgres when the database name contains e.g. a hyphen.
### Steps to reproduce
Use the following in a database of which the name contains a hyphen.
```
{% set relations = dbt_utils.get_relations_by_prefix('some_schema', 'prefix') %}
```
### Expected results
```
19:03:39 Completed successfully
```
### Actual results
```
18:55:53 Finished running 1 table model, 1 project hook in 0 hours 0 minutes and 2.15 seconds (2.15s).
18:55:53
18:55:53 Completed with 1 error and 0 warnings:
18:55:53
18:55:53 Database Error in model some_model (models/kpis.sql)
syntax error at or near "-"
LINE 19: from foo-bar.information_schema.tables
```
### System information
**The contents of your `packages.yml` file:**
```
packages:
- package: dbt-labs/dbt_utils
version: 1.1.1
- package: calogica/dbt_expectations
version: 0.10.1
- package: calogica/dbt_date
version: 0.10.0
- package: Snowflake-Labs/dbt_constraints
version: [">=0.6.0", "<0.7.0"]
- package: pvcy/dbt_privacy
version: 0.3.1
```
**Which database are you using dbt with?**
- [x] postgres
- [ ] redshift
- [ ] bigquery
- [ ] snowflake
- [ ] other (specify: ____________)
**The output of `dbt --version`:**
```
Core:
- installed: 1.8.1
- latest: 1.8.1 - Up to date!
Plugins:
- postgres: 1.8.1 - Up to date!
```
### Additional context
### Are you interested in contributing the fix?
PR is here: https://github.com/dbt-labs/dbt-utils/pull/899
Contributor guide
Research direction
Start by locating the get_relations_by_prefix entry point and the get_tables_by_pattern_sql implementation named in the issue. Reproduce the call against Postgres with a hyphenated database name, then verify that the generated relation lookup completes successfully without a syntax error near the hyphen.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- postgresql, sql
- Domain
- databases
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 30/100