I have a question about escaping table names if anyone might have some insight. I'm working with oracle db and have a table named "slash_table/". I can call .getColumns
on the DatabaseMetaData if I use a table name of "slash_table//" and escape the slash myself. However, it returns a tablename of "slash_table/" unescaped. This seems strange to me.
(-> (jdbc/with-db-metadata [metadata (->spec database)]
(jdbc/result-set-seq (.getColumns metadata nil "HR" "slash_table//" nil)))
first
:table_name)
returns "slash_table/"
.I would expect that the table name returned would be a valid table name but that doesn't appear to be so
running the above with "slash_table/"
as the tablename results in ORA-01424: missing or illegal character following the escape character
Not to further confuse things, but '/' is not the escape character '\' is
Did you try "\"slash_table/\""
i.e., SQL-quoting the name? Not sure if JDBC respects that.
"\"slash_table/\""
- missing or illegal character
"\"slash_table//\""
no error but not matching the table
"\"slash_table\/\""
unsupported escape character \/
"slash_table/"
missing or illegal character
"slash_table//"
-> `"slash_table/"
however, when inserting the quotes work: (jdbc/insert! oracle "hr.\"foo//bar\"" {:column1 "single slash?"})
but there they don't need to be escaped (jdbc/query oracle "select * from hr.\"foo/bar\"")
(i have a table foo/bar and foo//bar for testing
the way to escape / would be \\/ which I don't think you tried
you want \/, to get it you need to exscape \ for string literals, hence the \\
ah right. "\"slash_table\\/\""
missing or illegal character
databases are weird... ¯\(ツ)/¯
haha yes they sure are. thank you both for your help so far. i think i'm in for a rough time figuring out when to escape and when not to ...