Re: [PATCH] Add crc32(text) & crc32(bytea)
| От | Aleksander Alekseev |
|---|---|
| Тема | Re: [PATCH] Add crc32(text) & crc32(bytea) |
| Дата | |
| Msg-id | CAJ7c6TOQX3PDSbci3bAvKqQQDEYgvJpYdPMHSywPy43i_h_SWQ@mail.gmail.com обсуждение исходный текст |
| Ответ на | Re: [PATCH] Add crc32(text) & crc32(bytea) (Nathan Bossart <nathandbossart@gmail.com>) |
| Ответы |
Re: [PATCH] Add crc32(text) & crc32(bytea)
|
| Список | pgsql-hackers |
Hi,
> This looks pretty good to me. The only point that I think deserves more
> discussion is the return type. Does bytea make the most sense here? Or
> should we consider int/bigint?
Personally I would choose BYTEA in order to be consistent with sha*() functions.
It can be casted to TEXT if user wants a result similar to the one
md5() returns:
```
SELECT encode(crc32('PostgreSQL'), 'hex');
```
... and somewhat less convenient to BIGINT:
```
SELECT ((get_byte(crc, 0) :: bigint << 24) | (get_byte(crc, 1) << 16)
| (get_byte(crc, 2) << 8) | get_byte(crc, 3))
FROM (SELECT crc32('PostgreSQL') AS crc);
```
I don't like the `integer` option because crc32 value is typically
considered as an unsigned one and `integer` is not large enough to
represent uint32.
Perhaps we need get_int4() / get_int8() / get_numeric() as there seems
to be a demand [1][2] and it will allow us to easily cast a `bytea`
value to `integer` or `bigint`. This is probably another topic though.
[1]: https://stackoverflow.com/questions/32944267/postgresql-converting-bytea-to-bigint
[2]: https://postgr.es/m/AANLkTikip9xs8iXc8e%2BMgz1T1701i8Xk6QtbVB3KJQzX%40mail.gmail.com
--
Best regards,
Aleksander Alekseev
В списке pgsql-hackers по дате отправления: