Repository navigation
feat: support postgresql numeric column type - #1311
Conversation
Summary of ChangesHello @greenteasocha, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request introduces crucial support for the PostgreSQL Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request adds support for the PostgreSQL NUMERIC data type by treating it similarly to DECIMAL. The change is correct and fixes the issue described. My review includes two main points. First, a high-severity concern about potential precision loss when converting NUMERIC and DECIMAL types to float64, which could lead to incorrect behavior in tests. I've recommended creating a follow-up task to address this. Second, I've suggested adding an automated unit test to ensure the long-term stability of this new feature. Overall, this is a good contribution that addresses a real-world use case.
| case t == "DECIMAL" || t == "FLOAT" || t == "DOUBLE": // MySQL: NUMERIC = DECIMAL ( FLOAT, DOUBLE maybe not used ) | ||
| // MySQL: NUMERIC is aliased to DECIMAL. PostgreSQL: DECIMAL is aliased to NUMERIC. ( FLOAT, DOUBLE maybe not used ) | ||
| case t == "DECIMAL" || t == "NUMERIC" || t == "FLOAT" || t == "DOUBLE": | ||
| num, err := strconv.ParseFloat(s, 64) //nostyle:repetition |
There was a problem hiding this comment.
Using strconv.ParseFloat for DECIMAL and NUMERIC types can cause precision loss, as float64 cannot accurately represent all exact decimal values. This can lead to incorrect test evaluations, especially with financial data.
A safer approach would be to either keep these values as strings or use a high-precision decimal library. Since this change is consistent with how DECIMAL is already handled, it's acceptable for now, but I strongly suggest creating a follow-up issue to address this for both DECIMAL and NUMERIC types to prevent potential data-related bugs.
There was a problem hiding this comment.
This precision issue already exists for DECIMAL types in the current implementation. This PR maintains that existing behavior and simply extends it to NUMERIC.
| row[c] = s | ||
| case t == "DECIMAL" || t == "FLOAT" || t == "DOUBLE": // MySQL: NUMERIC = DECIMAL ( FLOAT, DOUBLE maybe not used ) | ||
| // MySQL: NUMERIC is aliased to DECIMAL. PostgreSQL: DECIMAL is aliased to NUMERIC. ( FLOAT, DOUBLE maybe not used ) | ||
| case t == "DECIMAL" || t == "NUMERIC" || t == "FLOAT" || t == "DOUBLE": |
There was a problem hiding this comment.
There was a problem hiding this comment.
Looking at db_test.go, it seems that the tests primarily target SQLite3 rather than PostgreSQL, which is what this change addresses.
Additionally, the existing tests already include queries against NUMERIC type columns (e.g., created_at), so NUMERIC handling is already covered to some extent.
I'll keep the current implementation as is.
But also, I want to hear maintainers' opinion.
There was a problem hiding this comment.
I think it's fine as is in the current test environment.
k1LoW
left a comment
There was a problem hiding this comment.
@greenteasocha Thank you for your contribution!
Hello, thank you for maintaining such a great tool.
Recently, I encountered a situation that I want to handle postgresql
NUMERICtype column.This PR will fix this error.
Suggested Feature
Support postgresql
NUMERICcolumn type. It also supportDECIMAL, which is aliased toNUMERIC.Minimal reproducible example
init.sqlcompose.ymltest_postgres.ymlBackward compatibility check for other supported DBs
compose.yml(init_mysql.sqlis shown in following section)MySQL
init_mysql.sqltest_mysql.ymlSQLite3
init_sqlite.sqltest_sqlite.ymlCloud Spanner
test_spanner.yml(run with envirionment variable set.
SPANNER_EMULATOR_HOST=localhost:9010 runn run test_spanner.yml)