简体   繁体   中英

How can I store this object in an SQL database?

I'm new to the game and am wondering if it's possible to store the following object in one column in an SQL database like postgres:

    {
      "foo1": ["bar1", "bar2"],
      "foo2": ["bar1", "bar2", "bar3"],
      "foo3": ["bar1", "bar2"]
    } 

    // Idea is to store a list of values in each foo.

I'm sure I have the syntax incorrect, too; any help is appreciated. Thanks.

Actually, you can use a JSON object.

Example: If you are using Postgres, it started supporting JSON objects since version 9.2 you can use JSON or JSONB as specified https://www.postgresql.org/docs/current/datatype-json.html

MySQL, Oracle, T-SQL, SQL server... supports it. You can find definitive guide on their documentation.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM