Search Postgresql Archives

converting E'C:\\something' to bytea

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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?

Thanks,
V.

-- 
Sent via pgsql-general mailing list (pgsql-general@xxxxxxxxxxxxxx)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux