python - Hashed primary key -
i have table library
each row represents music track. want make primary key track's audio fingerprint. unfortunately sqlalchemy passes me postgres error when try insert:
operationalerror: (psycopg2.operationalerror) index row size 3384 exceeds maximum 2712 index "library_fingerprint_key" hint: values larger 1/3 of buffer page cannot indexed. consider function index of md5 hash of value, or use full text indexing.
i want store full fingerprint normal column , create hashed version primary key. i've tried using sqlalchemy's context-sensitive default functions still above error msg.
is there way automatically hash primary key based on column (the fingerprint column)?
code snippet below
def fingerprint_md5(context): return hashlib.md5(context.current_parameters['fingerprint']).hexdigest() class library(base): tablename = 'library' track_hash = column(string, primary_key=true, default=fingerprint_md5) fingerprint = column(string, nullable=false, unique=true)
updated index ddl:
indexes: "library_pkey" primary key, btree (track_hash) "library_fingerprint_key" unique constraint, btree (fingerprint) "library_path_key" unique constraint, btree (path)
the issue fingerprint value trying insert long index (primary key or otherwise). solution insert full fingerprint normal column no unique constraint, , calculate md5 hash primary key track_hash
using code in op.
Comments
Post a Comment