Re: || operator

From: Vinayak <vinpokale(at)gmail(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: || operator
Date: 2014-09-04 09:13:04
Message-ID: 1409821984720-5817712.post@n5.nabble.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hi,

The || operator with arguments (character,character) works fine and even ||
operator(character,varchar) also works fine.
but || operator is not working as expected with arguments character data
type and any other data type like integer,smallint,date,text.
Example:
postgres=# select 'ab'::char(10) || 4::int;
?column?
----------
ab4
(1 row)
postgres=# select 'ab'::char(10) || 'a'::text;
?column?
-------------
aba
(1 row)

so I have created || operator with argument character and anyelement.
Example:
create or replace function concat_character(character, anyelement) returns
text as $$ select concat($1,$2)$$ language sql;
create operator || (procedure = concat_character, leftarg = character,
rightarg = anyelement);
it works fine with argument of type int,smallint,bigint,date etc.
but its not working with text and varchar data type.
Example:
postgres=# select 'ab'::char(10) || 4::int;
?column?
-------------
ab 4
(1 row)

postgres=# select 'ab'::char(10) || 'b'::text;
?column?
----------
abb
(1 row)

postgres=# select 'ab'::char(10) || 'b'::varchar(5);
ERROR: operator is not unique: character || character varying
LINE 1: select 'ab'::char(10) || 'b'::varchar(5);
^
HINT: Could not choose a best candidate operator. You might need to add
explicit type casts.
Thought?

-----
Regards,
Vinayak,

--
View this message in context: http://postgresql.1045698.n5.nabble.com/operator-tp5817541p5817712.html
Sent from the PostgreSQL - general mailing list archive at Nabble.com.

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Pavel Stehule 2014-09-04 09:20:15 Re: || operator
Previous Message Craig Ringer 2014-09-04 08:38:45 Re: copymanager question