KnpLabs / KnpLabs/KnpPaginatorBundle

Random postgresql ?

Open
#654 18 comments 0 reactions 0 assignees View on GitHub
Help user Waiting for user's input
Dominant language
PHP
Stars
1.8k
Forks
332
Avg merge
1d 1h
Merged PRs (30d)
3

Description

Hi i have create DQL Function Random in postgresql but not work

```
match(Lexer::T_IDENTIFIER);
$parser->match(Lexer::T_OPEN_PARENTHESIS);
$parser->match(Lexer::T_CLOSE_PARENTHESIS);
}

public function getSql(SqlWalker $sqlWalker)
{
return 'RANDOM()';
}
}
```

```
dql:
numeric_functions:
Random: App\DQL\RandomFunction
```
```
$qb->orderBy('RANDOM()');
```

But got error
Invalid column reference: 7 ERROR: for SELECT DISTINCT, ORDER BY expressions must appear in select list

i have test
```
public function test(){
return $this->createQueryBuilder('q')->select('q.id')->orderBy('RANDOM()')->setMaxResults(5)->getQuery()->getResult();
}
```

And it works but with paginator no

Thanks for your help

Contributor guide

Open the contributing guide

Research direction

Start with the shown test() query and compare its direct execution with the paginator path, focusing on the PostgreSQL DISTINCT and ORDER BY interaction. Reproduce the failure using the Random DQL function and paginator, then add a regression test showing that random ordering works with pagination without triggering the invalid column reference.

Written by the indexing model from the issue text.

Assessment

Tech stack
php, postgresql, symfony
Domain
backend, databases
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.