Skip to contents

DuckDB parses SQL string literals itself, so raw Windows paths, paths containing single quotes, and relative paths interpolated into sprintf() are a recurring source of parser errors. Everything that puts a filesystem path into SQL should go through these helpers (mirror of omop_etl.paths in Python).

Usage

sanitize_sql_path(p)

sql_path_literal(p)

Arguments

p

A path (character).

Value

sanitize_sql_path(): a character string. sql_path_literal(): a quoted SQL literal.

Details

sanitize_sql_path() returns an absolute path with forward slashes. Remote URIs (s3://, https://, ...) are only slash-normalized, and glob patterns survive because the path need not exist. sql_path_literal() returns the same path as a quoted SQL string literal with single quotes escaped.

Examples

sanitize_sql_path("C:\\data\\site a\\vital.csv")
#> [1] "C:/data/site a/vital.csv"
sql_path_literal("o'brien.csv")
#> [1] "'/home/runner/work/omop-duck-db/omop-duck-db/docs/reference/o''brien.csv'"