Re: Problem with || and data types

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "Peter Darley" <pdarley(at)kinesis-cem(dot)com>
Cc: "Pgsql-General" <pgsql-general(at)postgresql(dot)org>
Subject: Re: Problem with || and data types
Date: 2003-05-01 01:15:40
Message-ID: 25679.1051751740@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

"Peter Darley" <pdarley(at)kinesis-cem(dot)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

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2003-05-01 01:34:08 Re: Problem with || and data types
Previous Message Tom Lane 2003-05-01 00:53:45 Re: box function implemented?