Skip to content

MariaDB: update with order by #131

@oOLooCoreZOo

Description

@oOLooCoreZOo

Hi,

I want to execute the following SQL statements:

SET @cur_pos = 0;
UPDATE table
SET position = (SELECT (@cur_pos := @cur_pos + 1000))
WHERE tableId = 3570
ORDER BY position DESC;
await connection.queryRunner.executeSelectOneRow('SET @cur_pos = 0');
const newPostion = connection.fragmentWithType('int', 'required').sql`(SELECT (@cur_pos := @cur_pos + 1000))`;
const reorder = await connection.update(table)
    .set({
        position: newPostion
    })
    .where(table.tableId.equals(3570))
    .customizeQuery({
        afterQuery: connection.rawFragment`ORDER BY position DESC`
    })
    // .orderBy(table.position)
    .executeUpdate();

ts-sql-query does not support ORDER BY in an update statement.
It would be great if this could be added.
Please see https://mariadb.com/kb/en/update/ for reference.
This only seems to be supported by MySQL and MariaDB.

Do you plan to integrate user defined variables into the API so I can avoid custom SQL?

Best Regards,
Chris

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions