pg_escape_bytea / pg_unescape_bytea (php) alternative in Rails?

Is there a built-in function that handles the problem of bitstreams in postgresql? The problem occurs when the stream contains for example the " character. Postgres will think that the string has ended with that character. Is there a function that changes all such characters into "\[ASCII-number]"? And the other way around when getting the stream back from the database? References: http://be.php.net/manual/nl/function.pg-escape-bytea.php http://be.php.net/manual/nl/function.pg-unescape-bytea.php