Re: Can we get sha* function over text, that could be used in index?
От
Daniel Verite
Тема
Re: Can we get sha* function over text, that could be used in index?
Дата
Msg-id
63a9ec31-8a5f-47c7-8a70-f1c57207ffd3@manitou-mail.org
Ответ на
Re: Can we get sha* function over text, that could be used in index? (Linus Heckemann)
Список
Дерево обсуждения
Can we get sha* function over text, that could be used in index? hubert depesz lubaczewski <depesz@depesz.com>
Re: Can we get sha* function over text, that could be used in index? Peter Eisentraut <peter@eisentraut.org>
Re: Can we get sha* function over text, that could be used in index? "Peter J. Holzer" <hjp-pgsql@hjp.at>
Re: Can we get sha* function over text, that could be used in index? "Peter J. Holzer" <hjp-pgsql@hjp.at>
Re: Can we get sha* function over text, that could be used in index? Ron Johnson <ronljohnsonjr@gmail.com>
Re: Can we get sha* function over text, that could be used in index? Linus Heckemann <linus@schreibt.jetzt>
Re: Can we get sha* function over text, that could be used in index? "Daniel Verite" <daniel@manitou-mail.org>
Re: Can we get sha* function over text, that could be used in index? Linus Heckemann <linus@schreibt.jetzt>
Linus Heckemann wrote: > - there is a byte-array representation of text columns, which appears to > be independent of database encoding Not sure what you're refering to. Both the on-disk and in-memory representations of text/varchar are encoding-dependent. > The obvious (to a naive user, like I was) approach, casting to bytea, > has exceptionally surprising behaviour: for many text strings, it does > exactly what the naive user might hope for, giving back the UTF-8 > representation. But multiple distinct text strings, like '\033' and > '\x1b', convert to the same byte string! And text strings containing a > backslash that doesn't fit the bytea hex format or the bytea escape > format will fail to convert completely! Yes. It seems a common mistake to forget or ignore that backslashes are special in the input text representation of bytea. It might be not obvious from reading the doc at [1] but we just need to quote backslashes by doubling them. AFAIK a working solution for the OP would be: sha256(replace(colname, '\', '\\')::bytea) The result is encoding-dependent, but that does not matter in the context of an expression. index. If the database ever needs to change its encoding, it will have to be recreated entirely anyway. [1] https://www.postgresql.org/docs/current/datatype-binary.html#DATATYPE-BINARY-BYTEA-ESCAPE-FORMAT Best regards, -- Daniel Vérité https://postgresql.verite.pro/
В списке pgsql-general по дате отправления
От: Adrian Klaver
Дата:
От: Linus Heckemann
Дата: