question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

BitArray: bit string length 1 does not match type bit(256)

See original GitHub issue

Created a postgresql tabel on my local computer with 2 columns (SystemID [as uuid], TrackingIDs [as Bit[] with size 256]).

In C# ASP.NET I’m getting the error:

22026: bit string length 1 does not match type bit(256)

“new BitArray(256)” is 256 in length not ‘1’ as the error suggests.

Here is an example of my C# code:

using (var connection = new NpgsqlConnection(DBUtils.connectionString))
{
    try
    {
        connection.Open();
        using (var cmd = connection.CreateCommand())
        {
            cmd.CommandText = "INSERT INTO hosts VALUES(@SystemID, @TrackingIDs)";
            cmd.Parameters.AddWithValue("@SystemID", NpgsqlDbType.Uuid, systemID);
            cmd.Parameters.AddWithValue("@TrackingIDs", NpgsqlDbType.Bit | NpgsqlDbType.Array, new BitArray(256));
            return cmd.ExecuteNonQuery() != 0 ? "Success" : "Failed";
        }
    }
    catch (Exception ex)
    {
        return ex.Message;
    }
    finally
    {
        connection.Close();
    }
}

Further technical details

pgAdmin4: 3.6 Npgsql version: 4.0.4 PostgreSQL version: 11.1 Operating system: Win10 x64 ASP.NET: .NET Core 2.2

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
austindrenskicommented, Dec 20, 2018

P.S. I’ve opened #2270 to track updating the docs with a sample or two based on this thread.

0reactions
austindrenskicommented, Dec 20, 2018

Yep that was it. Ok sorry for the confusion. Was just doing stuff in MySQL which is a lot more limited. PostgreSQL is awesome it divides stuff up like this.

No worries! I actually misread your error message to be bit[256] instead of bit(256), so apologies if that sample was a bit off base.

Glad that we were able to get to the bottom of it. Feel free to post back here if you encounter any other issues with this topic.

Read more comments on GitHub >

github_iconTop Results From Across the Web

ASP.NET postgresql NpgsqlDbType.Bit doesn't support ...
So the solution is to just create a "bit" type column with a length of 256. Then I can set a BitArray(256) to...
Read more >
BIT
The BIT and VARBIT data types stores bit arrays. With BIT , the length is fixed; with VARBIT , the length can be...
Read more >
Documentation: 15: 8.10. Bit String Types
Bit strings are strings of 1's and 0's. ... bit type data must match the length n exactly; it is an error to...
Read more >
bitarray
This library provides an object type which efficiently represents an array of booleans. Bitarrays are sequence types and behave very much like usual...
Read more >
bitstring.py
Classes: Bits -- An immutable container for binary data. ... length, value] initialiser is one of: hex, oct, bin, uint, int, se, ue,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found