7

I have string 'test\data' or just one backslash symbol '\'.

How it convert to bytea?

marvinorez
  • 593
  • 4
  • 7

1 Answers1

2

Backlashes need special handling if casted from to bytea see src/backend/utils/adt/varlena.c.

Thus escape each backslash using replace('test\data', '\', '\\')::bytea before casting to bytea.

You could also use the already suggested function convert_to(text, encoding) bytea. But note that this function is not IMMUTABLE and thus it can't be used in any context out of the box.

FireEmerald
  • 1,002
  • 12
  • 21