how can we write data to a file from database function in postgresql?
i searched many ways but i didn't get the information about开发者_StackOverflow社区 how to write the data to a file when call the database function (postgresql) in the java program.. please clarify me on this....
thanks in advance..
I assume you want the file to be written on the database server, not the application server (where the Java Program is running).
You need to implement a stored function in an untrusted language (like python or C). You would then call that function either from Java or from within the already existing function.
Here is an example that I found when googling for this:
CREATE FUNCTION makefile(text) RETURNS text AS $$ o=open("/path/to/file") o.write(args[0]) o.close() return "ok" $$ LANGUAgE plpythonu;
Here is another one:
http://www.leidecker.info/pgshell/Having_Fun_With_PostgreSQL.txt
A (very) short description is also given here: http://archives.postgresql.org/pgsql-novice/2007-01/msg00010.php
精彩评论