0

我想将一个数据帧写回plr中的数据库。

在标准 RI 中可以这样做:

require("RPostgreSQL")
con <-  dbConnect(dbDriver("PostgreSQL"), dbname = , port = ,  user = )
data(iris)
dbWriteTable(con, 'iris', iris, row.names=FALSE)

但是,在 plr 中,我已经连接到数据库。我在这里查看了 plr 文档:http: //www.joeconway.com/plr/doc/plr-US.pdf但找不到示例,还找到了这个sqlshorthands.R文档,但是那里的示例对我不起作用.

4

1 回答 1

1
--PostgreSQL always needs to know the function return type!
create or replace function r_iris(
    OUT "Sepal.Length" float8,
    OUT "Sepal.Width" float8, 
    OUT "Petal.Length" float8, 
    OUT "Petal.Width" float8, 
    OUT "Species" text)
returns setof record
As 
$$
data('iris')
iris
$$ LANGUAGE plr;

--assume there is an existing schema called testing
Select * into testing.iris From r_iris();
于 2017-01-24T00:26:57.857 回答