diff options
Diffstat (limited to 'includes/database/pgsql/install.inc')
-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 e953b91e86d8..bfd69d414429 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) { |