在我的一个select语句中,我遇到以下错误:
ERROR: failed to find conversion function from unknown to text
********** Error **********
ERROR: failed to find conversion function from unknown to text
SQL state: XX000
Run Code Online (Sandbox Code Playgroud)
这很容易修复使用cast,但我不完全理解为什么会发生.我将用两个简单的陈述说明我的困惑.
这个没关系:
select 'text'
union all
select 'text';
Run Code Online (Sandbox Code Playgroud)
这将返回错误:
with t as (select 'text')
select * from t
union all
select 'text'
Run Code Online (Sandbox Code Playgroud)
我知道我可以轻松解决它:
with t as (select 'text'::text)
select * from t
union all
select 'text'
Run Code Online (Sandbox Code Playgroud)
为什么第二个例子中的转换失败?是否有一些我不理解的逻辑或者这将在PostgreSQL的未来版本中修复?
PostgreSQL 9.1.9
PostgreSQL 9.2.4(SQL小提琴)上的相同行为
我需要使用哪个插件或库吗?我想首先在我的本地系统上尝试这个,然后在Heroku Postgresql上做同样的事情
什么是正确使用expect_error()的testthat包?我试图从帮助中调整示例,但是当我在错误消息中使用括号时,这会失败.
library(testthat)
# Works
tmp1 <- function() stop("Input is not correct")
expect_error(tmp1(),"Input is not correct")
# Does not work
tmp2 <- function() stop("Input (x) is not correct")
expect_error(tmp2(),"Input (x) is not correct")
# Does not work
tmp3 <- function() stop("Input(")
expect_error(tmp3(),"Input(")
Run Code Online (Sandbox Code Playgroud)
这导致:
> library(testthat)
>
> # Works
> tmp1 <- function() stop("Input is not correct")
> expect_error(tmp1(),"Input is not correct")
> # Does not work
> tmp2 <- function() stop("Input (x) is not correct")
> …Run Code Online (Sandbox Code Playgroud) 在数据帧名称为字符串的情况下,检查数据帧是否存在的首选方法是什么?我能想到:
df_name <- 'iris'
# Option 1
tryCatch(is.data.frame(get(df_name)), error=function(cond) FALSE)
# Option 2
if (exists(df_name)) is.data.frame(get(df_name)) else FALSE
Run Code Online (Sandbox Code Playgroud) 如何在列中按组聚合数据group并在列中折叠文本text?
样本数据:
df <- read.table(header=T, text="
group text
a a1
a a2
a a3
b b1
b b2
c c1
c c2
c c3
")
Run Code Online (Sandbox Code Playgroud)
所需输出(数据框):
group text
a a1a2a3
b b1b2
c c1c2c3
Run Code Online (Sandbox Code Playgroud)
我现在有:
sapply(unique(df$group), function(x) {
paste0(df[df$group==x,"text"], collapse='')
})
Run Code Online (Sandbox Code Playgroud)
这在某种程度上起作用,因为它返回按组正确折叠的文本,但作为向量:
[1] "a1a2a3" "b1b2" "c1c2c3"
Run Code Online (Sandbox Code Playgroud)
我需要一个带有group列的数据框.
如何正确指定rd文件的编码?我正在尝试将以下帮助文件添加到我的包中:
\name{dummy}
\encoding{ISO-8859-2}
\alias{dummy}
\title{P?íšern? žlu?ou?ký k?? úp?l ?ábelské ódy.}
\usage{
dummy(x)
}
\arguments{
\item{x}{P?íšern? žlu?ou?ký k?? úp?l ?ábelské
ódy.P?íšern? žlu?ou?ký k?? úp?l ?ábelské ódy.}
}
\description{
P?íšern? žlu?ou?ký k?? úp?l ?ábelské ódy.P?íšern?
žlu?ou?ký k?? úp?l ?ábelské ódy.
}
\examples{
dummy(x="P?íšern? žlu?ou?ký k?? úp?l ?ábelské ódy.P?íšern? žlu?ou?ký k?? úp?l ?ábelské ódy.")
}
Run Code Online (Sandbox Code Playgroud)
但是,当我尝试安装我的包(使用installfrom devtools)时,我得到:
Warning messages:
1: In fetch(key) : internal error -3 in R_decompress1
2: In strsplit(msg, "\n") : input string 1 is invalid in this …Run Code Online (Sandbox Code Playgroud) 我必须是信息模式中访问约束相关数据的关系的所有者吗?我测试了以下内容,似乎我必须是主人.
create schema rights_test;
create table rights_test.t1 (id int primary key);
create table rights_test.t2 (id int references rights_test.t1(id));
select
tc.constraint_name,
tc.constraint_schema || '.' || tc.table_name || '.' || kcu.column_name as physical_full_name,
tc.constraint_schema,
tc.table_name,
kcu.column_name,
ccu.table_name as foreign_table_name,
ccu.column_name as foreign_column_name,
tc.constraint_type
from
information_schema.table_constraints as tc
join information_schema.key_column_usage as kcu on (tc.constraint_name = kcu.constraint_name and tc.table_name = kcu.table_name)
join information_schema.constraint_column_usage as ccu on ccu.constraint_name = tc.constraint_name
where
constraint_type in ('PRIMARY KEY','FOREIGN KEY')
and tc.constraint_schema = 'rights_test'
/*
This will produce desired …Run Code Online (Sandbox Code Playgroud) 如何使用RStudio中的devtools在github上创建新的存储库?我试过:
然后我想我会create("MyNewRPackage")用来初始化目录结构和README.md文件.但是包骨架被创建为我项目的子文件夹而且我有~/MyNewRPackage/MyNewRPackage/R.但我需要在我的github存储库的根文件夹中创建包骨架.
使用devtools和RStudio在github上开始新R包开发的标准方法是什么?
在回答这个问题时,我了解到你可以在PostgreSQL中创建空表.
create table t();
Run Code Online (Sandbox Code Playgroud)
这有什么实际用例吗?你为什么要创建空表?因为你不知道它会有哪些列?