Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading