Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
175 views
in Technique[技术] by (71.8m points)

json - Inserting a default data into MySql

I know this is a weird and strange thing to want to do, but that's what I am trying to achieve.

I have a MySql database and I wish to have a default data entered into a column of a table in my database, the data is in JSON format:

{
  "address":"behindthescene",
  "state":"Slovakia",
  "zip":"56456465",
  "country":"Argentina",
  "city

Here's the strange part, my Json is incomplete and needs to be enclosed properly but this is how I want it added.

I configured my table column to use this JSON data as the default value instead of having a null value but when it inserts this as the default value it also completes it hence I now have

{
  "address":"behindthescene",
  "state":"Slovakia",
  "zip":"56456465",
  "country":"Argentina",
  "city":""
}

This is not what I want, I need it to be in the same exact way I entered the data.

Can anyone guide me on how to get my desired results, do not mind the strangeness of my JSON, I have my reason for wanting it that way.

question from:https://stackoverflow.com/questions/65894109/inserting-a-default-data-into-mysql

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

It's because the value was set to JSON instead of a CHAR string. If you want it to be incomplete for some reason, just make it a string and stick it in raw.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...