Closed (fixed)
Project:
Drupal core
Version:
7.x-dev
Component:
database system
Priority:
Major
Category:
Bug report
Assigned:
Unassigned
Issue tags:
Reporter:
Created:
26 May 2010 at 10:00 UTC
Updated:
22 Jul 2010 at 11:51 UTC
Jump to comment: Most recent file
Comments
Comment #1
damien tournoud commentedComment #2
Crell commentedIf CONCAT() is part of ANSI SQL, sounds fine to me. It should be added to the handbook page.
Perhaps we should consider adding a link from the main docblock for the DB layer to the handbook page when it's more fleshed out.
Comment #3
lambic commentedAs far as I know, all Oracle platforms support ||
CONCAT() doesn't exist in PostgreSQL, but you could write your own.
Comment #4
hshana commented|| is the ANSI SQL standard and is supported by everything but MSSQL. (Shocker, I know.) http://en.wikibooks.org/wiki/SQL_Dialects_Reference/Functions_and_expres...
Comment #5
damien tournoud commentedOther then documentation, I think we need something like this.
Comment #6
Crell commentedHm. What about hshana's point in #4? I'd rather go with "ANSI and supported by the core DBs and some others" than "not-ANSI and supported by the core DB and some others", for different "others".
Comment #7
damien tournoud commented@Crell: CONCAT() is easily supported in all the databases. || is not supported (and *impossible to support*) in a least two databases: SQL Server and Drizzle.
Sounds like a no-brainer to me.
Comment #8
bojanz commentedWhat about #3?
Since CONCAT() doesn't work in PostgreSQL, we'd need to create our own (like here)
Comment #9
damien tournoud commented@bojanz:
CONCAT()has been the standard way of concatenating strings for years in any version of Drupal < 7. We already have a compatibility CONCAT() function in PostgreSQL and SQLite.Comment #10
bojanz commentedGood to know, thanks for clearing it up.
Comment #12
Crell commentedOK, that makes sense. Thanks, DamZ. +1 on #5 then.
Do we know that any other databases we may want to support can be made to handle CONCAT() the way we do with Postgres?
Comment #13
chx commentedWow. just wow. Dont we all love standards...
Comment #14
Crell commentedSQL--
That's all I have to say.
Comment #15
tstoecklerTwo instances of "ANSI" left in the function descriptions.
Since test bot will test RTBC patches, leaving there.
Comment #16
dries commentedCommitted to CVS HEAD. Thanks.
Comment #17
damien tournoud commentedCan we get some help from the documentation team in documenting that?
Comment #18
catchComment #19
josh waihi commentedJust installed HEAD on PostgreSQL 8.3 and test failed:
Here is our existing code:
The problem is for every argument data type you can pass to CONCAT you need to specify another function. Ugly.
Comment #20
chx commentedHardly. You just need to add casts.
Comment #21
damien tournoud commentedThis bug was known, the new test only exposed it.
This should do it:
(yes, we need three functions, because all
anynonarraymust be of the same type when a polymorphic functions is called in PostgreSQL)Comment #22
dave reidI have given up on using CONCAT() in SQL. I honestly think we need some kind of $query->concat() function that will return the proper concatenation SQL for each database driver. See #319070: Provide a wrapper for cross-db and cross-field-type concatenation (PosgreSQL).
Comment #23
josh waihi commentedLast I checked, Crell was against smaller functions like that, though personally, I'm for it.
Comment #24
bellHead commentedHow many of the situations where CONCAT() is used can't be designed around? Looking at the bug issues involving it, I get the feeling that most can.
Most of the CAST() issues are related to the use of CONACT() too, so trying to move away from its use would reduce or eliminate two of the big areas of database compatibility problems.
I think that any documentation on this issue should suggest in strong terms you need to think hard, at least twice, before deciding that CONCAT() and therefore probably CAST() are part of the solution to your problem.
Comment #25
damien tournoud commentedI think we can design a type-insensitive CONCAT() in all the databases we support.
Comment #26
chx commentedDocument that SQL strings cant use concat, add a concat to mapConditionOperator and live happily ever after.
Comment #27
Crell commentedI don't think mapConditionOperator can handle concat in its current form. That's not really what it's there for.
Comment #28
damien tournoud commentedWhat we need is being able to replace
a || bby something as complex asCAST(a AS text) + CAST(b AS text). Could we use mapConditionOperator() for that?Comment #29
josh waihi commentedregex for drivers who don't support ||?
Comment #30
josh waihi commentedregex for drivers who don't support ||?
Comment #31
chx commentedstring parsing is not a solution. Damien is right -- we might need a separate concat method :(
Comment #32
damien tournoud commentedJosh, do you really believe that you can parse a random SQL expression with a regexp? Remember that there might be *anything* on both sides of the operator, and that you have to take into account precedence rules.
Comment #33
josh waihi commentedNo, I don't think REGEX are a good solution for SQL. But I knew it would stir people up! ;)
DamZ solution seems reasonable to me. 3 CONCAT functions. If it makes 'Basic SQL syntax tests" pass without an exception then I'm happy.
Comment #34
Crell commentedSo to summarize then:
1) Document that || is verbotten.
2) We need a new patch that makes all 3 variants of Concat() for Postgres. Who's doing that one?
3) Do we need anything for SQLite?
Comment #35
josh waihi commentedAttached is PostgreSQL funcs. Have tested and they work.
Comment #36
chx commentedMySQL CONCAT takes any number of parameters -- but then I guess we can document that plz do not use such CONCAT (good luck with people keeping that one...)
Comment #37
damien tournoud commented@chx: I already documented (as a stub) that only CONCAT(string1, string2) is supported in the list of functions and operators wie support.
Comment #38
Stevel commentedThe concat(text, text) function is already created several lines before the place where this patch is applied, so we are creating/replacing the function twice for the (text, text) arguments.
Also, in HEAD the patch applied with an offset of 32 lines.
Comment #39
damien tournoud commentedI guess this foreach needs to read "for each" too.
Comment #40
chx commentedMy opinion in the patch name but meh.
Comment #41
damien tournoud commentedTested #40 on Postgresql 8.3, works as intended (which is weird because generally on PostgreSQL nothing works the way you would expect them to).
Comment #42
damien tournoud commentedNote: SQLite is not affected, so with this patch the "Basic SQL" test passes on every database we support.
Comment #43
webchickAgreed, they're not critical. Where is that major priority anyway? :(
Committed to HEAD all the same, though.
Comment #44
yesct commented:)
Comment #46
mustanggb commented