-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
Enabled capitzalized table names for sequence reset #19825
Conversation
🦋 Changeset detectedLatest commit: 0c5b7a4 The changes in this PR will be included in the next version bump. This PR includes changesets to release 2 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
shout out to @paescuj for the support 🎉 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! ❤️
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! Out of curiosity, tried to looked up more info from the official docs regarding this and they do seem to support the actual fix and reasoning behind the quotes around table name, but not needed for column name.
pg_get_serial_sequence ( table text, column text ) → text
Because the first parameter potentially contains both schema and table names, it is parsed per usual SQL rules, meaning it is lower-cased by default. The second parameter, being just a column name, is treated literally and so has its case preserved.
Link to above reference
Quoting an identifier also makes it case-sensitive, whereas unquoted names are always folded to lower case. For example, the identifiers FOO, foo, and "foo" are considered the same by PostgreSQL, but "Foo" and "FOO" are different from these three and each other. (The folding of unquoted names to lower case in PostgreSQL is incompatible with the SQL standard, which says that unquoted names should be folded to upper case. Thus, foo should be equivalent to "FOO" not "foo" according to the standard. If you want to write portable applications you are advised to always quote a particular name or never quote it.)
Link to above reference
* escaped identifiers * fix * used parameters for values and knex for escaping identifiers * changeset * Update api/src/database/helpers/sequence/dialects/postgres.ts * Update .changeset/silver-cars-hear.md --------- Co-authored-by: Pascal Jufer <pascal-jufer@bluewin.ch> Co-authored-by: Azri Kahar <42867097+azrikahar@users.noreply.github.com>
Closes #19817
When looking up the auto increment sequence name for a table which is capitalized, PostgreSQL throwed an error saying
relation xy does not exist
. The table name needed explicit quotes, otherwise PostgreSQL used a lowercase variant of the table name automatically and couldn't resolve some (internal) relationship (I guess).So the table name for the
pg_get_serial_sequence
function call, which need to be passed as string, needed to be escaped.In addition of just escaping the value to the
pg_get_serial_sequence
, now all the values get passed as parameters to the database (using Knex's?
) and all identifiers now get escaped via Knex using??
.This is an example of how the statement now looks:
I also tested with a capitalized column name, but this worked fine without the explicit double quotes like it was needed for the table name.