English 中文(简体)
从PL/RR的R功能中恢复多个不同数据结构
原标题:returning multiple dissimilar data structures from R function in PL/R

我一直在研究关于SO和其他地方的各种讨论,普遍共识是,如果从R功能中恢复多个非类似数据结构,最好作为<代码>list(a, b),然后由索引<代码>0和1等检索。 除通过PL/R在Perl方案中使用R功能外,Rlist功能统一了该清单,并且甚至对数字作了说明。 例如

my $res = $sth->fetchrow_arrayref;
# now, $res is a single, flattened, stringified list
# even though the R function was supposed to return 
# list([1, "foo", 3], [2, "bar"])
#
# instead, $res looks like c("1", ""foo"", "3", "2", ""bar"")
# or some such nonsense

Using a data.frame doesn t work because the two arrays being returned are not symmetrical, and the function croaks.

因此,我如何从由一套任意设置的数据结构组成的R功能中恢复一个单一数据结构,并且仍然能够从Perl获得每个单项零件,仅作为<代码>$res->[0],$res-> or $res->{雇员<>>/code>,res->{ pets }update<>:> 我正在研究一个Perl s [1,“foo”, 3],[2,“bar”],, 甚至[[[1, “foo”, 3],{a => 2, b =>“bar”}

<><><>>>>: 我的问题主要在于如何从PL/R的功能中恢复多种不同的数据结构。 然而,如上所述,二次,由于我把数据转换为初等计算机,而所有外引的只是增加服务器与用户之间无用数据,因此,二次强化也存在问题。

问题回答

我认为,你在这里有几个问题。 第一个是,你只能够回过一个阵列,因为它赢得了“邮政信箱”阵列检查(信息必须是不对称的,所有同类)。 请注意,如果你把PL/R从PL/Perl传到一个盘问界面,那么PogreSQL类制约因素将是一个问题。

你有几种选择。

You could return setof text[], with one data type per row.

您可以通过结构归还某种结构化的数据。 PostgreSQL理解如下:

CREATE TYPE ab AS (
   a text,
   b text
);

CREATE TYPE r_retval AS (
   labels text[],
   my_ab ab
);

这将使你能够回来:

{labels => [1, "foo", 3], ab => {a =>  foo , b =>  bar } }

但无论如何,你必须把它纳入邮政总局规划人员能够理解的数据结构,而这正是我认为你所不见的。





相关问题
摘录数据

我如何将Excel板的数据输入我的Django应用? I m将PosgreSQL数据库作为数据库。

Postgres dump of only parts of tables for a dev snapshot

On production our database is a few hundred gigabytes in size. For development and testing, we need to create snapshots of this database that are functionally equivalent, but which are only 10 or 20 ...

How to join attributes in sql select statement?

I want to join few attributes in select statement as one for example select id, (name + + surname + + age) as info from users this doesn t work, how to do it? I m using postgreSQL.

What text encoding to use?

I need to setup my PostgreSQL DB s text encoding to handle non-American English characters that you d find showing up in languages such as German, Spanish, and French. What character encoding should ...

SQL LIKE condition to check for integer?

I am using a set of SQL LIKE conditions to go through the alphabet and list all items beginning with the appropriate letter, e.g. to get all books where the title starts with the letter "A": SELECT * ...

热门标签