You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
And attempt to create them with dbCreateTable, it works as expected for table_a. However, it fails for table_b giving the following Error: Failed to fetch row: ERROR: type "logical" does not exist at character 75.
I was not able to find a mention of this in the docs or this repo's issues. My apologies in advance if this was an already considered/documented case or simply a misuse on my end.
After two full days trying and failing to achieve this, I was able to find a workaround using dataframes instantiated with empty vectors to enforce datatypes, like so
Also, an example is missing, but this is difficult to demo with SQLite because it doesn't really have a notion of strict types. The example could also use a zero-row data frame as the structure, like you did.
Oooh, I see. That actually makes a lot of sense and it might have to do with some weird type behavior I was seeing that seemed to originate in postgres itself. Specifically with floats, which I was using double for, thinking it had to be an R type.
I'll definetly look into this closer and will revisit these definitions. I'd be happy to contribute to the docs or provide postgres examples if needed.
Sorry for the late reply, we ended up moving away these functionalities in favor of python+sqlalchemy.
I can positively confirm the following creates the table with the intended types in PostgreSQL 14.8 (Debian 14.8-1.pgdg110+1)
test <- c(col_1='character', col_2='boolean', col_3='double precision')
dbCreateTable(conn, 'test_table', test, row.names=NULL)
To get the correct names for the types I consulted this page. I think the documentation could say something like:
A named character vector: Names are column names, values are types (as defined by your PostgreSQL instance).
Maybe it could also include a reference or a link to the postgres docs I mentioned above?
I haven't found any contributing guidelines other than this so I don't know the procedure to update docs, but if this sounds reasonable I would gladly help opening a pull request, submitting more examples or in another way.
Activity
castagninojose commentedon Jan 13, 2023
After two full days trying and failing to achieve this, I was able to find a workaround using dataframes instantiated with empty vectors to enforce datatypes, like so
table_b = data.frame(col_1=character(), col_2=numeric(), col_3=logical())which is not quite what I wanted but it's close enough.
Anyway, I'm leaving this open in case this is in fact a bug and someone wants to take a stab at it. Feel free to close otherwise.
Cheers
krlmlr commentedon Apr 1, 2023
Thanks. I see how this is confusing.
In https://dbi.r-dbi.org/reference/dbcreatetable#arguments-1, the
fieldsargument is documented asIt doesn't suggest anywhere that the "types" must be SQL types. So, something along the lines of
should work too.
Also, an example is missing, but this is difficult to demo with SQLite because it doesn't really have a notion of strict types. The example could also use a zero-row data frame as the structure, like you did.
castagninojose commentedon Apr 1, 2023
Oooh, I see. That actually makes a lot of sense and it might have to do with some weird type behavior I was seeing that seemed to originate in postgres itself. Specifically with floats, which I was using
doublefor, thinking it had to be an R type.I'll definetly look into this closer and will revisit these definitions. I'd be happy to contribute to the docs or provide postgres examples if needed.
Thank you for your time,
José
castagninojose commentedon Jun 7, 2023
Hey,
Sorry for the late reply, we ended up moving away these functionalities in favor of python+sqlalchemy.
I can positively confirm the following creates the table with the intended types in
PostgreSQL 14.8 (Debian 14.8-1.pgdg110+1)To get the correct names for the types I consulted this page. I think the documentation could say something like:
Maybe it could also include a reference or a link to the postgres docs I mentioned above?
I haven't found any contributing guidelines other than this so I don't know the procedure to update docs, but if this sounds reasonable I would gladly help opening a pull request, submitting more examples or in another way.
Cheers,
José.