Npgsql is the open source .NET data provider for PostgreSQL. It allows you to connect and interact with PostgreSQL server using .NET.
For the full documentation, please visit the Npgsql website. For the Entity Framework Core provider that works with this provider, see Npgsql.EntityFrameworkCore.PostgreSQL.
Here's a basic code snippet to get you started:
var connString = "Host=myserver;Username=mylogin;Password=mypass;Database=mydatabase";
await using var conn = new NpgsqlConnection(connString);
await conn.OpenAsync();
// Insert some data
await using (var cmd = new NpgsqlCommand("INSERT INTO data (some_field) VALUES (@p)", conn))
{
cmd.Parameters.AddWithValue("p", "Hello world");
await cmd.ExecuteNonQueryAsync();
}
// Retrieve all rows
await using (var cmd = new NpgsqlCommand("SELECT some_field FROM data", conn))
await using (var reader = await cmd.ExecuteReaderAsync())
{
while (await reader.ReadAsync())
Console.WriteLine(reader.GetString(0));
}
- High-performance PostgreSQL driver. Regularly figures in the top contenders on the TechEmpower Web Framework Benchmarks.
- Full support of most PostgreSQL types, including advanced ones such as arrays, enums, ranges, multiranges, composites, JSON, PostGIS and others.
- Highly-efficient bulk import/export API.
- Failover, load balancing and general multi-host support.
- Great integration with Entity Framework Core via Npgsql.EntityFrameworkCore.PostgreSQL.
For the full documentation, please visit the Npgsql website at https://www.npgsql.org.
Bug1645 -> Npgsql.PostgresException : 42P07: relation "data" already exists Bug2278 -> Npgsql.PostgresException : 0A000: DOMAIN is not yet supported. Bug2296 -> Npgsql.PostgresException : 42P07: relation "data" already exists Bug3649 -> Npgsql.PostgresException : 42601: syntax error at or near "binary"
Chunked_char_array_write_buffer_encoding_space -> Npgsql.PostgresException : 42601: syntax error at or near "BINARY" Chunked_string_write_buffer_encoding_space -> Npgsql.PostgresException : 42601: syntax error at or near "BINARY"
Connect_OptionsFromEnvironment_Succeeds -> SetEnvironmentVariable("PGOPTIONS", "-c default_transaction_isolation=serializable -c default_transaction_deferrable=on -c foo.bar=My"))
Npgsql.PostgresException : 0A000: openGauss does not support large object yet
String_to_citext -> Npgsql.PostgresException : 58P01: could not open extension control file: No such file or directory
StatementOID_legacy_batching -> CREATE TABLE ... WITH OIDS is not yet supported.
Column_schema_data_types -> type line is not yet supported
MetaDataCollections -> type pg_node_tree is not yet supported.
Precision_and_scale -> type pg_node_tree is not yet supported
Interval_as_Duration_with_months_fails -> function make_interval(months := integer) does not exist