Skip to content
Advertisement

PostgreSQL – repeating rows from LIMIT OFFSET

I noticed some repeating rows in a paginated recordset.

When I run this query:

I get:

Next query:

I get:

Why does “foo” appear in both queries?

Advertisement

Answer

Why does “foo” appear in both queries?

Because all rows that are returned have the same value for the status column. In that case the database is free to return the rows in any order it wants.

If you want a reproducable ordering you need to add a second column to your order by statement to make it consistent. E.g. the ID column:

If two rows have the same value for the status column, they will be sorted by the id.

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement