Questions tagged [concat]

In formal language theory and computer programming, string concatenation is the operation of joining two character strings end-to-end

In formal language theory and computer programming, string concatenation is the operation of joining two character strings end-to-end. For example, the concatenation of snow and ball is snowball.

In many programming languages, string concatenation is a binary infix operator. The + operator is often overloaded to denote concatenation for string arguments: "Hello, " + "World"; has the value "Hello, World".

Comparison of different SQL implementations on CONCATENATION

Standard     Core feature ID E021-07:
             Concatenating two strings is done with the || operator:
             string1 || string2
             If at least one operand is NULL, then the result is NULL.


PostgreSQL   Follows the standard.
             Automatically casts the concatenated values into types compatible with concatenation. If an operand is NULL then the result is NULL.


DB2         Follows the standard, partly.
            Does not automatically cast concatenated values into compatible types.


MSSQL    Breaks the standard by using the '+' operator instead of '||'.
          Does not automatically cast operands to compatible types. If an operand is NULL, then the result is NULL.


MySQL    Badly breaks the standard by redefining || to mean OR.
         Offers instead a function, CONCAT(string, string), which accepts two or more arguments.
         Automatically casts values into types which can be concatenated. If an operand is NULL, then the result is NULL.


Oracle   Follows the standard, partly.
         Automatically casts values into types which can be concatenated.    
         As Oracle interprets NULL as the empty string, it doesn't return NULL if an operand is NULL.


Informix    Follows the standard.
         Automatically casts numeric data into character data, if needed. If an operand is NULL then the result is NULL.
74 questions
36
votes
2 answers

'CONCAT' is not a recognized built-in function name

A client reported that they were running on SQL Server 2012, and we delivered some test queries for testing prior to a final delivery, however: 'CONCAT' is not a recognized built-in function name. I understand that CONCAT() is a new built-in…
beeks
  • 1,251
  • 1
  • 8
  • 15
26
votes
4 answers

How to exclude NULL values inside CONCAT MySQL?

If I have this - tadd is the Address table: CONCAT(tadd.street_number, ' ', tadd.street_name,', ', tadd.apt_number,', ', tadd.city,', ', tadd.postal_code,', ', tadd.country) AS…
ed-ta
  • 463
  • 2
  • 6
  • 10
23
votes
1 answer

Is "+" slower than "CONCAT" for large strings?

I have always thought that CONCAT function is actually a wrapper over the + (String Concatenation) with some additional checks in order to make our life more easier. I have not found any internal details about how the functions are implemented. As…
gotqn
  • 4,348
  • 11
  • 52
  • 91
20
votes
2 answers

Why does Concatenation operator estimate fewer rows than its inputs?

In the following query plan snippet, it seems obvious that the row estimate for the Concatenation operator should be ~4.3 billion rows, or the sum of the row estimates for its two inputs. However, an estimate of~238 million rows is produced, leading…
13
votes
1 answer

How to append value of column with double quotes (add quotes around string)

I have a table with a column that is TEXT type. In the column are numeric characters. What I'm trying to achieve is to wrap those characters in double quotes. EXAMPLE: NAME ID QTY Apples A1 1 Oranges O1 1 Foo F1 0 IDEAL…
Bard
  • 133
  • 1
  • 1
  • 6
13
votes
2 answers

Conditional string concatenation in PostgreSQL

I have a table parcels which currently contains the columns owner_addr1, owner_addr2, owner_addr3. Sometimes, one or both of the latter two fields is empty. I want to combine them into a single new field, owner_addr where each of the above fields is…
J. Taylor
  • 379
  • 2
  • 5
  • 17
11
votes
2 answers

What is the most efficient way to concatenate strings in SQL Server?

I have this code: DECLARE @MyTable AS TABLE ( [Month] INT, Salary INT ); INSERT INTO @MyTable VALUES (1,2000), (1,3100); SELECT [Month], Salary FROM @MyTable; Output: I want to concat the Salary (grouping by month) so that it will be…
Misha Zaslavsky
  • 499
  • 2
  • 8
  • 17
9
votes
2 answers

Returning empty string when string_agg has no records

I am trying to return a text field in a PostgreSQL query that is of the form 'stringOne' || string_agg(field, ',') || 'stringTwo' where for certain elements in the group clause, field is always null. I want, and expect, to end up with…
Michael Underwood
  • 385
  • 1
  • 3
  • 10
8
votes
2 answers

NULL value causes blank row in SELECT results for text concatenation

I have a query for producing some text for creating some VALUES text to put in a .sql file for inserting some rows. I get a blank line in the results: postgres=# SELECT ' (' || obj_id || ', ''' || obj_type || '''),' FROM il2.objects WHERE obj_id <…
Randall
  • 385
  • 5
  • 18
8
votes
2 answers

SQL Row concatenation with XML PATH and STUFF giving aggregate sql error

I am trying to query two tables and get results like the following: Section Names shoes AccountName1, AccountName2, AccountName3 books AccountName1 The tables are: CREATE TABLE dbo.TableA(ID INT, Section varchar(64), AccountId…
B.McCarthy
  • 83
  • 1
  • 1
  • 3
7
votes
1 answer

Avoiding entitized characters when using FOR XML PATH for string concatenation

I have this query: SELECT DISTINCT f1.CourseEventKey, STUFF ( ( SELECT '; ' + Title FROM ( SELECT DISTINCT ces.CourseEventKey, …
keeehlan
  • 173
  • 1
  • 1
  • 5
5
votes
1 answer

How to concatenate two column of different types in sql? (without getting some strange warning)

When I try to concatenate two columns, of different type, I get the following warning: Type conversion in the expression (CONVERT_IMPLICIT(varchar(41), [TABLE].[COLUMN], 0)) can affect "CardinalityEstimate" in choosing query plan. By doing a…
G. Ciardini
  • 153
  • 5
4
votes
1 answer

Syntax error with concat in trigger near signal statement

Please help me with syntax for MySQL 5.6. For some reason I get the error: ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '('WRONG SOCIAL:…
Alexander Farber
  • 405
  • 3
  • 7
  • 19
3
votes
3 answers

How to find data type of output in MySQL?

I was reading about the CONCAT() function, and I noticed this: mysql> SELECT CONCAT(14.3); -> '14.3' While running this command in MySQL 8.0 Command Line Client, the output didn't have quotes. So I wanted to verify the data type of the…
Random Person
  • 157
  • 1
  • 7
3
votes
3 answers

Why does the concatenation order change with a User-Defined Table Type?

I've encountered what seems to me to be a strange ordering issue when using CONCAT with a User Defined Table Type. I've put the SQL below that allows me to reproduce this: I have the following user type: CREATE TYPE [dbo].[StringList] AS TABLE ( …
Interminable
  • 181
  • 5
1
2 3 4 5