在R中包括PostgreSQL中的单引号

时间:2019-04-19 18:05:13

标签: r postgresql

我有以下查询在PostgreSQL中运行良好。当我尝试在R中(通过PostgreSQL)运行相同的查询时,它不起作用,因为不包括单引号。

我已经尝试使用"'"day"'"'day\',但都无法使用。

Query <- dbGetQuery(con,'select
DATE_PART('day', to_timestamp("rollbackTime") - to_timestamp("commitTime")) as "Cancellation from payment')

1 个答案:

答案 0 :(得分:0)

您可以将'\'隔开,所以也许您正在寻找:

sql <- 'select DATE_PART(\'day\', to_timestamp("rollbackTime") - to_timestamp("commitTime")) as "Cancellation from payment"'
Query <- dbGetQuery(con, sql)

调试此类字符串时,cat可能有用:

cat(sql)

将返回

select DATE_PART('day', to_timestamp("rollbackTime") - to_timestamp("commitTime")) as "Cancellation from payment"