Skip to content

dbQuoteLiteral() can't handle zero-length **typed** values #355

@mmuurr

Description

@mmuurr

When passed a typed, length-zero vector, {RPostgres}' dbQuoteIdentifier() method yields a length-one string that triggers a Postgres SQL syntax error. The ANSI() driver behaves differently (and, I think, correctly).

## db_conn is my RPostgres connection str(DBI::dbQuoteLiteral(DBI::ANSI(), integer(0))) # Formal class 'SQL' [package "DBI"] with 1 slot # ..@ .Data: chr(0) str(DBI::dbQuoteLiteral(db_conn, integer(0))) # Formal class 'SQL' [package "DBI"] with 1 slot # ..@ .Data: chr "::int4"

Injecting the RPostgres value into a query, e.g. via glue::glue_sql() yields something like so:

my_val <- DBI::dbQuoteLiteral(db_conn, integer(0)) sql <- glue::glue_sql("select * from my_tbl where {my_val}", .con = db_conn) DBI::dbGetQuery(db_conn, sql) # Error: Failed to prepare query: ERROR: syntax error at or near "::" # LINE 1: select * from my_tbl where ::int4

FWIW, NULL as an input across both ANSI() and RPostgres connections/drivers works fine, this error is specifically in the length-zero typed case.

{RPostgres} v1.2.1
{DBI} v1.1.0

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