-
Notifications
You must be signed in to change notification settings - Fork 81
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
insertTable for Sqlite adds decimal precision to data inserted into character field #280
Comments
By default Beyond this, the insert is completed with |
Tracing through live code in the example you sent and adding a I confirm the issue is with the DBI::dbWriteTable
Which is adding the decimal precision internally - likely inside RSQLite https://github.com/r-dbi/DBI/blob/main/R/dbWriteTable_DBIConnection_Id_ANY.R However, reproducing this example is trickier than I'd like. Creating a reproducible example is challenging but the only way to resolve this in this package would be to force the type conversions after reading the csv. However, this feels like a hack. |
The following is a reproducible example that uses only library(DatabaseConnector)
unlink("test.sqlite")
sqliteConnectionDetails <- createConnectionDetails(
dbms = "sqlite",
server = "test.sqlite"
)
sqliteConnection <- connect(sqliteConnectionDetails)
sql <- "
CREATE TABLE @schema.test_table (
database_id VARCHAR primary key
);
"
renderTranslateExecuteSql(sqliteConnection, sql, schema = "main")
data <- data.frame(
database_id = 12345689878
)
insertTable(connection = sqliteConnection,
data = data,
createTable = FALSE,
dropTableIfExists = FALSE,
tableName = "test_table",
databaseSchema = "main")
print(renderTranslateQuerySql(sqliteConnection, "SELECT database_id FROM test_table"))
# Prints
# DATABASE_ID
# 12345689878.0
disconnect(sqliteConnection) |
Would it be possible to convert the numeric value to a character string in R, before sending it to |
This will have a workaround in the next Perhaps the data types of the table could be read prior to insert and then this could be cast in R accordingly? |
This appears to be creating problems downstream when sqlite is used see OHDSI/Eunomia#65 |
I really think consistently casting numerics to string is out of scope for DatabaseConnector. This should be handled prior to handing it over to DatabaseConnector. If not, then we'd need to parse every SQL statement to see if it contains an INSERT, then try to derive where it is inserting to, get the schema of that, and perform the correct casting. |
I would argue that the conversion of data to use decimal precision is occurring after the user passes the data to insertTable. In every other driver case, the insert does not add the decimal value. Perhaps a more consistent approach would be to use the jdbc driver? |
Sorry, this is incredibly easy to fix (and not unreasonable to ask) before talking to DatabaseConnector, and really hard to fix with DatabaseConnector. I'm going to declare this a 'won't fix'. |
I'm not sure if this is an RMM issue or not but starting by putting it here. This issue is based on the work happening in OHDSI/Strategus#147 (comment).
Here is some code that can be used to reproduce the example between creating the table & uploading data in SQLite vs PostgreSQL. The files references in the code below is attached to the issue at the bottom. The issue is that when
database_id
is inserted into SQLite, it is formatted as85642205.0
while when it is inserted into PostgreSQL, it is85642205
database_meta_data.zip
The text was updated successfully, but these errors were encountered: