Postgres solving a syntax error caused by a dash (-) - sql

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?

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.

Related

Consistent Missing Right Parenthesis Error

I'm trying to right a query that checks if the value is a number and I keep getting a
ORA-00907: missing right parenthesis
error no matter what I do.
Even these queries return the error:
SELECT CAST(123456 AS NUMBER(1,0) DEFAULT -1 ON CONVERSION ERROR)
FROM ANY_TABLE_NAME
SELECT VALIDATE_CONVERSION('99' AS NUMBER)
FROM ANY_TABLE_NAME
Anything I can do to solve this?
I'm using Oracle SQL Developer version 20.2.1.175
VALIDATE_CONVERSION was not introduced until Oracle 12.2.
CAST also did not get the error handling extension until Oracle 12.2.
Therefore, if you are using Oracle 12.1 or earlier then those functions will not be valid.
For example:
They fail in Oracle 11g db<>fiddle
The work in Oracle 18g db<>fiddle
Note: this is the Oracle database version and not the version of SQL Developer, which is just a front-end user interface for accessing the database.
ORA-00907: missing right parenthesis
This error belongs to generic error messages, indicating one or more syntax errors.
How to debug ?
it means we have omitted a right bracket.
(to verify, you can use an editor which allows a "match bracket" control)
it means the compiler received an "out of context" keyword.
it means a misspelled word (i.e a missing comma, a space instead of an underscore,etc )
Your sinthax seems to be right.
You're (probably) facing an "out of context" keyword.

How would I fix these "ORA-00933: SQL command not properly ended" "ORA-00923: FROM keyword not found where expected" errors?

This Statement:
SELECT id, units, cost FROM inventory_list WHERE cost <= 20;
Gives me:
ORA-00923: FROM keyword not found where expected
While this statement:
SELECT * FROM items WHERE ilt_id = 'il010230126' OR ilt_id = 'il010230128';
Gives me:
ORA-00933: SQL command not properly ended
Not sure about this and may be version dependent (below link is for oracle 10g... but you can see on this site
https://docs.oracle.com/cd/B19306_01/em.102/b40103/app_oracle_reserved_words.htm
That cost is an oracle reserved keyword, so it is not wise to use it as a column name.
If you have no control of the table I think you may be able to surround it in double quotes eg select "COST" to avoid oracle picking it up as a reserved word.
By default Oracle creates fields in uppercase so the field name will need to be in uppercase unless when the table was created it was forced into different case by surrounding it in Quotes.
Check that you don't have invisible characters in your file and that you're using the right encoding. I sometimes accidentally introduce them because I have a non english keyboard map and accidentally hit the wrong key combination.
Just type again one of your SQL statements and test them.

psql restore sql dump syntax error

I am trying to import https://www.yelp.com/dataset/documentation/sql into a PostgreSQL instance. It is having problems with accent marks/backtick. Other than doing a character replace, is there any other way to deal with this?
ERROR: syntax error at or near "PaxHeader"
LINE 1: PaxHeader/yelp_db.sql17 uid=998889796
^
ERROR: syntax error at or near "`"
LINE 1: CREATE DATABASE /*!32312 IF NOT EXISTS*/ `yelp_db` /*!40100 ...
^
ERROR: syntax error at or near "USE"
LINE 1: USE `yelp_db`;
^
ERROR: syntax error at or near "`"
LINE 1: DROP TABLE IF EXISTS `attribute`;
These are typical MySQL syntax issues that PostgreSQL conforms to the standard on and therefore doesn't support. There are a few different converters on GitHub that might help. When I had to do this last, there were tools to convert text dumps. They didn't work perfectly but they got things close enough. Reviewing the tools around today, they tend to assume you have an actual MySQL database, not just a dump file.
So it looks like the appropriate way to address this today is to load the data into MySQL and then move it to PostgreSQL. In this regard you seem to have four options that I can think of for converting the schema and data:
There are tools to convert XML dumps from MySQL and load these into PostgreSQL.
You could set up a foreign data wrapper from PostgreSQL to the MySQL db and then copy the schemas and data in.
You could manually convert the schemas, and then dump/reload the data using an ETL process via CSV.
There are tools to read a live MySQL database and insert the data into PostgreSQL.

ORA-01741: illegal zero-length identifier

Hi I am using a delete query in my shell script and I am facing this issue.
delete from WHITELIST_CLI where filecode like'%Line_Index_condense%';
Error:
ERROR:
ORA-01741: illegal zero-length identifier
Here is some information on the error:
ORA-01741: illegal zero-length identifier
Cause: An attempt was made to use two double quotes ("") as an
identifier. An identifier must be at least one character long.
Your query has nothing of the sort. This may be an interaction between ksh and Oracle. Or you may have used double quotes when you mean single quotes. Or, you may have oversimplified the query when you posted the question. Or another query may be the issue.
Here is a simple example of the error on SQL Fiddle.

Sql error with backquotes, says there's a syntax error at or near "`"

I'm trying to load a database into Heroku from a sql file, however I get a syntax error from back quotes / backticks.
heroku pg:psql < backup.sql
Outputs this error:
syntax error at or near "`"
Why is that? Aren't backquotes valid?
I can find/replace them with something else if that would be good to try.
are you restoring from a postgresql system or another db software such mySQL?
can you search your backup.sql file for the back-ticks and post that section of your file?
it would help to know if your back-ticks are in the column field names or in the data portion of the SQL statement.