Skip to content

[5.x]: invalid input syntax for type integer when ordering by score #14761

@tommysvr

Description

@tommysvr

What happened?

Description

Ordering by score on Postgres results in this error:

PDOException: SQLSTATE[22P02]: Invalid text representation: 7 ERROR:  invalid input syntax for type integer: "2-1"
CONTEXT:  unnamed portal parameter $6 = '...' in /var/www/html/vendor/yiisoft/yii2/db/Command.php:1302

Steps to reproduce

This query will result in the error:
{% set entries = craft.entries().search('keyword').orderBy('score').all() %}

Ordering with another param works:
{% set entries = craft.entries().search('keyword').orderBy('postDate desc').all() %}

Expected behavior

Able to order by score

Actual behavior

Errors as above

PDOException: SQLSTATE[22P02]: Invalid text representation: 7 ERROR:  invalid input syntax for type integer: "2-1"
CONTEXT:  unnamed portal parameter $6 = '...' in /var/www/html/vendor/yiisoft/yii2/db/Command.php:1302
Stack trace:
#0 /var/www/html/vendor/yiisoft/yii2/db/Command.php(1302): PDOStatement->execute()
#1 /var/www/html/vendor/yiisoft/yii2/db/Command.php(1168): yii\db\Command->internalExecute('SELECT "element...')
#2 /var/www/html/vendor/yiisoft/yii2/db/Command.php(410): yii\db\Command->queryInternal('fetchAll', NULL)
#3 /var/www/html/vendor/yiisoft/yii2/db/Query.php(249): yii\db\Command->queryAll()
#4 /var/www/html/vendor/craftcms/cms/src/db/Query.php(247): yii\db\Query->all(NULL)
#5 /var/www/html/vendor/craftcms/cms/src/elements/db/ElementQuery.php(1785): craft\db\Query->all(NULL)
#6 /var/www/html/vendor/twig/twig/src/Extension/CoreExtension.php(1635): craft\elements\db\ElementQuery->all()
#7 /var/www/html/vendor/craftcms/cms/src/helpers/Template.php(129): twig_get_attribute(Object(craft\web\twig\Environment), Object(Twig\Source), Object(craft\elements\db\EntryQuery), 'all', Array, 'method', false, false)
#8 /var/www/html/storage/runtime/compiled_templates/ce/cea1e557c1dcdeb194b01b7046507dff.php(42): craft\helpers\Template::attribute(Object(craft\web\twig\Environment), Object(Twig\Source), Object(craft\elements\db\EntryQuery), 'all', Array, 'method')
#9 /var/www/html/vendor/twig/twig/src/Template.php(394): __TwigTemplate_a1929ddd56b506b5cdbb107f1c8a4d7e->doDisplay(Array, Array)
#10 /var/www/html/vendor/twig/twig/src/Template.php(367): Twig\Template->displayWithErrorHandling(Array, Array)
#11 /var/www/html/vendor/twig/twig/src/Template.php(379): Twig\Template->display(Array)
#12 /var/www/html/vendor/twig/twig/src/TemplateWrapper.php(38): Twig\Template->render(Array)
#13 /var/www/html/vendor/twig/twig/src/Environment.php(280): Twig\TemplateWrapper->render(Array)
#14 /var/www/html/vendor/craftcms/cms/src/web/View.php(482): Twig\Environment->render('', Array)
#15 /var/www/html/vendor/craftcms/cms/src/web/View.php(535): craft\web\View->renderTemplate('', Array)
#16 /var/www/html/vendor/craftcms/cms/src/web/TemplateResponseFormatter.php(57): craft\web\View->renderPageTemplate('', Array, 'site')
#17 /var/www/html/vendor/yiisoft/yii2/web/Response.php(1100): craft\web\TemplateResponseFormatter->format(Object(craft\web\Response))
#18 /var/www/html/vendor/craftcms/cms/src/web/Response.php(337): yii\web\Response->prepare()
#19 /var/www/html/vendor/yiisoft/yii2/web/Response.php(340): craft\web\Response->prepare()
#20 /var/www/html/vendor/yiisoft/yii2/base/Application.php(390): yii\web\Response->send()
#21 /var/www/html/web/index.php(12): yii\base\Application->run()
#22 {main}

Craft CMS version

5.0.1

PHP version

8.2

Operating system and version

No response

Database type and version

PostgreSQL 14/15/16

Image driver and version

No response

Installed plugins and versions

No response

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions