$this->db->distinct() weirdness with PostgreSQL

#1
[eluser]redguy[/eluser]
I was trying to get a distinct list of questions, but the distinct function doesn't work (with PostgreSQL).

The following code:
Code:
$this->db->distinct();
$this->db->get('questions');
Produces duplicate items in the result set. This is because the SQL is:
Code:
SELECT DISTINCT * FROM "questions"
while it should be:
Code:
SELECT DISTINCT ON ("question") * FROM "questions"


See PostgreSQL manual for reference.

The distinct() function only takes a boolean, so supplying the column name doesn't help.

#2
[eluser]Seppo[/eluser]
DISTINCT ON accepts one or multiple field according to the docs... does it accept * too?

I'm asking this because the MySQL behaviour un distinct is removing duplicated rows using all columns and I don't see in the postgre manual if it's valid

#3
[eluser]redguy[/eluser]
Something like:
Code:
SELECT DISTINCT *
FROM questions;

is possible. But that just returns every row, since each row has/should an unique identifier. It's also not SQL compliant. In PostgreSQL you always have to supply at least one column name.


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.