Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PRESERVE_CASE doesn't preserve case in VIEWs and CHECK constraints #1047

Open
otterrisk opened this issue Dec 7, 2020 · 6 comments
Open

Comments

@otterrisk
Copy link

otterrisk commented Dec 7, 2020

Setting PRESERVE_CASE to 1 and migrating an Oracle schema gives expected results on CREATE/ALTER TABLE statements, etc., i.e. table names in the resulting table.sql are double quoted upper case (e.g. CREATE TABLE "MY_TABLE"). However, CREATE OR REPLACE VIEW statements in the resulting view.sql have unquoted table names in AS clauses, which results in:

psql:./schema/views/view.sql:X: ERROR:  relation "my_table" does not exist
LINE 2:      FROM MY_TABLE
                  ^
ERROR: an error occurs when importing file ./schema/views/view.sql.

kind of errors. Similar thing happens when table definitions contain CHECK constraints, which result in unquoted table names as well.

Ora2Pg v21.0

@darold
Copy link
Owner

darold commented Dec 8, 2020

Yes, Ora2Pg can only quote identifier when they are fully qualified otherwise there is nothing which makes it possible to distinguish an identifier from a keyword in a view definition. Ora2Pg doesn't embed a SQL parser. Won't be fixed.

@otterrisk
Copy link
Author

Just an idea... Ora2Pg knows table and column names from the scanning stage anyway. It doesn't need to understand SQL in order to double-quote a set of known identifiers in the post-processing stage. Wouldn't that be the way to go?

@darold
Copy link
Owner

darold commented Dec 9, 2020

Yes why not, this will slow down the view export but once it is done it is done. But honestly why preserving the Oracle case? Does your queries systematically used double quote for identifiers? In all migration I have done PRESERVE_CASE was disabled because it has no interest in keeping thing upper cases only.

@otterrisk
Copy link
Author

I am using an ORM framework in Python, which happens to be case sensitive with respect to table/column names. My code (18k LOC) used to work with an Oracle database, so all names (which are hard-coded for a good reason) are upper case. Now we are migrating to a PostgreSQL database, and changing table/column names in the code would break the Oracle connectivity, which we need to keep.

@darold
Copy link
Owner

darold commented Dec 9, 2020

Ok good to know that there is good reasons to have upper case forced in Oracle, I hope to never encounter such a case :-) However if there is a PRESERVE_CASE configuration directive this is to allow that, I mark the issue as needing enhancement to gather table+column names before migrating view to be able to find them in the view source code definition. Thanks for the report.

@otterrisk
Copy link
Author

I meant hard-coding table/column names in general has a good reason ;-) The ORM framework derives table names from class names by default. Hard-coding them is a security measure, to prevent class name refactoring from braking the ORM mapping. But once you opted for hard-coding names, you need to decide for the case as well. It turns out that the particular framework I am using is case sensitive under the hood.

Thanks for considering my report as an enhancement! With some guidance from your side I could help getting it done.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants