graphe
This commit is contained in:
30
docker-entrypoint-initdb.d/9_json.sql
Normal file
30
docker-entrypoint-initdb.d/9_json.sql
Normal file
@@ -0,0 +1,30 @@
|
||||
create table item (
|
||||
id integer primary key,
|
||||
data jsonb
|
||||
);
|
||||
|
||||
DO $$
|
||||
DECLARE
|
||||
f TEXT;
|
||||
BEGIN
|
||||
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, data)
|
||||
VALUES (
|
||||
replace(f, '.json','')::bigint,
|
||||
pg_read_file('/tmp/json/' || f)::jsonb
|
||||
)
|
||||
ON CONFLICT (id) DO UPDATE
|
||||
SET data = EXCLUDED.data;
|
||||
|
||||
EXCEPTION WHEN OTHERS THEN
|
||||
RAISE WARNING 'Erreur lors de l''import du fichier % : %', f, SQLERRM;
|
||||
END;
|
||||
END IF;
|
||||
END LOOP;
|
||||
END;
|
||||
$$ LANGUAGE plpgsql;
|
||||
Reference in New Issue
Block a user