HiveBrain v1.2.0
Get Started
← Back to all entries
snippetsqlMinor

How to use an RSA public key as the primary key to a table in postgres

Submitted by: @import:stackexchange-dba··
0
Viewed 0 times
theprimarypostgresrsapublichowusetablekey

Problem

I have a data set that needs to be looked up by RSA public keys. These keys are 392 text characters long.

What is the best way to make that a primary and/or unique key?

Should it be a BYTEA field?

Is it too long for a primary key? Should I store a shorter hashed version of it to index on and filter by first before checking for an exact match?

Solution

I would say store them as bytea, but not for that reason. Simply because pg_crypto expects the keys as bytea. That establishes a convention. They likely have good reason for it: it seems intuitively faster.

Also there is no reason to store them as a PRIMARY KEY. You can sanely just store them in an indexed field.

Context

StackExchange Database Administrators Q#115128, answer score: 2

Revisions (0)

No revisions yet.