30

I find this really weird. If we will look at the major programming languages they all use "||" as logical "or" operator. Is there any (maybe historical) reason why "||" is living in PostgreSQL along with CONCAT() function?

2
  • 5
    PHP, for example, uses dot for string concatenation. The world is full with weird operators. Accept and move on. Commented Mar 4, 2016 at 13:54
  • 6
    It is SQL standard, not only PostgreSQL.
    – Abelisto
    Commented Mar 4, 2016 at 15:02

1 Answer 1

62
-- DB2 / Oracle / Postgres / ANSI Standard
SELECT first_name || ' ' || last_name As full_name FROM customers;
-- Sybase / SQL Server / Microsoft Access
SELECT FirstName + ' ' + LastName As FullName FROM Customers;
-- MySQL
SELECT CONCAT(`FirstName`, ' ', `LastName`) As `FullName` FROM `Customers`;

Double pipe concatenation is part of the ANSI SQL standard. SQL was initially developed at IBM deep in the mainframe era. Most of the "major programming languages" you are thinking of did not exist when SQL was created. Most modern languages are "C like" on some level but FORTRAN77, for example, uses // as it's concatenation operator.

1
  • 1
    Thanks! This is valuable history lesson :)
    – Arius
    Commented Mar 4, 2016 at 22:11

Not the answer you're looking for? Browse other questions tagged or ask your own question.