Search Postgresql Archives

Re: crosstab

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi Joe,

Do you maybe know, is it possible inside PL/R to call another PL/R function - but take result as R object (whatever R function returns)?

If we take this scenario for example (Take some data from DB, pivot them, and save it as CSV)... pseudo code would be:

-Execute SQL query
-pivot returned data
-save it to CSV...

of course everything could be in one function, but I would organize my code in much more... because of for example, if I need tomorrow get the same thing and save it to PDF, or Save it to graph etc... I could copy/paste the same function and change code in step 3... but if something tomorrow should be changed in step 1 or 2 - I would need to make the same change on 3 places... In pure R for example, I would have at least: getPivotedData function and then SaveToCSV would call getPivotedData() and save it in CSV, SaveToPdf would call the same getPivotedData() and save it to PDF... etc, then tomorrow if something should be changed in first two steps - I would change just getPivotedData function... and cover whole 3 scenarios...

Now, of course PostgreSQL function can't return  R object, but plv8 has solved that problem as plv8 Postgres Function returns record - what is an v8 object...

Then inside one plv8 function, we say plv8.find_function("myv8FunctionWhatReturnsv8Object"), call it and takes actuall result and do with that whatever need to be done inside v8 environment...

During I have written this mail - you have replied that actually my question could be acomplished with serialise/deserialise... but I am not sure I would take that approach - because of "methods" of an object would be lost during serialize/deserialize... (what btw forced me to check it in plv8 - and it seems they use the same approach internally in behind :(  - though doesn't make sense because of find_function works just with plv8 postgres functions)


Thanks,

Misa




2012/9/4 Joe Conway <mail@xxxxxxxxxxxxx>
On 09/04/2012 01:23 PM, Aram Fingal wrote:
> So then, PL/R is not a solution to being able to pivot tables
> directly in PostgreSQL but I might be able to define a PL/R procedure
> which, for example, pivots tables and then uses the write.table()
> function of R to send the results to disk without returning any rows
> to PostgreSQL?  Such a procedure might prove be faster and more
> convenient than extracting the data from PostgreSQL into an R
> application layer and then writing to disk.

As mentioned somewhere else along this thread, I don't know that it will
be faster, but it may well be more convenient if your goal is to get a
CSV file in the end anyway.

Joe


--
Joe Conway
credativ LLC: http://www.credativ.us
Linux, PostgreSQL, and general Open Source
Training, Service, Consulting, & 24x7 Support




--
Sent via pgsql-general mailing list (pgsql-general@xxxxxxxxxxxxxx)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux