Postgresql libpq inserting empty line for no reason
I am using libpq library in C to access my Postgresql database. The application inserts some of the data supplied from the queue. When there is a lot of data and it inserts very quickly, it will randomly insert an empty row into the table as well. Before I even do the pasting, I check that the length of the text to be inserted is greater than one. Is there any reason why this happens by accident? This happens when there is less data.
* I would like to point out that this does not happen in Mysql, only Postgresql
a source to share
See commentary by Milena A. Radev. It had to be the answer. You must not allow blank lines.
Of course, at least one column can have a constraint that can cause the insert to fail. Your application can then print / log the error with enough diagnostics for you to figure out what is happening and under what conditions.
Without rearranging the above, determine if all the data from your queue was inserted correctly or if some rows are missing. Ie, see if some strings are translated into blank inserts. If you see that some data is causing this, you can find what contains the problem data.
Are you using prepared, parameterized inserts, or are you building the SQL insert statement string every time and doing that? If you are creating SQL strings for execution, you must ensure that you are quoting character / binary string columns correctly using the procedures provided by libpq. Or switch to a different way of preparing insert and passing data as parameters, where it can be correctly quoted by libpq itself. It can also improve performance.
a source to share