0

I have a udf in postgres that expects array as input argument. Example:

create or replace function vwap(prices numeric[], volume integer[])

I have the prices and volume stored in a R data.table.

dt <- data.table(prices = numeric(), volume = integer())

How do I use RPostgresql or any other postgres package to call the defined udf?

aajkaltak
  • 1,437
  • 4
  • 20
  • 28
  • The example I have provided is a very basic example. I need to run simulations in postgres (pivotal greenplum MPP architecture) for which input arrays need to be passed in as arguments to postgres udf. These arrays are stored in R data.table. Hope that helps. – aajkaltak Dec 01 '18 at 23:43
  • `DBI::dbWriteTable(con, "mytable", mydata[c("prices","volume")], create=TRUE)` to create a table (optionally temporary), then something like `DBI::dbGetQuery(con, "select vwap(prices, volume) from mytable")`. You might want to clean-up with `DBI::dbExecute(con, "drop table mytable")` or `DBI::dbExecute(con, "delete from mytable")` (both are assuming, of course, that you own the table and are happy discarding anything in it ... please don't do this cavalierly). – r2evans Dec 02 '18 at 00:12

0 Answers0