Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

dbUnquoteIdentifier

Unquote identifiers


Description

Call this method to convert a SQL object created by dbQuoteIdentifier() back to a list of Id objects.

Usage

dbUnquoteIdentifier(conn, x, ...)

Arguments

conn

A DBIConnection object, as returned by dbConnect().

x

An SQL or Id object.

...

Other arguments passed on to methods.

Value

dbUnquoteIdentifier() returns a list of objects of the same length as the input. For an empty character vector this function returns a length-0 object. The names of the input argument are preserved in the output. When passing the first element of a returned object again to dbUnquoteIdentifier() as x argument, it is returned unchanged (but wrapped in a list). Passing objects of class Id should also return them unchanged (but wrapped in a list). (For backends it may be most convenient to return Id objects to achieve this behavior, but this is not required.)

An error is raised if plain character vectors are passed as the x argument.

Specification

For any character vector of length one, quoting (with dbQuoteIdentifier()) then unquoting then quoting the first element is identical to just quoting. This is also true for strings that contain special characters such as a space, a dot, a comma, or quotes used to mark strings or identifiers, if the database supports this.

Unquoting simple strings (consisting of only letters) wrapped with SQL() and then quoting via dbQuoteIdentifier() gives the same result as just quoting the string. Similarly, unquoting expressions of the form SQL("schema.table") and then quoting gives the same result as quoting the identifier constructed by Id(schema = "schema", table = "table").

See Also

Examples

# Unquoting allows to understand the structure of a
# possibly complex quoted identifier
dbUnquoteIdentifier(
  ANSI(),
  SQL(c('"Catalog"."Schema"."Table"', '"Schema"."Table"', '"UnqualifiedTable"'))
)

# The returned object is always a list,
# also for Id objects
dbUnquoteIdentifier(
  ANSI(),
  Id(catalog = "Catalog", schema = "Schema", table = "Table")
)

# Quoting is the inverse operation to unquoting the elements
# of the returned list
dbQuoteIdentifier(
  ANSI(),
  dbUnquoteIdentifier(ANSI(), SQL("UnqualifiedTable"))[[1]]
)

dbQuoteIdentifier(
  ANSI(),
  dbUnquoteIdentifier(ANSI(), Id(schema = "Schema", table = "Table"))[[1]]
)

DBI

R Database Interface

v1.1.1
LGPL (>= 2.1)
Authors
R Special Interest Group on Databases (R-SIG-DB) [aut], Hadley Wickham [aut], Kirill Müller [aut, cre] (<https://orcid.org/0000-0002-1416-3412>), R Consortium [fnd]
Initial release
2021-01-04

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.