Search code examples
postgresqlstreamnpgsqljsonb

Npgsql support for getting jsonb field as stream


I am trying to do the following on a jsonb field:

using (var reader = cmd.ExecuteReader())
{
    while (reader.Read())
    {
        using (var results = reader.GetStream(0))
        {
            results.CopyTo(stream);
        }
    }
    reader.Close();
}

and getting an exception telling me that GetStream is not supported for this field. Am I missing something here or is it Npgsql that simply doesn't support streaming jsonb fields (yet)?


Solution

  • This is already handled in the next version of Npgsql, 3.1. Unfortunately that version is still in alpha, hopefully I'll be able to release a beta in around two months.

    In the meantime you can work around this by reading the jsonb as a string, and if needed, wrapping a TextReader around it (may not be as efficient but will work).