diff options
author | Angie Byron <webchick@24967.no-reply.drupal.org> | 2010-06-21 01:32:21 +0000 |
---|---|---|
committer | Angie Byron <webchick@24967.no-reply.drupal.org> | 2010-06-21 01:32:21 +0000 |
commit | 605362393ddef1472d25705647326002b68992d5 (patch) | |
tree | 99cd4ed36eeb974e27c77389dc9f6845b8527447 /includes/database/pgsql | |
parent | 3cca50da4495b15f7454f55fefc19d917759d038 (diff) | |
download | brdo-605362393ddef1472d25705647326002b68992d5.tar.gz brdo-605362393ddef1472d25705647326002b68992d5.tar.bz2 |
#809698 follow-up by Damien Tournoud, Josh Waihi, chx: Add CONCAT() function to PostgreSQL since || isn't supported reliably across database systems.
Diffstat (limited to 'includes/database/pgsql')
-rw-r--r-- | includes/database/pgsql/install.inc | 31 |
1 files changed, 23 insertions, 8 deletions
diff --git a/includes/database/pgsql/install.inc b/includes/database/pgsql/install.inc index e953b91e8..bfd69d414 100644 --- a/includes/database/pgsql/install.inc +++ b/includes/database/pgsql/install.inc @@ -109,18 +109,33 @@ class DatabaseTasks_pgsql extends DatabaseTasks { ); } - // Don't use {} around pg_proc table. - if (!db_query("SELECT COUNT(*) FROM pg_proc WHERE proname = 'concat'")->fetchField()) { - db_query('CREATE OR REPLACE FUNCTION "concat"(text, text) RETURNS text AS - \'SELECT $1 || $2;\' - LANGUAGE \'sql\'' - ); - } - db_query('CREATE OR REPLACE FUNCTION "substring_index"(text, text, integer) RETURNS text AS \'SELECT array_to_string((string_to_array($1, $2)) [1:$3], $2);\' LANGUAGE \'sql\'' ); + + // Using || to concatenate in Drupal is not recommeneded because there are + // database drivers for Drupal that do not support the syntax, however + // they do support CONCAT(item1, item2) which we can replicate in + // PostgreSQL. PostgreSQL requires the function to be defined for each + // different argument variation the function can handle. + db_query('CREATE OR REPLACE FUNCTION "concat"(anynonarray, anynonarray) RETURNS text AS + \'SELECT CAST($1 AS text) || CAST($2 AS text);\' + LANGUAGE \'sql\' + '); + db_query('CREATE OR REPLACE FUNCTION "concat"(text, anynonarray) RETURNS text AS + \'SELECT $1 || CAST($2 AS text);\' + LANGUAGE \'sql\' + '); + db_query('CREATE OR REPLACE FUNCTION "concat"(anynonarray, text) RETURNS text AS + \'SELECT CAST($1 AS text) || $2;\' + LANGUAGE \'sql\' + '); + db_query('CREATE OR REPLACE FUNCTION "concat"(text, text) RETURNS text AS + \'SELECT $1 || $2;\' + LANGUAGE \'sql\' + '); + $this->pass(st('PostgreSQL has initialized itself.')); } catch (Exception $e) { |