0

Using this SELECT:

select 'some_table' as table_name, jsonb_agg(t.*) as content
from some_table t;

If some_table had 1000 rows, are the "column names", which are repeated for each row in "content", sent over the network 1000 times? Or is that somehow optimized away? If the column names are really reapeated once per row, we would spend more bandwith for them, then for the values.

| improve this question | | | | |
  • Depends - usually the json-object carries only the data. Except its from serialization ... But if the column names are contained .. the chances are high that it's every time the case – eagle275 Nov 15 '19 at 14:46
2

It is not optimized. Each column name, as a JSON key, is sent in full, multiple times. You could try connecting over SSL and turning on compression, but for security reasons that is disabled by default in most systems, and is getting increasingly difficult to turn on.

If the column names are really reapeated once per row, we would spend more bandwith for them, then for the values.

If that is the highest cost you have to pay for gratuitous use of JSON, then consider yourself lucky.

| improve this answer | | | | |
  • It only looks "gratutious" because I haven't explained the motivation, as it's not really relevant to this question. Still, you made me laugh. :) – Sebastien Diot Nov 15 '19 at 15:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.