evidence-dev / evidence

Business intelligence as code: build fast, interactive data visualizations in pure SQL and markdown
https://evidence.dev
MIT License
3.38k stars 164 forks source link

Dash in postgres schema name crashes app #1906

Closed mitchwd closed 2 weeks ago

mitchwd commented 2 weeks ago

Steps To Reproduce

  1. Create a new connection, to a postgres database with a dash in the schema name:
    name: Mitch_Local
    type: postgres
    options:
    host: localhost
    port: 5432
    database: postgres
    schema: mitch-api

Environment

Expected Behavior

Evidence should allow connecting to schemas with dashes in the name.

Actual Behaviour

Application attempts to run, then crashes:

npm run sources

> my-evidence-project@0.0.1 sources
> evidence sources

Processing Mitch_Local
syntax error at or near "-"

Alternatively, this can be triggered via the browser: Settings > Edit data source > Click Test Connection > Application crashes in terminal:

error: syntax error at or near "-"
    at /Users/mitchwd/projects/evidence/node_modules/pg/lib/client.js:526:17
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
  length: 90,
  severity: 'ERROR',
  code: '42601',
  detail: undefined,
  hint: undefined,
  position: '22',
  internalPosition: undefined,
  internalQuery: undefined,
  where: undefined,
  schema: undefined,
  table: undefined,
  column: undefined,
  dataType: undefined,
  constraint: undefined,
  file: 'scan.l',
  line: '1176',
  routine: 'scanner_yyerror'
}

Workarounds

I've attempted to wrap my schema name in single and double quotes, with no luck. :'(

archiewood commented 2 weeks ago

This is being thrown at the underlying connector level as it is not receiving a quoted value, and this must be a quoted identifier to contain a hyphen.

YAML allows you to specify quotes:

Or else:

mitchwd commented 2 weeks ago

Thanks Archie. I was able to resolve it by escaping the quotes. For anyone else's reference, this worked:

name: Mitch_Local
type: postgres
options:
  host: localhost
  port: 5432
  database: postgres
  schema: |
    "mitch-api"