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

Add support for escaping double quotes in Postgres Identifiers #428

Open
1 of 4 tasks
nickzelei opened this issue Sep 3, 2024 · 0 comments
Open
1 of 4 tasks

Add support for escaping double quotes in Postgres Identifiers #428

nickzelei opened this issue Sep 3, 2024 · 0 comments
Assignees

Comments

@nickzelei
Copy link

Is your feature request related to a problem? Please describe.
Hello 👋

So we use Goqu all throughout Neosync and I've just run into a little issue with special characters in schemas and tables (I guess columns as well).
Goqu handles special characters pretty well by simply escaping the schema/table in double quotes.
However, where this gets weird is if the schema/table itself contains a double quote.

Something like: user"s_data must be escaped like this: "users""s_data".

CREATE TABLE "user""s_data" (id TEXT NOT NULL PRIMARY KEY);

SELECT * from "users""s_data";

You can also do wild things like "myescaped_table", which to be valid SQL, becomes this grotesque statement:

SELECT * FROM """myescapedschema"""."""myescapedtable""";

Describe the solution you'd like
I would love if Goqu could handle this for me when using goqu.T.
I'm sure there are a lot of edge cases here, and possibly other characters? But double quotes is the only one I've been actively testing with that breaks when passing it into Goqu. Also unclear if it should even be in Goqu's wheelhouse to do something like this.

This is pretty advanced, but a part of what Neosync is doing is retrieving schema information from the pg_catalog and then using that to do other queries. So in most cases, it comes out of the database like users"s_data, because, well, that is what it is actually named! But it makes for a real bear when trying to actually query the thing.

Describe alternatives you've considered
The main alternative I've considered is imply writing a function that does this for me before passing it into goqu.T

Dialect

  • postgres
  • mysql
  • sqlite3
  • mssql

I imagine this is an issue with any of the supported dialects that have special characters that allow double quotes.

Additional context
Love this library Doug. Has made handling SQL in Neosync much, much smoother that it would have been otherwise.

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

No branches or pull requests

2 participants