Thread: What is || doing

What is || doing

From
Frank Lanitz
Date:
Hi list,

I've got an query which contains || inside the select statement and I'm
not sure, what this is doing. Can you help me out a bit or send me a
link to documentation where I can find this?

Example:

SELECT 'ba_'|| foo || '_pr_'
FROM 'foobaa'
WHERE id=1234;

Cheers,
Frank

Re: What is || doing

From
Thom Brown
Date:
On 27 June 2011 13:59, Frank Lanitz <frank@frank.uvena.de> wrote:
> Hi list,
>
> I've got an query which contains || inside the select statement and I'm
> not sure, what this is doing. Can you help me out a bit or send me a
> link to documentation where I can find this?
>
> Example:
>
> SELECT 'ba_'|| foo || '_pr_'
> FROM 'foobaa'
> WHERE id=1234;

|| in PostgreSQL is a concatenation operator.  It's equivalent to + in
Microsoft SQL Server, or concat() in MySQL.

So if foo = 'hello', the output of that select would be 'ba_hello_pr_'

See http://www.postgresql.org/docs/current/static/functions-string.html

Regards

Thom Brown
Twitter: @darkixion
IRC (freenode): dark_ixion
Registered Linux user: #516935

EnterpriseDB UK: http://www.enterprisedb.com
The Enterprise PostgreSQL Company

Re: What is || doing

From
"Jean-Yves F. Barbier"
Date:
On Mon, 27 Jun 2011 14:59:30 +0200, Frank Lanitz <frank@frank.uvena.de> wrote:


This is a concatenation operator; in this case 'ba_' is assembled with var foo
and '_pr_'.
eg: if foo = 'by', the resulting string is: 'ba_by_pr_'.

> SELECT 'ba_'|| foo || '_pr_'

--
Honest, officer, had I known my health was in jeopardy, why, I'd never have
lit one!

Re: What is || doing

From
Frank Lanitz
Date:
Am 27.06.2011 15:13, schrieb Jean-Yves F. Barbier:
> On Mon, 27 Jun 2011 14:59:30 +0200, Frank Lanitz <frank@frank.uvena.de> wrote:
>
>
> This is a concatenation operator; in this case 'ba_' is assembled with var foo
> and '_pr_'.
> eg: if foo = 'by', the resulting string is: 'ba_by_pr_'.

Coo, thanks very much ;)
Was looking inside index etc and didn't find any hint :(

Cheers,
Frank

Re: What is || doing

From
Tim Landscheidt
Date:
Frank Lanitz <frank@frank.uvena.de> wrote:

> I've got an query which contains || inside the select statement and I'm
> not sure, what this is doing. Can you help me out a bit or send me a
> link to documentation where I can find this?

> Example:

> SELECT 'ba_'|| foo || '_pr_'
> FROM 'foobaa'
> WHERE id=1234;

It's a string concatenation, cf.
<URI:http://www.postgresql.org/docs/current/interactive/functions-string.html>.

Tim