pg.ddx.io pgsql-bugs@postgresql.org mailing list archive
help / color / mirror / Atom feedBug involving plus sign before newline in text field being duplicated or stripped
4+ messages / 3 participants
[nested] [flat]
* Bug involving plus sign before newline in text field being duplicated or stripped
@ 2019-03-12 15:36 Jon Wedell <wedell@bmrb.wisc.edu>
2019-03-12 17:08 ` Re: Bug involving plus sign before newline in text field being duplicated or stripped Alvaro Herrera <alvherre@2ndquadrant.com>
2019-03-12 17:18 ` Re: Bug involving plus sign before newline in text field being duplicated or stripped Tom Lane <tgl@sss.pgh.pa.us>
0 siblings, 2 replies; 4+ messages in thread
From: Jon Wedell @ 2019-03-12 15:36 UTC (permalink / raw)
To: pgsql-bugs@lists.postgresql.org; +Cc: Dimitri Maziuk <dmaziuk@bmrb.wisc.edu>
Hello,
This report contains either one or two distinct bugs, if they are two
they appear related.
First I noticed than when using the python pyscopg2-binary library, a
plus sign immediately proceeding a newline at the end of a value was
being stripped.
When investigating further, I noticed that when directly using the psql
command line interface, when inserting a text value ending with a plus
sign and then a newline, the plus sign is duplicated.
This behavior exists on the following three versions I have tested:
PostgreSQL 11.2 (Ubuntu 11.2-1.pgdg18.04+1) on x86_64-pc-linux-gnu,
compiled by gcc (Ubuntu 7.3.0-27ubuntu1~18.04) 7.3.0, 64-bit
and
PostgreSQL 10.7 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 4.4.7
20120313 (Red Hat 4.4.7-23), 64-bit
and
PostgreSQL 10.6 (Ubuntu 10.6-0ubuntu0.18.04.1) on x86_64-pc-linux-gnu,
compiled by gcc (Ubuntu 7.3.0-16ubuntu3) 7.3.0, 64-bit
I've attached very small example SQL and python files that reproduce the
bug(s). The SQL file demonstrates the duplication bug - run it first.
The python file demonstrates the stripping bug - run it after the table
is created.
Here is an example of the duplication bug (ran on a fresh 11.2
installation from the postgresql repo on Ubuntu 18.04, no configuration
changes or start up options):
wedell@manowar:~$ psql -U postgres
psql (11.2 (Ubuntu 11.2-1.pgdg18.04+1))
Type "help" for help.
postgres=# create table test (inchi text);
CREATE TABLE
postgres=# insert into test values ('test+
postgres'# ');
INSERT 0 1
postgres=# select * from test;
inchi
-------
test++
(1 row)
As you can see, only one plus sign was inserted, but two are returned.
(The expected return value was 'test+\n' but the actual value was
'test++\n'.)
For reference, the second line as entered was
insert into test values ('test+
');
The second bug is that pyscopg2-binary is stripping a plus sign at the
end of the value out. The following example was ran immediately after
the SQL above:
wedell@manowar:~$ python
Python 2.7.15rc1 (default, Nov 12 2018, 14:31:15)
Type "copyright", "credits" or "license" for more information.
IPython 5.5.0 -- An enhanced Interactive Python.
? -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help -> Python's own help system.
object? -> Details about 'object', use 'object??' for extra details.
In [1]: import psycopg2
In [2]: conn = psycopg2.connect(user='postgres')
In [3]: cur = conn.cursor()
In [4]: cur.execute('select * from test');
In [5]: print cur.fetchall()
[('test+\n',)]
Based on the psql response above, the expected value was 'test++\n' but
the actual value was 'test+\n'.
It is true that the original insert had one plus sign, but if psql is to
be believed the value in the database now has two. This was how I
originally noticed the problem; in a table I had a value which psql
reports having just one plus sign, but psycopg2 strips it and returns a
value with none.
I'm happy to provide any other information necessary.
Best Regards,
Jon Wedell
Attachments:
bug.psql (text/plain, 114B) download
drop table if exists test;
create table test (inchi text);
insert into test values ('test+
');
select * from test;
bug.py (text/x-python, 195B) download
#!/usr/bin/env python2
from __future__ import print_function
import psycopg2
conn = psycopg2.connect(user='postgres')
cur = conn.cursor()
cur.execute('select * from test')
print(cur.fetchall())
signature.asc (application/pgp-signature, 487B) download
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: Bug involving plus sign before newline in text field being duplicated or stripped
2019-03-12 15:36 Bug involving plus sign before newline in text field being duplicated or stripped Jon Wedell <wedell@bmrb.wisc.edu>
@ 2019-03-12 17:08 ` Alvaro Herrera <alvherre@2ndquadrant.com>
2019-03-12 17:20 ` Re: Bug involving plus sign before newline in text field being duplicated or stripped Jon Wedell <wedell@bmrb.wisc.edu>
1 sibling, 1 reply; 4+ messages in thread
From: Alvaro Herrera @ 2019-03-12 17:08 UTC (permalink / raw)
To: Jon Wedell <wedell@bmrb.wisc.edu>; +Cc: pgsql-bugs@lists.postgresql.org, Dimitri Maziuk <dmaziuk@bmrb.wisc.edu>
On 2019-Mar-12, Jon Wedell wrote:
> postgres=# select * from test;
> inchi
> -------
> test++
>
This is just psql showing a literal "+" as continuation character,
indicating that the field contains a newline. Try changing "\pset
format" to something different.
--
Álvaro Herrera https://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: Bug involving plus sign before newline in text field being duplicated or stripped
2019-03-12 15:36 Bug involving plus sign before newline in text field being duplicated or stripped Jon Wedell <wedell@bmrb.wisc.edu>
2019-03-12 17:08 ` Re: Bug involving plus sign before newline in text field being duplicated or stripped Alvaro Herrera <alvherre@2ndquadrant.com>
@ 2019-03-12 17:20 ` Jon Wedell <wedell@bmrb.wisc.edu>
0 siblings, 0 replies; 4+ messages in thread
From: Jon Wedell @ 2019-03-12 17:20 UTC (permalink / raw)
To: Alvaro Herrera <alvherre@2ndquadrant.com>; +Cc: pgsql-bugs@lists.postgresql.org
🤦
Thanks guys, this was the source of my confusion.
Best,
Jon
> On 2019-Mar-12, Jon Wedell wrote:
>
>> postgres=# select * from test;
>> inchi
>> -------
>> test++
>>
> This is just psql showing a literal "+" as continuation character,
> indicating that the field contains a newline. Try changing "\pset
> format" to something different.
>
Attachments:
signature.asc (application/pgp-signature, 487B) download
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: Bug involving plus sign before newline in text field being duplicated or stripped
2019-03-12 15:36 Bug involving plus sign before newline in text field being duplicated or stripped Jon Wedell <wedell@bmrb.wisc.edu>
@ 2019-03-12 17:18 ` Tom Lane <tgl@sss.pgh.pa.us>
1 sibling, 0 replies; 4+ messages in thread
From: Tom Lane @ 2019-03-12 17:18 UTC (permalink / raw)
To: Jon Wedell <wedell@bmrb.wisc.edu>; +Cc: pgsql-bugs@lists.postgresql.org, Dimitri Maziuk <dmaziuk@bmrb.wisc.edu>
Jon Wedell <wedell@bmrb.wisc.edu> writes:
> postgres=# create table test (inchi text);
> CREATE TABLE
> postgres=# insert into test values ('test+
> postgres'# ');
> INSERT 0 1
> postgres=# select * from test;
> inchi
> -------
> test++
>
> (1 row)
Well, that one is not a bug. The character value you inserted is
"t e s t + newline", and when psql renders a value including a
newline, by default it puts a plus at the end of the preceding line.
You can alter that behavior with psql's various \pset options, I believe.
> The second bug is that pyscopg2-binary is stripping a plus sign at the
> end of the value out.
I don't use pyscopg2, but I suspect that you're confusing
the decorative "+" shown by psql with actual data.
regards, tom lane
^ permalink raw reply [nested|flat] 4+ messages in thread
end of thread, other threads:[~2019-03-12 17:20 UTC | newest]
Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2019-03-12 15:36 Bug involving plus sign before newline in text field being duplicated or stripped Jon Wedell <wedell@bmrb.wisc.edu>
2019-03-12 17:08 ` Alvaro Herrera <alvherre@2ndquadrant.com>
2019-03-12 17:20 ` Jon Wedell <wedell@bmrb.wisc.edu>
2019-03-12 17:18 ` Tom Lane <tgl@sss.pgh.pa.us>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox