BitArray: bit string length 1 does not match type bit(256)
See original GitHub issueCreated 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:
- Created 5 years ago
- Comments:5 (3 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
P.S. I’ve opened #2270 to track updating the docs with a sample or two based on this thread.
No worries! I actually misread your error message to be
bit[256]
instead ofbit(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.