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
In PostgreSQL, allow spaces in table names without schema #26722
Conversation
I don't see why we'd want to treat The current intention appears to be that the table name is treated as an unquoted identifier, meaning |
@@if so, it's inconsistent with the mysql/sqlite adapter behavior, which appear to handle table names with spaces as a quoted identifier and have no problem with just "foo bar". Then again, they are the outliers in not having separate schema/database concepts, so maybe there's an argument for different behavior. Honestly, I don't understand why the white space is checked in that regex at all. Is it intentionally another option for specifying schema? White space isn't shown in any of the test cases, and the only way I know to specify schema is with a dot. This fix doesn't preclude handling the parsing logic any way we want, so actual table names with dots in them (lord help us :-D) are still handled correctly. If there's no dot though, there simply can't be a schema, so it should be treated as a quoted identifier, in my opinion. |
74231f5
to
956ad95
Compare
If your table name has spaces (e.g. ‘work orders’) and you don’t specify schema or use quotes, the postgresql adapter would use the first word as schema. This fix interprets as table name unless it contains a dot.
Looks like it's been an undocumented behaviour since #1632. As is, this would change (read: break) handling of Let's go the safest route, and deprecate unquoted spaces -- leave it parsing as a schema for now (and users can quote for the table-name-with-spaces interpretation), then look at stricter options later. |
Good point! I added a test for quoted strings without a schema, and I don't believe this changes any behavior with ""foo"" because strings are unquoted by the Name class. The different behavior should only be with quotes and spaces when there's no dot in the string. Malformed double quotes for instance. Some examples I can think of:
All of these examples were erroneous before, though. I definitely won't say that there are no legitimate identifiers that would be broken, but I can't think of any. Regarding #1632, I didn't see any reasoning for the use of |
This doesn't seem sufficiently far-fetched to me that we can silently change it. (The others do seem inconsequential.) So, I agree the |
That sounds good. Thanks for helping me on this. |
Summary
Fix for #26721 by checking for a dot before parsing out schema. Test case added.
Other Information
If your table name has spaces (e.g. ‘work orders’) and you don’t
specify schema or use quotes, the postgresql adapter would use the
first word as schema. This fix interprets as table name unless it
contains a dot.
This function has previously been the source of performance issues. This change should cause a slight performance penalty when the schema is included, and improve performance when it's not.
I benchmarked this patch in rails 4.2.7 by running the test cases for 20s:
First time contributor here! Hope I can get this to PR a usable state.