jackc / pgtype

MIT License
300 stars 111 forks source link

why is pgtype.JSONB PreferredResultFormat == TextFormatCode instead of BinaryFormatCode? #168

Closed ashtonian closed 1 year ago

ashtonian commented 2 years ago

I just noticed the JSONB types PreferredResultFormat is set to TextFormatter which avoids binary decoding, is this intentional?

jackc commented 2 years ago

Yes. The only difference between text and binary format is the binary format is prefixed by binary 1. Using the text format makes it the result more flexible. Also, returning text values in the binary format can be significantly slower. See https://www.postgresql.org/message-id/CAMovtNoHFod2jMAKQjjxv209PCTJx5Kc66anwWvX0mEiaXwgmA%40mail.gmail.com

ashtonian commented 1 year ago

Thanks for the followup, and opening the upstream issue. I added a pr with a comment to add some context, not sure if its worth the merge. Awesome lib, thanks!