Currently I'm trying to develop a PostgreSQL database schema, it has only 2 tables, one of which contains usernames. The difficulty is that for certain reasons I cannot store the username directly, so I have to store the hash (SHA256).
Postgres has a bytea data type, which is an array of bytes, which is technically SHA256.
My question is whether there is a better type to store the hash in terms of speed of searching whether the username exists in the database or not.
Perhaps I should look towards NoSQL solutions, where such a search is faster?
-----Add-----
The answer and comments suggest that it is optimal to use bytea
.
CREATE TABLE users (
username bytea PRIMARY KEY,
somedata text NOT NULL
);
CHAR(64)
instead ofbytea
? Or maybe something else?bytea
is probably the most compact way of storing the hash.