Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8692555
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T00:20:06+00:00 2026-06-13T00:20:06+00:00

Within Entity Repository: $qb = $this->createQueryBuilder(‘c’); //…. $qb->addSelect(‘POWER(‘.$qb->expr()->abs( $qb->expr()->diff(‘c.latitude’, $filter[‘latitude’]) ).’,2) AS ddst’; //….

  • 0

Within Entity Repository:

$qb = $this->createQueryBuilder('c');
//....
$qb->addSelect('POWER('.$qb->expr()->abs(
                $qb->expr()->diff('c.latitude', $filter['latitude'])
            ).',2) AS ddst';
//....
return $qb->getQuery(); //to Pagerfanta with DoctrineORMAdapter

Errors:

QueryException: [Syntax Error] line 0, col 11: Error: Expected known function, got 'POWER'

QueryException: SELECT c, (POWER(ABS(c.delivery_latitude - 47.227163),2) AS ddst 
FROM MyEntity c ORDER BY ddst ASC, c.created_at DESC (this is dql error)

What’s not right? Dql doesn’t support POWER. I didn’t found it in qb-expressions.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T00:20:07+00:00Added an answer on June 13, 2026 at 12:20 am

    And… Maybe it will be helpfull for someone. Answer:

    //app/config/config.yml
    
    doctrine:
        dbal:
            #.....    
        orm:
            auto_generate_proxy_classes: %kernel.debug%
            # auto_mapping: true #comment this line if isset
            entity_managers:
                default:
                    auto_mapping: true #from orm to here or custom mapping
                    dql:
                        numeric_functions:
                            power: Acme\MyBundle\DQL\PowerFunction #or power_num: ... it's an identifier
    

    src/Acme/MyBundle/DQL/PowerFunction.php:

    <?php
    namespace Acme\MyBundle\DQL;
    
    use Doctrine\ORM\Query\Lexer;
    
    class PowerFunction extends \Doctrine\ORM\Query\AST\Functions\FunctionNode
    {
        public $numberExpression = null;
        public $powerExpression = 1;
    
        public function parse(\Doctrine\ORM\Query\Parser $parser)
        {
            //Check for correct
            $parser->match(Lexer::T_IDENTIFIER);
            $parser->match(Lexer::T_OPEN_PARENTHESIS);
            $this->numberExpression = $parser->ArithmeticPrimary();
            $parser->match(Lexer::T_COMMA);
            $this->powerExpression = $parser->ArithmeticPrimary();
            $parser->match(Lexer::T_CLOSE_PARENTHESIS);
        }
    
        public function getSql(\Doctrine\ORM\Query\SqlWalker $sqlWalker)
        {
            return 'POWER(' .
                $this->numberExpression->dispatch($sqlWalker) . ', ' .
                $this->powerExpression->dispatch($sqlWalker) . ')';
        }
    }
    

    And using (in MyEntityRepository):

    $qb = $this->createQueryBuilder('c');
    //some code
    $qb->addSelect('power('.$yourNumber.',2) AS powered_num');
    //'power' must be in lowercase!!!; if idetifier in config for example, 'power_num', then write 'power_num($yournumber,2)'
    
    //some code ...
    
    return $qb->getQuery(); //or getResult()
    

    done.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Within Dynamics CRM the Lead entity has both a Status and a Status Reason.
Within my code I have list items like this; <div id=content> <ul class=kwicks> <li
I am looking into creating an Entity Framework 4 generic repository for a new
I am having an issue casting an entity to a interface to use within
I am using the entity framework 4 with edmx files and POCOs within an
I have a Project entity that has a set of Word entities within. My
Let me preface this question and state that using Entity Framework is not an
I have a 'Customer' POCO entity within my Entity Framework 4 project. I want
I'm trying to implement a Soft-deletable repository. Usually this can be easily done with
I have a form which is displayed again after it's saved. Within this form

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.