Database-independent SQL String Concatenation in Rails

后端 未结 3 1760
难免孤独
难免孤独 2020-12-10 04:03

I want to do a database-side string concatenation in a Rails query, and do it in database-independent way.

SQL-92 specifies double-bar (||) as the conca

3条回答
  •  暖寄归人
    2020-12-10 04:25

    If you want something Rails neutral, you're going to need to return the values you want concatenated and do that once the data has been delivered to rails (or do it in rails before you give it to the database).

    It looks like Mysql uses CONCAT(), Postgres ||, Oracle CONCAT() or ||, T-SQL +.

    Any rails abstraction of the same would have to take place at a point where you could just be doing concatenation using regular Ruby, or I've completely misunderstood the question.

提交回复
热议问题