Skip to content
Advertisement

Column concatenation in Order by expression. Is it wrong?

What are pros and cons whether I use Order by expression like this:

select * from table1
order by column1 || column2 || column3 || column4

or in this way:

select * from table1
order by column1, column2, column3, column4

How each one does impact on performance?

Advertisement

Answer

The concatenation is unnecessary and may produce incorrect results. For instance, consider these values:

abc       a     b     c
ab        d     e     f

The concatenation will put the first row first. By individual keys, it will put the second one first.

It can slow down the order by, if the order by can make use of indexes.

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement