Andrew Kilburn
Andrew Kilburn

Reputation: 2251

How to insert JSON data into a dynamic column MySQL?

Im simply trying to insert json data into a dynamic column.

Data looks like follows:

"{"Fields": {
    "CompanyCode": "1",
    "FiscalYear": "2014",
    "CalYear": "2014",
    "CalPeriod": "1",
    "MinPostDate": "2014-01-14T00:00:00",
    "MaxPostDate": "2014-01-14T00:00:00",
    "CreditDebitInd": "H"
  }
}"

Query is like this:

 INSERT INTO jsontest (ID, Text) VALUES(DEFAULT, 'JsonHere');

ID is an ID which is the PK and it auto increments. Text is a BLOB

Upvotes: 0

Views: 1531

Answers (1)

Andrew Kilburn
Andrew Kilburn

Reputation: 2251

INSERT INTO test VALUES(DEFAULT, '{"Fields": {
    "CompanyCode": "E009",
    "FiscalYear": "2014",
    "CalYear": "2014",
    "CalPeriod": "1",
    "MinPostDate": "2014-01-14T00:00:00",
    "MaxPostDate": "2014-01-14T00:00:00",
    "CreditDebitInd": "H"
  }
}');

I was using the ` symbol to encapsulate the data. It needs to be the ' symbol

Upvotes: 2

Related Questions