Using PostgreSQL query to write/read the value of jsonb?

As topic title, can I just use the PostgreSQL query to write/read the value of jsonb, such as user’s wallet and the value of storage objects?
Because most of the time, I just want to read or write one value of the jsonb in the Postgre database.
If I use the runtime function which always needs to unmarshal and marshal the objects, then put it into the Postgre.
Any recommendations?
I use the Golang 1.18 version and Nakama 3.12.
Thanks! :smiley:

Hey :wave:

You can do that, but we don’t recommend it. Marshaling and unmarshaling objects through the Nakama API has trivial performance implications.

Hello, what’s the recommend way to store data in PostgreSQL?
It’s the way the all data save in the value column like below:

or separate the value to just one value and save it in the column like below:


thanks! :smiley:

Hey @9843h9d87 will players be mutating this data? If not, you don’t even need to put it in Postgres but can just put it in your code in a map.

1 Like

Hello, lugehorsam.
Sorry for I used my friends account to reply.
It will a quite large data/table to check the status of players, like above is a level checking table and the data/table will update sometimes.
Our team needs to decide how to save and handle those data/table will get excellent performance.
Thanks! :smiley:

Okay. Like I said, I’d go with config-in-code if it’s not being mutated by the user, otherwise I’d store it using our storage API but clean up your schema to use an array like this, if your levels are going to be ordered:

{
   "levels": [
     { 
       "ExpNeed": 6
     },
     ...
   ]
}

Separate each data to just one value of jsonb and using “Key Name” to search the results will get a better performance when the data/table grow up?
We knew this is a database issue, just curious about how will handle/save the data/table in a general way.
Thanks!

It depends on your access patterns to the data.

Our idea is using “select SQL query” to access jsonb data/table directly , normally we just need 1~3 value, not entire table, then send it to Client, the Client will return final data to Server, the server using “StorageWriteFunction” to update the data/table.

For an XP model, I’d recommend putting experience requirements in a static configuration and storing the user’s current level, total XP, and the XP since the last level in the storage engine. That way you aren’t pulling more data than you need from the storage engine.