Changeset: ec8781fe0464 for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=ec8781fe0464
Added Files:
        sql/backends/monet5/Tests/rapi12.sql
Branch: default
Log Message:

schema-changing r udf


diffs (45 lines):

diff --git a/sql/backends/monet5/Tests/rapi12.sql 
b/sql/backends/monet5/Tests/rapi12.sql
new file mode 100644
--- /dev/null
+++ b/sql/backends/monet5/Tests/rapi12.sql
@@ -0,0 +1,39 @@
+START TRANSACTION;
+
+CREATE TABLE observations (subject int, age int, height int, weight int);
+insert into observations values (1, 30, 180, 75), (2, 60, 190, 85), (3, 7, 
100, 40), (4, 48, 196, 597);
+
+SELECT * FROM observations;
+
+CREATE FUNCTION widetolong(subject int, age int, height int, weight int) 
RETURNS TABLE (subject int, key string, value int) LANGUAGE R {
+       dd <- data.frame(subject, age, height, weight)
+       do.call(rbind, 
+               lapply(split(dd, dd$subject), 
+                       function(split) data.frame(
+                               subject=rep(split$subject, 3), 
+                               key=c("age", "height", "weight"), 
+                               value=c(split$age, split$height, 
split$weight))))
+};
+
+SELECT widetolong(subject, age, height, weight) from observations;
+SELECT * FROM widetolong(SELECT * FROM observations);
+SELECT * FROM widetolong(observations);
+
+-- result should look like this (without the row number)
+--    subject    key value
+-- 1        1    age    30
+-- 2        1 height   180
+-- 3        1 weight    75
+-- 4        2    age    60
+-- 5        2 height   190
+-- 6        2 weight    85
+-- 7        3    age     7
+-- 8        3 height   100
+-- 9        3 weight    40
+-- 10       4    age    48
+-- 11       4 height   196
+-- 12       4 weight   597
+
+DROP FUNCTION widetolong;
+DROP TABLE observations;
+ROLLBACK;
\ No newline at end of file
_______________________________________________
checkin-list mailing list
checkin-list@monetdb.org
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to