ERROR: for SELECT DISTINCT, ORDER BY expressions must appear in select list

  • Hi


    We just started using new MRI machine today and my db and pacs log is being flooded with this error:

    Code
    ERROR: for SELECT DISTINCT, ORDER BY expressions must appear in select list

    it is caused by this statement (postgres):


    SQL
    SELECT DISTINCT COUNT(1) FROM DICOMStudies WHERE DICOMStudies.PatientNam = E'Jan^Kowalski' and DICOMStudies.PatientID = E'123456789101' and DICOMStudies.Sex = E'M' ORDER BY (DICOMStudies.PatientNam)


    Any idea how to fix this?


    Patryk

  • 1) 1.4.17d

    2) hard to see cause there is a lot going on but I think this was the root cause (I've cut some lines cause there was a study incoming at the same time):

    Code
    20190722 09:36:34 UPACS THREAD 8967: STARTED AT: Mon Jul 22 09:36:34 2019
    20190722 09:36:34 Calling Application Title : "MRC25702 "
    20190722 09:36:34 Called Application Title : "ARPACS1 "
    20190722 09:36:34 Application Context : "1.2.840.10008.3.1.1.1", PDU length: 528378
    20190722 09:36:34 Presentation Context 0 "1.2.840.10008.5.1.4.1.2.1.1" 1
    20190722 09:36:34 (PatientRootQuery) search level: PATIENT
    20190722 09:36:36 *** ERROR: for SELECT DISTINCT, ORDER BY expressions must appear in select list
    20190722 09:36:36 *** ERROR: for SELECT DISTINCT, ORDER BY expressions must appear in select list
    20190722 09:36:36 *** ERROR: for SELECT DISTINCT, ORDER BY expressions must appear in select list

    I also looked at the database log and it turns out it was the empty query (or rather a query with no filters). It was going for few hours before I caught it... was already at letter 'j' :)


    Here is the query which started it all:


    Code
    2019-07-22 09:36:36 127.0.0.1(4345)LOG: duration: 1531.999 ms statement: SELECT DISTINCT DICOMPatients.PatientNam, DICOMPatients.PatientID, DICOMPatients.PatientSex FROM DICOMPatients WHERE DICOMPatients.PatientNam LIKE E'%' and DICOMPatients.PatientID LIKE E'%' ORDER BY (DICOMPatients.PatientNam)


    As you can see - no filters... so it basically asked for ALL 180.000 patients, and then the problems started cause it started asking about each and every one of them with this query:


    Quote

    SELECT DISTINCT COUNT(1) FROM DICOMStudies WHERE DICOMStudies.PatientNam = E'Jan^Kowalski' and DICOMStudies.PatientID = E'123456789101' and DICOMStudies.Sex = E'M' ORDER BY (DICOMStudies.PatientNam)

    producing error each time since this is not a valid query.


    Putting aside the stupid part (lack of filters) this query should still return a valid answer - the number of studies the patient had. It's just that the query itself is wrong

  • sure

  • Hi,


    It is a bug, but if you put something in here it might be fixed:


    PatientQuerySortOrder = PatientID

    StudyQuerySortOrder = StudyDate

    SeriesQuerySortOrder = SeriesDate

    ImageQuerySortOrder = ImageNumber


    Marcel

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!