2

I am trying to query from a database called physionet-data.mimiciii_clinical.diagnoses_icd

PostgresSQL returns the following error message:

quan.sql:273: ERROR:  syntax error at or near "`"
LINE 132: from `physionet-data.mimiciii_clinical.diagnoses_icd` icd

I think it is caused by the dash. If I change the `for ' the same error comes up

quan.sql:273: ERROR:  syntax error at or near
"'physionet-data.mimiciii_clinical.diagnoses_icd'"

Any clue on how to fix that?

  • https://www.postgresql.org/docs/current/sql-syntax-lexical.html#SQL-SYNTAX-IDENTIFIERS –  Dec 06 '20 at 11:49

1 Answers1

2

You would need to quote that schema name, using double-quotes:

select ...
from "physionet-data".mimiciii_clinical.diagnoses_icd

Note that quoting an identifier makes it case-sensitive. You would need to ensure that the character case the schema was created with matches the one you are using here.

Using identifiers that require quoting is not a good idea in general; as you are fiding out, this requires quoting them every where you use it later on. If that's not too late, I would recommend changing the schema name to a name that does not require quoting.

GMB
  • 216,147
  • 25
  • 84
  • 135
  • Hi @GMB! Thank you for your swift response :) Unfortunately, I can't change the schema name, it's a public db... I tried your solution but it did not work out. I got: LINE 132: from "physionet-data".mimiciii_clinical.diagnoses_icd icd ^ Could this be because the from goes first in the code, as follows: `from "physionet-data".mimiciii_clinical.diagnoses_icd icd where ... select ...` The Github page for the code is there: https://github.com/MIT-LCP/mimic-code/blob/master/concepts/comorbidity/elixhauser_quan.sql – Lucile Ter-Minassian Dec 06 '20 at 11:59
  • Could you explain a bit more what you mean by "You would need to ensure that the character case the schema was created with matches the one you are using here" please ? – Lucile Ter-Minassian Dec 06 '20 at 12:03
  • @LucileTer-Minassian: I mean that if your schema was created with mixed upper/lower case, then you need to use that in your query. See: https://wiki.postgresql.org/wiki/Don't_Do_This#Don.27t_use_upper_case_table_or_column_names – GMB Dec 06 '20 at 12:27
  • oh, I see! I think the schema is all lower case so we're good on that side. but if double quotation marks don't work, are there other alternatives? – Lucile Ter-Minassian Dec 06 '20 at 14:27