Function to convert from TEXT to BYTEA?

From: "D(dot) Dante Lorenso" <dante(at)lorenso(dot)com>
To: PGSQL <pgsql-general(at)postgresql(dot)org>
Subject: Function to convert from TEXT to BYTEA?
Date: 2007-12-12 02:23:20
Message-ID: 475F4618.4000409@lorenso.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

All,

I want to use the ENCRYPT and DECRYPT functions from contrib, but they
require inputs of BYTEA.

My data is in VARCHAR and TEXT fields and when I try to use the contrib
functions, they complain about wrong datatypes. Is there a string
function or something that will take a VARCHAR or TEXT input and output
a BYTEA so that I can use that as input for the ENCRYPT/DECRYPT functions?

I know about creating a CAST from VARCHAR to BYTEA, but the problem with
a CAST is that it doesn't port to other database servers when I do a
dump and restore. That forces me to manually have to recreate the cast
each time a new database is set up and usually that's the step that gets
forgotten.

Is there a function that will do what I want to convert the datatype
without having to create a CAST that PostgreSQL doesn't have natively?
How else are you supposed to use the ENCRYPT and DECRYPT functions?

-- Dante

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Richard Broersma Jr 2007-12-12 02:46:05 Re: Creating Aggregate functions in PLpgSQL
Previous Message Joshua D. Drake 2007-12-12 02:18:32 Slow PITR restore