0

I am trying to load a JSON file into a PostgreSQL table that I've created, but I can't seem to figure out how to do it.

Everytime I try something it seems to be appropriate with SQL tables but not PostgreSQL.

This is my table :

create table test_opening_hours( 
    id serial primary key,
    info json
);

All I can do is insert lines into the table manually, but my file has 200+ different values so I can't do it this way. I'm pretty sure there must be a way to do it but I can't find how...

here's what I've tried so far :

COPY test_opening_hours(info) 
FROM 'data.json' ;

or

declare @jsondata nvarchar(max)
set @jsondata = 'data.json'

insert into test_opening_hours (info)
select * from openjson (@jsondata)
EmCot
  • 1
  • 2
  • What do you mean with "SQL tables"? All tables in Postgres are "SQL tables" as Postgres uses SQL as its query language. –  Oct 11 '19 at 15:06
  • Do you want to store the complete JSON value into a single column of a single row? Or do you want to turn the JSON into multiple rows and columns? –  Oct 11 '19 at 15:07
  • Sorry I meant that I use a SQL table but the query language is PostGreSQL and not MySQL. – EmCot Oct 11 '19 at 16:00
  • And I would like to have a singe row for each JSON value – EmCot Oct 11 '19 at 16:01
  • Possible duplicate of [How can I import a JSON file into PostgreSQL?](https://stackoverflow.com/questions/39224382/how-can-i-import-a-json-file-into-postgresql) – Bergi Oct 12 '19 at 03:56

0 Answers0