var connectionString = "<an amazing connection string>";
using (var conn = new NpgsqlConnection(connectionString)) {
conn.Open();
using (var trans = conn.BeginTransaction()) {
using(var cmd = new NpgsqlCommand(@"SELECT 1000000000000000000000.123456789;", conn, trans)) {
Console.Out.WriteLine(cmd.ExecuteScalar());
}
}
}
ExecuteScalar()
is unable to return large decimal numbers.
Exception message:
Unknown message code: 22
Unknown message code: 35
Stack trace:
The stack trace is the same for both cases, only the message changes.
Npgsql.NpgsqlException
HResult=0x80004005
Message=Unknown message code: XX
Source=Npgsql
StackTrace:
at Npgsql.Util.PGUtil.ValidateBackendMessageCode(BackendMessageCode code)
at Npgsql.NpgsqlConnector.<>c__DisplayClass160_0.<<DoReadMessage>g__ReadMessageLong|0>d.MoveNext()
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Npgsql.NpgsqlDataReader.<NextResult>d__44.MoveNext()
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Npgsql.NpgsqlDataReader.<Consume>d__64.MoveNext()
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Npgsql.NpgsqlDataReader.<Close>d__69.MoveNext()
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Npgsql.NpgsqlDataReader.Close()
at Npgsql.NpgsqlCommand.<ExecuteScalar>d__95.MoveNext()
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Npgsql.NpgsqlCommand.ExecuteScalar()
at Tests.Program.Main(String[] args)
Npgsql version: 4.0.10 & 4.1.3.1
PostgreSQL version: 11.4 & 12
Operating system: Windows 10
Will take a look.
@YohDeadfall pinging as a reminder :)
The expected exception from ExecuteScalar
is "hidden" behind an unexpected exception from Dispose
as already seen in #2621.
The exception should be here an OverflowException("Numeric value does not fit in a System.Decimal")
.
Thanks @manandre! That code actually catches OverflowException, but it's also reading within that try/catch and probably doesn't make sure everything has been consumed before throwing NpgsqlSafeReadException. Am going to close this as a duplicate of #2621.
Most helpful comment
Will take a look.