How to change the quotation character(s) for dbQuoteString?

It looks that the "MS SQL" is not recognized by the DBI::dbQuoteString() as a valid SQL dialect.
I am not using directly the DBI::dbQuoteString(), but I was trying to use the glue::glue_sql() instead to construct the SQL querries.

The apostrophe is used as the (') as quotation character, but the MS SQL Server accepts the double quotation mark (") (or the square brackets) as quotation characters.

library(tidyverse)
library(odbc)

con <- 
  dbConnect(odbc(),
            # Microsoft ODBC Driver for SQL Server on Windows
            driver = "SQL Server",
            .....)

DBI::dbQuoteString(conn = con, "res")
#> <SQL> 'res'

How can I overwrite the quotation character or what type of connector should I define/use?

dbQuoteString works correctly in case of SQL Server - it shows quotes that mark string values to use in SQL string operations (in filters, etc.). You could use double quotations to mark column name in your SELECT statement, but it is not necessary. Please provide more details if possible, what do you need to mark with double quotes?

Sorry, it was my mistake. I mixed the dbQuoteIdentifier (var) and dbQuoteString (val).

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.