Re: Problem with || and data types - Mailing list pgsql-general

From Tom Lane
Subject Re: Problem with || and data types
Date
Msg-id 25679.1051751740@sss.pgh.pa.us
Whole thread Raw
In response to Re: Problem with || and data types  ("Peter Darley" <pdarley@kinesis-cem.com>)
List pgsql-general
"Peter Darley" <pdarley@kinesis-cem.com> writes:
>     I've figured out the problem here... When I have a where clause that
> contains "x=(select x from y where z) || 'test'" it's interpreting this as
> "(x=(select x from y where z)) || 'test'" instead of "x=((select x from y
> where z) || 'test')".

Doesn't look that way from here:

regression=# explain
regression-# select f1 from int4_tbl where f1 = (select unique1 from tenk1) || 'test';
                            QUERY PLAN
-------------------------------------------------------------------
 Seq Scan on int4_tbl  (cost=0.00..1.10 rows=1 width=4)
   Filter: ((f1)::text = (($0)::text || 'test'::text))
   InitPlan
     ->  Seq Scan on tenk1  (cost=0.00..458.00 rows=10000 width=4)
(4 rows)

Whether this is a particularly sensible interpretation I dunno, but
for sure it's binding || more tightly than =.

There are related syntaxes (= ANY and so forth) that are treated like
generic operators and so would bind left-to-right in this example:

regression=# explain
regression-# select f1 from int4_tbl where f1 = any (select unique1 from tenk1) || 'test';
ERROR:  Unable to identify an operator '||' for types 'boolean' and '"unknown"'
        You will have to retype this query using an explicit cast

But AFAICT 7.2 does that the same way.

            regards, tom lane


pgsql-general by date:

Previous
From: Tom Lane
Date:
Subject: Re: box function implemented?
Next
From: Tom Lane
Date:
Subject: Re: Problem with || and data types