Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot prepare query longer than 73707 characters. #2635

Open
catsaremine opened this issue Sep 24, 2019 · 0 comments

Comments

@catsaremine
Copy link

commented Sep 24, 2019

Steps to reproduce

using System;
using System.Threading.Tasks;
using Npgsql;

namespace PgBlobParam
{
    class Program
    {
        static async Task Main(string[] args)
        {
            const string connectionString = "xxxx";
            int queryLength = 73708;

            string template = "select '{0}';";

            string sql = string.Format(template, new string('A', (queryLength - template.Length) + 3)); // +3 for the '{0}'.

            using (var connection = new NpgsqlConnection(connectionString))
            {
                await connection.OpenAsync();

                try
                {
                    using (var command = connection.CreateCommand())
                    {
                        command.CommandText = sql;

                        await command.PrepareAsync();

                        await command.ExecuteNonQueryAsync();
                    }

                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                    throw;
                }
            }

            Console.WriteLine();
        }
    }
}

The issue

When you have a query that is longer than 73707 characters the driver fails and throws an exception: Received backend message ParseComplete while expecting ReadyForQueryMessage. Please file a bug.

Exception message: Received backend message ParseComplete while expecting ReadyForQueryMessage. Please file a bug.

Stack trace:
  at Npgsql.NpgsqlCommand.<>c__DisplayClass74_0.<<Prepare>g__PrepareLong|0>d.MoveNext()
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at PgBlobParam.Program.<Main>d__0.MoveNext() in D:\Dev\small-projects\PgBlobParam\Program.cs:line 33

Further technical details

Npgsql version: 4.0.10
PostgreSQL version: psql (PostgreSQL) 11.5 (Ubuntu 11.5-1.pgdg16.04+1)
Operating system: Ubuntu 16.04

@roji roji added the bug label Sep 24, 2019
@roji roji added this to the 4.0.11 milestone Sep 24, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.