Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQLite with skip (offset) only (not limit)

Tags:

sqlite

offset

I am trying to query a sql lite database with only an offset and no limit.

SELECT [Id], [Name], [IntValue], [IntNulableValue] FROM [Product] OFFSET 10 

I can do an offset query when I have a limit however (LIMIT 10 OFFSET 10).

Here is the error sql lite is giving me.

SQLite error near "10": syntax error 
like image 951
Paul Knopf Avatar asked May 08 '12 01:05

Paul Knopf


People also ask

Does SQLite support offset?

SQLite Limit:In the LIMIT clause, you can select a specific number of rows starting from a specific position using the OFFSET clause. For example, “LIMIT 4 OFFSET 4” will ignore the first 4 rows, and returned 4 rows starting from the fifth rows, so you will get rows 5,6,7, and 8.

Does SQLite support limit?

Maximum Database SizeThe maximum size of a database file is 4294967294 pages. At the maximum page size of 65536 bytes, this translates into a maximum database size of approximately 1.4e+14 bytes (281 terabytes, or 256 tebibytes, or 281474 gigabytes or 256,000 gibibytes).

How do I limit the number of rows returned?

You use the LIMIT clause to constrain the number of rows returned by the query. For example, a SELECT statement may return one million rows. However, if you just need the first 10 rows in the result set, you can add the LIMIT clause to the SELECT statement to retrieve 10 rows.

What is offset limit?

The OFFSET LIMIT clause is an optional clause to skip then take some number of values from the query. The OFFSET count and the LIMIT count are required in the OFFSET LIMIT clause. When OFFSET LIMIT is used in conjunction with an ORDER BY clause, the result set is produced by doing skip and take on the ordered values.


2 Answers

Just set LIMIT to -1.

For example:

SELECT * FROM table LIMIT -1 OFFSET 10 
like image 110
Ming-Hong Bai Avatar answered Sep 29 '22 15:09

Ming-Hong Bai


On the SQL as understood by SQLite page, you'll notice that OFFSET isn't understood without LIMIT.

http://sqlite.org/lang_select.html

According to the same documentation:

If the LIMIT expression evaluates to a negative value, then there is no upper bound on the number of rows returned.

like image 24
Mark Paine Avatar answered Sep 29 '22 16:09

Mark Paine