Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add random() order support #16964

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open

Add random() order support #16964

wants to merge 3 commits into from

Conversation

sebastienros
Copy link
Member

Fixes #16961

var id = idList.ChildNodes[i].ChildNodes[0];

// RANDOM() is a special case where we need to use the dialect's random function.
if (id.ChildNodes[0].Token?.ValueString == "RANDOM")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could work in SQLite & Postgres only, RAND is the one that works in SQL Server and MySQL

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

_builder.Append(_dialect.RandomOrderByClause);

But maybe you forgot how sql queries are managed in this feature. Call me if you want a quick refresher.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I revisited YesSQL and after I looked to _dialect.RandomOrderByClause it's fine for me

if (funArgs.Term.Name == "funArgs" && funArgs.ChildNodes.Count == 0)
{
_builder.Append(_dialect.RandomOrderByClause);
continue;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
continue;
continue;

Comment on lines +254 to +256
var result = SqlParser.TryParse(sql, _schema, _defaultDialect, _defaultTablePrefix, null, out var rawQuery, out var errors);
Assert.True(result);
Assert.Equal(expectedSql, FormatSql(rawQuery));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
var result = SqlParser.TryParse(sql, _schema, _defaultDialect, _defaultTablePrefix, null, out var rawQuery, out var errors);
Assert.True(result);
Assert.Equal(expectedSql, FormatSql(rawQuery));
// Arrange & Act
var result = SqlParser.TryParse(sql, _schema, _defaultDialect, _defaultTablePrefix, null, out var rawQuery, out var errors);
// Assert
Assert.True(result);
Assert.Equal(expectedSql, FormatSql(rawQuery));

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

SQL Query fails with "ORDER BY random()"
2 participants