On Wed, Jul 25, 2007 at 06:02:10PM +0530, Nalin Bakshi wrote: > I have come on a problem regarding encryption. I am firing a simple > select statement: > > select encrypt('\\','abcd','bf'); > > I want to use \ for encryption but I get the error: > "invalid input syntax for type bytea" > > I tried using \\\\ to encrypt \ , but on decryption I get \\ instead of > \ (single backslash). The double backslash is the output representation of a single backslash. See Table 8-7 "bytea Literal Escaped Octets" and Table 8-8 "bytea Output Escaped Octets" in the documentation: http://www.postgresql.org/docs/8.2/interactive/datatype-binary.html You can use length(), octet_length(), or encode() to see that the decrypted value contains only a single octet: test=> select decrypt(encrypt(e'\\\\', 'abcd', 'bf'), 'abcd', 'bf'); decrypt --------- \\ (1 row) test=> select octet_length(decrypt(encrypt(e'\\\\', 'abcd', 'bf'), 'abcd', 'bf')); octet_length -------------- 1 (1 row) test=> select encode(decrypt(encrypt(e'\\\\', 'abcd', 'bf'), 'abcd', 'bf'), 'hex'); encode -------- 5c (1 row) Depending on your security requirements you might wish to use pgp_sym_encrypt() or pgp_sym_encrypt_bytea() instead of encrypt(). See the "Raw encryption" section of README.pgcrypto for some of the disadvantages of encrypt(). -- Michael Fuhr