How to trim Bytea fields

Started by Howard Coleover 20 years ago3 messagesgeneral
Jump to latest
#1Howard Cole
howardnews@selestial.com

Hi,

I have an bytea field that contains data with a lot of trailing blank
space composed of multiple '\000' zero bytes. Does anyone know of a
quick SQL fix to trim these bytes from the data?

Thanks

Howard Cole
http://www.selestial.com

#2Joe Conway
mail@joeconway.com
In reply to: Howard Cole (#1)
Re: How to trim Bytea fields

Howard Cole wrote:

Hi,

I have an bytea field that contains data with a lot of trailing blank
space composed of multiple '\000' zero bytes. Does anyone know of a
quick SQL fix to trim these bytes from the data?

trim() will remove '\000' bytes from both ends -- would that work for you?

select trim('\\000'::bytea from '\\00012\\00034\\000\\000'::bytea);
btrim
----------
12\00034
(1 row)

Joe

#3Howard Cole
howardnews@selestial.com
In reply to: Joe Conway (#2)
Re: How to trim Bytea fields

Joe Conway wrote

trim() will remove '\000' bytes from both ends -- would that work for
you?

Thanks Joe, just what I was looking for.

Howard