Hello,
J'ai un petit problème, j'ai besoins de stocker des données binaires dans postgresql, j'ai donc cette table :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
| -- Table: bench_file
-- DROP TABLE bench_file;
CREATE TABLE bench_file
(
id integer NOT NULL DEFAULT nextval('bech_file_id_seq'::regclass),
"name" character varying(1024) NOT NULL,
bindata bytea,
hexdigest character varying(20) NOT NULL,
CONSTRAINT pk_bench_file_id PRIMARY KEY (id),
CONSTRAINT unik_bench_file_name UNIQUE (name)
)
WITH (OIDS=FALSE);
ALTER TABLE bench_file OWNER TO test; |
J'essaie d'insérer des données comme ceci :
INSERT INTO bench_file(name,bindata,hexdigest) VALUES ('ooo','ao', ENCODE(DIGEST(bindata, 'sha1'), 'hex'))
(ici une ligne d'exemple pour tester),
Seulement j'ai cette erreur :
1 2 3
|
ERROR: column "bindata" does not exist
LINE 1: ...bindata,hexdigest) VALUES ('ooo','ao', ENCODE(DIGEST(bindata, 'sha... |
Alors que pourtant, je peux très bien select bindata, et cela fonctionne très bien, il y a juste un problème au niveau de l'insertion, que faire ?
Merci
EDIT: Problème résolu via :
INSERT INTO bench_file(name,bindata,hexdigest) SELECT name,bindata::bytea,encode(digest(bindata, 'sha1'), 'hex') from (values (%s,%s)) as val(name,bindata);
Partager