Hi, Bruce, Yes, I essentially want to reinterpret text as bytea without any conversion or actual backslash logic coming in the process, in the same way pg_convert_from internally reinterprets the bytea return value from pg_convert as text without any additional logic. I.e. given the text field 'C:\some\dir' (E'C:\\some\\dir') which is 11 codepoints long and contains a grand total of two backslashes, I want those two backslashes to map to two byte values 0x5c in a corresponding 11-byte long bytea. :) I tried to achieve this zero-logic via CREATE DOMAIN ... WITHOUT FUNCTION and casting via the domain, assuming the lot would then behave like the aforementioned trick in the pg_convert_from implementation, but it doesn't seem to work that way. :( V. On Wed, Mar 16, 2011 at 11:51 AM, Bruce Momjian <bruce@xxxxxxxxxx> wrote: > Vlad Romascanu wrote: >> Hello, >> >> Is there any way of casting (reinterpreting) a varchar/text field >> containing arbitrary backslashes to bytea without making an escaped >> copy of the varchar/text first? ÂIn the examples below I am using a >> constant E'...' for clarity, the value normally comes from a >> varchar/text column in a table but the end behaviour is the same. >> >> E.g.: >> >> 1) SELECT E'C:\\something'::bytea >> Â Â ERROR: Âinvalid input syntax for type bytea >> Â Â --> essentially like calling decode(); bad in this case because of >> the naked backslash! >> >> 2) SELECT replace(E'C:\\something', E'\\', E'\\\\')::bytea >> Â Â --> works OK, but bad performance-wise because needed to make an >> escaped copy of the string which is inefficient >> >> 3) CREATE DOMAIN my_varlena AS text; >> Â Â CREATE CAST (my_varlena AS bytea) WITHOUT FUNCTION; >> Â Â SELECT E'C:\\something'::my_varlena::bytea >> Â Â ERROR: Âinvalid input syntax for type bytea >> Â Â --> WHY? > > Well, the '\\' is being converted to '\' because of the single-quotes, > and then bytea is saying it doesn't know how to process \something. ÂIt > sounds like you want bytea but don't want the ability to use backslash > escapes to input the bytea values. ÂI am unsure how to accomplish that. > > -- > ÂBruce Momjian Â<bruce@xxxxxxxxxx> Â Â Â Âhttp://momjian.us > ÂEnterpriseDB Â Â Â Â Â Â Â Â Â Â Â Â Â Â http://enterprisedb.com > > Â+ It's impossible for everything to be true. + > -- Sent via pgsql-general mailing list (pgsql-general@xxxxxxxxxxxxxx) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-general