Giter Site home page Giter Site logo

Comments (7)

krlmlr avatar krlmlr commented on August 25, 2024 2

Closing, fixed downstream. Thanks @dpprdan!

from rpostgres.

dpprdan avatar dpprdan commented on August 25, 2024 1

Fixed in {sf}: r-spatial/sf#2223

from rpostgres.

dpprdan avatar dpprdan commented on August 25, 2024

This only concerns the sf::dbWriteTable() method, so I think this is better handled there than here.

However, this is partly caused by RPostgres::dbWriteTable() stop()ing if append && !is.null(field.types)

if (append && !is.null(field.types)) {
stopc("Cannot specify `field.types` with `append = TRUE`")
}

This also happens when the table does not (yet) exist, i.e. when there is nothing to append to.

Do you think it would be possible to move this check a few lines down and only stop if the table is found, @krlmlr?

found <- dbExistsTable(conn, name)

Right now, dbWriteTable will create the table anyway if no field.types are provided.

if (!found || overwrite) {
if (is.null(field.types)) {
combined_field_types <- lapply(value, dbDataType, dbObj = conn)
} else {

The downside is that dbWriteTable(append = TRUE, field.types = "something") will work when the table does not exist but stop when it does. This might be confusing. However, we could ameliorate this by issuing a message "You wanted to append, but the table does not exist yet so we created it".

Of course, third-party methods have to provide custom field.types for their datatypes, like sfc, so field.types cannot be NULL for them. So they cannot create a table currently if append = TRUE but the table does not exist.

from rpostgres.

krlmlr avatar krlmlr commented on August 25, 2024

Thanks, missed that. IIUC, we can fix this by fixing sf::dbWriteTable()?

from rpostgres.

dpprdan avatar dpprdan commented on August 25, 2024

Thanks, missed that. IIUC, we can fix this by fixing sf::dbWriteTable()?

Yes. But the fix is a bit ugly (IMO, i.e. overriding function arguments).

IMHO it would be best, i.e. cleanest, if append were only possible if the table already exists, but that's probably too much of a breaking change.

from rpostgres.

krlmlr avatar krlmlr commented on August 25, 2024

There are new generics dbCreateTable() and dbAppendTable(), does sf support these?

from rpostgres.

dpprdan avatar dpprdan commented on August 25, 2024

Ha, I just had a similar thought, i.e. refactor sf::dbWriteTable() using dbCreateTable() and dbAppendTable().

So no, sf does not support/use them yet.

Anyway, I am not convinced by my "create table if append = TRUE" proposal above myself anymore, so this can be closed IMO.

from rpostgres.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.