-
-
Notifications
You must be signed in to change notification settings - Fork 592
Add sql export format #619
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
Conversation
for more information, see https://pre-commit.ci
…sql-export required for merging
claudep
left a comment
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.
Thanks, I think this is a nice addition to this lib.
…s sql columns from dataset headers or from optional argument now
for more information, see https://pre-commit.ci
| """ | ||
| tbl = table or getattr(dataset, 'title', None) or 'EXPORT_TABLE' | ||
| tbl_ident = cls._quote_ident(str(tbl)) | ||
| tbl_ident = str(tbl) |
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.
What is your rationale for not quoting table/column names? Typically, I think that for example on PostgreSQL uppercase names should be quoted.
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.
Hi when the table name is in quotes then you're not able to reference schema names like schema_name.table_name so "schema_name.table_name" doesn't work. Seems like you can have syntaxes like "Schema Name"."table name" as well. I think the user should just pass the quotes into the title if they require it instead of having it as default
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.
Maybe _quote_ident could smartly detect the "schema_name.table_name" case? In any case, having the default EXPORT_TABLE unquoted looks like it will hurt many.
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.
Yep that's true, I'll change EXPORT_TABLE to be lowercase export_table.
I looked into it some more and it looks like by default MySQL doesn't support quotes for table names so it needs to be the plain table name to work with all formats. Seems like MySQL uses backticks `` instead of quotes so INSERT INTO "TBL" VALUES (1, 'value'); will raise a syntax error with MySQL
…sql-export merge changes
|
@hugovk Could you quickly make a final review? |
hugovk
left a comment
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.
Looks good, a couple of suggestions.
| except Exception: | ||
| pass | ||
| return 'NULL' |
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.
What might trigger this? Can we have a more specific exception here? Can it be covered by tests?
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.
Honestly, I'm not sure. It would have to be something obscure like a class that subclasses the float type and throws an exception in it's repr method
Co-authored-by: Hugo van Kemenade <[email protected]>
|
Thanks a lot for this contribution 😍 |
Hi! I've added .sql to the export formats and added tests
This is useful especially with the records library https://pypi.org/project/records/ which uses this library to create exports.
examples: