catfan / Medoo

The lightweight PHP database framework to accelerate the development.
https://medoo.in
MIT License
4.84k stars 1.15k forks source link

PostgreSQL LIMIT with OFFSET fails #796

Closed jerrac closed 6 years ago

jerrac commented 6 years ago

Describe the bug When trying to limit a select query, and using an offset, the limit is just left off the query entirely.

Information

Detail Code $this->db is from new Medoo(...);.

$offset = 0;
$size = 100;
 $get = $this->db->select('actions_data',
                  ['id', 'action', 'udcid', 'field', 'value', 'created'],
                  ['LIMIT' => [$offset, $size]]
                );

Using xdebug, I can tell the sql statement is:

SELECT "id","action","udcid","field","value","created" FROM "actions_data"

Expected output I expect a result with 100, or fewer, results.

The query should have looked like:

SELECT "id","action","udcid","field","value","created" FROM "actions_data" LIMIT 100 OFFSET 0;

The $offset value changes based on the results of a loop that processes each returned row.

What I get is all 1.8 million rows in my database table.

jerrac commented 6 years ago

Never mind. If found some code before my select call if(empty($offset)) can evaluate to true when $offset = 0... Inside that if statement, I was selecting all rows.