pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
BUG #10201: Invalid input accepted with IN expression
4+ messages / 4 participants
[nested] [flat]

* BUG #10201: Invalid input accepted with IN expression
@ 2014-05-02 20:01  dbaston@gmail.com
  0 siblings, 2 replies; 4+ messages in thread

From: dbaston@gmail.com @ 2014-05-02 20:01 UTC (permalink / raw)
  To: pgsql-bugs

The following bug has been logged on the website:

Bug reference:      10201
Logged by:          Daniel Baston
Email address:      dbaston@gmail.com
PostgreSQL version: 9.2.2
Operating system:   Windows Server 2012
Description:        

If two items in an IN expression are separated by a newline instead of a
comma, those items will be ignored with no error.

CREATE TABLE testing (id varchar(1));
INSERT INTO testing VALUES ('1'), ('2'), ('3'), ('4'), ('5');

-- Missing comma produces a syntax error
SELECT * FROM testing WHERE id IN ('1'  '2', '3');

-- Unless there is a newline
SELECT * FROM testing WHERE id IN ('1' 
'2', '3');

 id
----
 3
(1 row)



-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs



^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: BUG #10201: Invalid input accepted with IN expression
@ 2014-05-02 20:05  Andres Freund <andres@2ndquadrant.com>
  parent: dbaston@gmail.com
  1 sibling, 0 replies; 4+ messages in thread

From: Andres Freund @ 2014-05-02 20:05 UTC (permalink / raw)
  To: dbaston@gmail.com; +Cc: pgsql-bugs

Hi,

On 2014-05-02 20:01:27 +0000, dbaston@gmail.com wrote:
> If two items in an IN expression are separated by a newline instead of a
> comma, those items will be ignored with no error.
> 
> CREATE TABLE testing (id varchar(1));
> INSERT INTO testing VALUES ('1'), ('2'), ('3'), ('4'), ('5');
> 
> -- Missing comma produces a syntax error
> SELECT * FROM testing WHERE id IN ('1'  '2', '3');
> 
> -- Unless there is a newline
> SELECT * FROM testing WHERE id IN ('1' 
> '2', '3');

Check what
SELECT '1'
'2';
returns. Two string constants separated by a newline are essentially
concatenated. So, what the above means is: id IN ('12', '3')

Check:
http://www.postgresql.org/docs/current/interactive/sql-syntax-lexical.html#SQL-SYNTAX-CONSTANTS

Greetings,

Andres Freund

-- 
 Andres Freund	                   http://www.2ndQuadrant.com/
 PostgreSQL Development, 24x7 Support, Training & Services


-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs



^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: BUG #10201: Invalid input accepted with IN expression
@ 2014-05-02 20:07  Tom Lane <tgl@sss.pgh.pa.us>
  parent: dbaston@gmail.com
  1 sibling, 1 reply; 4+ messages in thread

From: Tom Lane @ 2014-05-02 20:07 UTC (permalink / raw)
  To: dbaston@gmail.com; +Cc: pgsql-bugs

dbaston@gmail.com writes:
> If two items in an IN expression are separated by a newline instead of a
> comma, those items will be ignored with no error.

> CREATE TABLE testing (id varchar(1));
> INSERT INTO testing VALUES ('1'), ('2'), ('3'), ('4'), ('5');

> -- Missing comma produces a syntax error
> SELECT * FROM testing WHERE id IN ('1'  '2', '3');

> -- Unless there is a newline
> SELECT * FROM testing WHERE id IN ('1' 
> '2', '3');

This is not a bug; what you've got there is the SQL-standard way of
breaking a literal across lines.  Compare

select '1'
'2', '3';
 ?column? | ?column? 
----------+----------
 12       | 3
(1 row)

			regards, tom lane


-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs



^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: BUG #10201: Invalid input accepted with IN expression
@ 2014-05-02 20:08  Daniel Baston <dbaston@gmail.com>
  parent: Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 0 replies; 4+ messages in thread

From: Daniel Baston @ 2014-05-02 20:08 UTC (permalink / raw)
  To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: pgsql-bugs

Got it.  Apologies for the false positive.


On Fri, May 2, 2014 at 4:07 PM, Tom Lane <tgl@sss.pgh.pa.us> wrote:

> dbaston@gmail.com writes:
> > If two items in an IN expression are separated by a newline instead of a
> > comma, those items will be ignored with no error.
>
> > CREATE TABLE testing (id varchar(1));
> > INSERT INTO testing VALUES ('1'), ('2'), ('3'), ('4'), ('5');
>
> > -- Missing comma produces a syntax error
> > SELECT * FROM testing WHERE id IN ('1'  '2', '3');
>
> > -- Unless there is a newline
> > SELECT * FROM testing WHERE id IN ('1'
> > '2', '3');
>
> This is not a bug; what you've got there is the SQL-standard way of
> breaking a literal across lines.  Compare
>
> select '1'
> '2', '3';
>  ?column? | ?column?
> ----------+----------
>  12       | 3
> (1 row)
>
>                         regards, tom lane
>

^ permalink  raw  reply  [nested|flat] 4+ messages in thread


end of thread, other threads:[~2014-05-02 20:08 UTC | newest]

Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2014-05-02 20:01 BUG #10201: Invalid input accepted with IN expression dbaston@gmail.com
2014-05-02 20:05 ` Andres Freund <andres@2ndquadrant.com>
2014-05-02 20:07 ` Tom Lane <tgl@sss.pgh.pa.us>
2014-05-02 20:08   ` Daniel Baston <dbaston@gmail.com>

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