skinr-ui uses a three-parameter concat function:

    $result = db_select('block', 'b')
      ->fields('b')
      ->distinct()
      ->where('CONCAT(b.module, \'-\', b.delta) = :identifier', array(':identifier' => $form['skinr']['sid']['#value']))
      ->range(0, 1)
      ->execute();

Now, it would be possible to hop on over to the skinr queue and ask them to split the form value and do a two-clause where instead; however, as a postgres user, this seems sort of like an uphill battle. Unless Drupal is going to forbid three-parameter CONCAT functions (and how would that policy be communicated?), it seems better to support this in core so that we don't have to keep chasing these down whenever they pop up.

The attached patch defines an update function and modifies the pgsql install function to define a new three-argument CONCAT function. Using anynonarray for all three parameters rather than trying to hit all permutations of text and anynonarray seems preferable, and works in the current instance.

To reproduce: On a Drupal-7 install using postgres, install and enable skinr and skinr-ui with some theme that uses it (fusion-starter is good). Mouse over the "configure" widget and select "edit skin". Without this patch, you get the following error:

PDOException: SQLSTATE[42883]: Undefined function: 7 ERROR: function concat(character varying, unknown, character varying) does not exist LINE 4: WHERE (CONCAT(b.module, '-', b.delta) = 'search-form') ^ HINT: No function matches the given name and argument types. You might need to add explicit type casts.: SELECT DISTINCT b.* FROM {block} b WHERE (CONCAT(b.module, '-', b.delta) = :identifier) LIMIT 1 OFFSET 0; Array ( [:identifier] => search-form ) in block_skinr_preprocess_hook_callback() (line 94 of /srv/www/d7.com/sites/all/modules/skinr/modules/block.skinr.inc).

Apply this patch and run updatedb, and the above operation works fine (edit skin dialog is displayed).

Workaround: Waiting for this patch to land? Change your working directory to your site's configuration folder (containing settings.php) and run the following drush command:

drush sqlq "CREATE OR REPLACE FUNCTION \"concat\"(anynonarray, anynonarray, anynonarray) RETURNS text AS 'SELECT CAST(\$1 AS text) || CAST(\$2 AS text) || CAST(\$3 AS text);' LANGUAGE 'sql';"

This has the same affect as the attached patch, but of course is temporary in nature (must be done once per d7 site). Workaround does not cause problems with the update script in this patch.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

greg.1.anderson’s picture

Added #1073108: Use of three-parameter concat function is bad for postgres compatibility to skinr queue for documentation / fallback.

Note also that the above simpletest pass was done on MySQL only, which this patch does not affect (good that the test passed to confirm this!). Seems like the postgres automated tests have been broken for a while.

Crell’s picture

Category: bug » feature

This would be a feature request, not a bug report, I think. We don't make any claims currently to support SQL functions in a portable fashion.

Is 3-part-concat currently supported in both MySQL and SQLite? If we're going to try and support it, it would have to be consistently supported across all core databases. I'm not sure what the implications would be for the contrib drivers, either.

DamZ's input would be helpful here.

chx’s picture

Title: Add a three-parameter concat function to pgsql for skinr-ui » Figure out what to do with string concats
Version: 7.x-dev » 8.x-dev
Category: feature » task
Status: Needs review » Active

Well, almost every database we support core or contrib uses || (MySQL in ANSI mode too and we run in ANSI). The exception is MS SQL and there does not seem to be an in-database, cross-database solution. Do we want to add a concat class with a __toString?

Liam Morland’s picture

Issue tags: +PostgreSQL
jaredsmith’s picture

Status: Active » Needs review
FileSize
2.03 KB

I've made a patch that handles concat with three arguments. If you'd like, I'd be happy to extend the patch to cover cases of four, five, and even six arguments if there's a use for it.

jaredsmith’s picture

Attached is a more complete patch, which covers three, four, and five arguments.

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

jhedstrom’s picture

Version: 8.1.x-dev » 8.2.x-dev
Status: Needs review » Postponed (maintainer needs more info)
Issue tags: +Needs reroll, +Needs issue summary update

This needs an updated patch, as well as an IS update since it's been so long and the examples are about D7.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.0-beta1 was released on August 3, 2016, which means new developments and disruptive changes should now be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.0-alpha1 will be released the week of January 30, 2017, which means new developments and disruptive changes should now be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.0-alpha1 will be released the week of July 31, 2017, which means new developments and disruptive changes should now be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.0-alpha1 will be released the week of January 17, 2018, which means new developments and disruptive changes should now be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.6.x-dev » 8.7.x-dev

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Percy101’s picture

Percy101’s picture

I am sorry but the above reroll and this one has the same content. But the above reroll that is in comment number 17 does not follow the right nomenclature.

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

quietone’s picture

Issue tags: -Needs review

Cleaning up tags.

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.