Skip to content

Bug Report: Duplicate ORDER BY causes SQLSTATE\[42000] on SQL Server #590

Open
@phongle8912

Description

@phongle8912

Plugin: RainLab.Blog
OctoberCMS Version: 3.7.12
RainLab.Blog Version: 1.7.1
Database: SQL Server (tested with ODBC Driver 17)


❗ Description

When using the Blog Post Import feature, after uploading the import file, the system throws the following SQL error on Microsoft SQL Server:

SQLSTATE[42000]: [Microsoft][ODBC Driver 17 for SQL Server][SQL Server]A column has been specified more than once in the order by list. Columns in the order by list must be unique.

Generated SQL query (excerpt):

... ORDER BY [sort_order] ASC, [system_files].[sort_order] ASC

This indicates that the query includes sort_order twice in the ORDER BY clause, which is not allowed on SQL Server.


🧪 Steps to Reproduce

  1. Navigate to Blog > Import Posts in the backend.
  2. Upload any valid import file.
  3. Observe the error triggered by duplicate ORDER BY clauses.

📌 Notes

  • This issue does not occur on MySQL, which silently ignores duplicate columns in the ORDER BY clause.
  • Only affects Microsoft SQL Server, which enforces strict uniqueness on column names in ORDER BY.
  • The error likely originates from the internal query used by the attachMany + deferred_bindings relationship in PostImport model.

✅ Suggested Fix

Ensure that ORDER BY clauses generated for file attachments remove duplicate column names when querying deferred bindings.


Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions