Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PostgreSQL query inconsistency

I am trying to execute this SQL command:

SELECT page.page_namespace, pagelinks.pl_namespace, COUNT(*) 
    FROM page, pagelinks
    WHERE 
        (page.page_namespace <=3 OR page.page_namespace = 12 
            OR page.page_namespace = 13
        ) 
        AND 
        (pagelinks.pl_namespace <=3 OR pagelinks.pl_namespace = 12 
            OR pagelinks.pl_namespace = 13
        )
        AND 
        (page.page_is_redirect = 0)
        AND 
        pagelinks.pl_from = page.page_id 
    GROUP BY (page.page_namespace, pagelinks.pl_namespace) 
; 

When I do so, I get the following error:

    ERROR:  could not identify an ordering operator for type record
    HINT:  Use an explicit ordering operator or modify the query.

    ********** Error **********

    ERROR: could not identify an ordering operator for type record
    SQL state: 42883
    Hint: Use an explicit ordering operator or modify the query.

I have tried adding : ORDER BY (page.page_namespace, pagelinks.pl_namespace) ASC to the end of the query without success.

UPDATE:

I also tried this:

SELECT page.page_namespace, pagelinks.pl_namespace, COUNT(*) 
    FROM page, pagelinks
    WHERE pagelinks.pl_from = page.page_id 
    GROUP BY (page.page_namespace, pagelinks.pl_namespace) 
; 

But I still get the same error.

Thx

like image 372
Nicholas Leonard Avatar asked Feb 05 '26 09:02

Nicholas Leonard


1 Answers

I haven't checked any documentation but the fact that you have your GROUP BY expression in parentheses looks unusual to me. What happens if you don't use parentheses here?

like image 120
Adrian Pronk Avatar answered Feb 08 '26 05:02

Adrian Pronk