postgresql 18

This commit is contained in:
2025-10-05 19:16:58 +02:00
parent 52241d96b7
commit 5d5e882e56
3 changed files with 41 additions and 26 deletions

View File

@@ -1,22 +1,25 @@
create table item (
id bigint primary key,
caracteristiques jsonb
);
DO $$
DECLARE
f TEXT;
f TEXT;
BEGIN
FOR f IN SELECT pg_catalog.pg_ls_dir('/tmp/json')
LOOP
IF right(f, 5) = '.json' THEN
INSERT INTO item (id, caracteristiques)
VALUES (
replace(f, '.json','')::bigint,
pg_read_file('/tmp/json/' || f)::jsonb
)
ON CONFLICT (id) DO UPDATE SET caracteristiques = EXCLUDED.caracteristiques;
END IF;
END LOOP;
FOR f IN SELECT pg_catalog.pg_ls_dir('/tmp/json')
LOOP
IF right(f, 5) = '.json' THEN
BEGIN
RAISE NOTICE 'Import du fichier : %', f;
INSERT INTO item (id, caracteristiques)
VALUES (
replace(f, '.json','')::bigint,
pg_read_file('/tmp/json/' || f)::jsonb
)
ON CONFLICT (id) DO UPDATE
SET caracteristiques = EXCLUDED.caracteristiques;
EXCEPTION WHEN OTHERS THEN
RAISE WARNING 'Erreur lors de l''import du fichier % : %', f, SQLERRM;
END;
END IF;
END LOOP;
END;
$$ LANGUAGE plpgsql;