DEV Community


Discussion on: PostgreSQL vs MongoDB

rhymes profile image

Yeah, PostgreSQL almost got it, except JSON in Postgres are strings. Almost there :)

Not really though: JSON in PostgreSQL is just JSON:

PracticalDeveloper_development> select id, username, email_public from users limit 1;
| id   | username        | email_public   |
| 6    | rosenbaumladawn | False          |
Time: 0.016s
PracticalDeveloper_development> select row_to_json(t) from (select id, username, email_public from users limit 1) t;
| row_to_json                                                |
| {"id":6,"username":"rosenbaumladawn","email_public":false} |
Time: 0.015s

Integers are integers, strings are strings and booleans are booleans

Thread Thread
necmettin profile image
Necmettin Begiter

When PostgreSQL came up with the JSON features, I remember reading examples and always seeing 'some-json-formatted-data'::JSON, so I assumed JSON data is given to / received from PostgreSQL in a string. Even the comments field in your example a few comments back (the one with the 3 comments of user 10) has the JSON data in strings.

If that isn't the case, my bad, I didn't know PostgreSQL had progressed this far, I thought it was still using strings to encapsulate/represent JSON data contained in cells.

Forem Open with the Forem app