Command Prompt, Inc. (authors of Practical PostgreSQL from O’ReillY) are releasing their plPHP ( http://www.commandprompt.com/entry.lxp?lxpe=260 )to the open source community under the PHP License. Now you can create custom postgreSQL function using your favority scripting language (php) and utilize them in the database.
Example:
We will replace each line break in a text field with a html break tag (followed by a line break).
CREATE OR REPLACE FUNCTION line_breaks(text) RETURNS text AS ' $txt = str_replace("n","<br>n", $arg0); if ($txt) { return $txt; } ' LANGUAGE 'plphp';
Then you can call your SELECT like so:dbname=# SELECT id, line_breaks(body) FROM table1 ; id | line_breaks ----+----------------------- 1 | Lots of text
wjpoefjeowpqjf
body text r09u3
234jr23032ur03u29r0u
p2jend of text (1 row)