Skip to content

Confusing error for names in parameterized queries #266

Closed

Description

@mbedward

This is perhaps related to #199 but hopefully a simpler request.

Presently this code...

dat <- data.frame(foo = 1:3, bar = 4:6)
rs <- dbSendQuery(con, "INSERT INTO sometable (foo, bar) VALUES ($1, $2);")
dbBind(rs, params = dat)
dbClearResults(rs)

...provokes an error: 'Named parameters not supported'.

This confused me because the code has positional rather than named placeholders. After looking at the package sources (PgResult.R line 172) I arrived at this work-around:

dbBind(rs, params = unname(dat))

Would it cause problems if names were just ignored rather than raising an error? If so, perhaps adding an example of this work-around to the docs would help others.

Activity

  1. krlmlr commented on Dec 26, 2020

    @krlmlr
    Member

    Thanks. I agree the error message could be clearer. What wording would be best suited for the problem?

    The strictness here is intentional -- named placeholders require named parameters, same with unnamed.

  2. added this to the 1.2.2 milestone on Dec 26, 2020
  3. modified the milestones: 1.2.2, 1.2.3, 1.4.0 on Jan 2, 2021
  4. github-actions commented on Sep 15, 2022

    @github-actions
    Contributor

    This old thread has been automatically locked. If you think you have found something related to this, please open a new issue and link to this old issue if necessary.

  5. locked and limited conversation to collaborators on Sep 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions