News for hackers. Stuff that matters.
Re:Don't Do This with PostgreSQL by FreakLegion on Tuesday November 12, 2024 @08:12PM (#42121891)
There's also "char", with quotes, as a special type. It's always 1 byte.

The other types have overhead. A single-byte bytea will actually use 2 bytes, char(1) will use at least that much, and bit(8) will use 7 bytes. Smallint is strictly better for representing small numbers.

Re:Don't Do This with PostgreSQL by Volundr on Wednesday November 13, 2024 @09:47PM (#42132642)
TIL: https://www.postgresql.org/docs/17/datatype-character.html (it's in the table at the bottom). I'd still be suspicious of using it, and the docs recommend against it, but it exists.
Re:Don't Do This with PostgreSQL by FreakLegion on Thursday November 21, 2024 @12:20AM (#42201378)
A good reason not to use it is that 49::"char"::int == 49, but 49::"char"::smallint == 1. In other words, int casts directly interpret the value as an integer, but smallint (and bigint) casts interpret it as an ASCII character, '1', which they then convert to the integer 1.