Postgres bytea column is returning string (char array) instead of byte array

后端 未结 2 631
南笙
南笙 2021-01-03 07:07

I have been using C# to write a concrete provider implementation for our product for different databases. W/out getting into details, one of the columns is of byte array typ

2条回答
  •  执念已碎
    2021-01-03 07:46

    Ran the same problem, but managed to solve the problem without having to resort to changing drivers.

    PHP documentation has a good description of what's happening, Postgres is returning escaped data. Check your output against an ASCII table, when you see 92 48 ... it's the text lead in to an octal escape sequence, \0xx, just like PHP describes.

    Postgres's binary data type explains the output escaped octets. Fret not, there are code examples.

    The solution is to tell Postgres how to bytea output is escaped, which can be either escape or hex. In this case issue the following to Postgres via psql to match your data:

    ALTER DATABASE yourdb SET BYTEA_OUTPUT TO 'escape';
    

提交回复
热议问题