user1471980
user1471980

Reputation: 10626

Unable to insert JSON data into database table

I am trying to insert JSON data into an SQLite3 database table. I'm getting an error:

Error: near line 1: unrecognized token: "1d"

This is the query:

update dashboard set data=
'{"annotations":{"list":[]},"editable":true,"hideControls":false,"id":30,
"nav":[{"collapse":false,"enable":true,"notice":false,"now":false,
"refresh_intervals":["5s","10s","30s","1m","5m","15m","30m","1h","2h","1d"],
"status":"Stable",
"time_options":["5m","15m","1h","6h","12h","24h","2d","7d","30d"],"type":"timepicker"}]}'
where where title='TEMPLATE';

Any ideas what is causing this?

Upvotes: 0

Views: 132

Answers (1)

ravenspoint
ravenspoint

Reputation: 20457

I do not think you have posted the correct code. If I fix the double 'where' your code works just fine.

C:\Users\James>sqlite3 test
SQLite version 3.8.3.1 2014-02-11 14:52:19
Enter ".help" for instructions
Enter SQL statements terminated with a ";"
sqlite> create table dashboard ( data, title );
sqlite> .schema
CREATE TABLE dashboard ( data, title );
sqlite> insert into dashboard ( "test","TEMPLATE");
sqlite> update dashboard set data=
   ...> '{"annotations":{"list":[]},"editable":true,"hideControls":false,"id":30,
   ...> "nav":[{"collapse":false,"enable":true,"notice":false,"now":false,
   ...> "refresh_intervals":["5s","10s","30s","1m","5m","15m","30m","1h","2h","1d"],
   ...> "status":"Stable",
   ...> "time_options":["5m","15m","1h","6h","12h","24h","2d","7d","30d"],"type":"timepicker"}]}'
   ...> where where title='TEMPLATE';
Error: near "where": syntax error
sqlite> update dashboard set data=
   ...> '{"annotations":{"list":[]},"editable":true,"hideControls":false,"id":30,
   ...> "nav":[{"collapse":false,"enable":true,"notice":false,"now":false,
   ...> "refresh_intervals":["5s","10s","30s","1m","5m","15m","30m","1h","2h","1d"],
   ...> "status":"Stable",
   ...> "time_options":["5m","15m","1h","6h","12h","24h","2d","7d","30d"],"type":"timepicker"}]}'
   ...> where title='TEMPLATE';
sqlite> select * from dashboard;
{"annotations":{"list":[]},"editable":true,"hideControls":false,"id":30,
"nav":[{"collapse":false,"enable":true,"notice":false,"now":false,
"refresh_intervals":["5s","10s","30s","1m","5m","15m","30m","1h","2h","1d"],
"status":"Stable",
"time_options":       ["5m","15m","1h","6h","12h","24h","2d","7d","30d"],"type":"timepicker"}]}|TEMPLATE

>

Upvotes: 1

Related Questions