Details

    • Type: Task
    • Status: Open
    • Priority: Major
    • Resolution: Unresolved
    • Fix Version/s: 10.2
    • Component/s: None
    • Labels:
      None

      Description

      Allow DELETE statment with OFFSET, this allow a DELETE like SQLITE:
      http://www.sqlite.org/lang_delete.html

      it's interesting with history table applications where a fixed number of rows is wanted, for example

      CREATE TABLE history (
       channel_id INT NOT NULL DEFAULT 0,
       date_unix DECIMAL(22,6) NOT NULL DEFAULT 0,
       value DECIMAL(22,7) NOT NULL DEFAULT 0,
       PRIMARY KEY (channel_id,date_unix)
      );
      

      many inserts....

      INSERT INTO history (1,now(),current_temperature);
      INSERT INTO history (1,now(),current_temperature);
      INSERT INTO history (1,now(),current_temperature);
      INSERT INTO history (1,now(),current_temperature);
      .....
      

      an crond job executed at every hour:

      DELETE FROM history WHERE channel_id=1 ORDER BY date_unix DESC LIMIT -1 OFFSET 5000
      

      from SQLITE: A negative LIMIT value is interpreted as "no limit".

      this will remove all rows from this 'channel' that are older than the 5000th row


      today this should be done with two queries:

      SELECT date_unix FROM history WHERE channel_id=1 ORDER BY date_unix DESC LIMIT 1 OFFSET 5000
      

      get the date_unix value, and execute:

      DELETE FROM history WHERE channel_id=1 AND date_unix<"{$date_unix from previous query$}"
      

        Gliffy Diagrams

          Attachments

            Activity

            There are no comments yet on this issue.

              People

              • Assignee:
                Unassigned
                Reporter:
                rspadim roberto spadim
              • Votes:
                0 Vote for this issue
                Watchers:
                2 Start watching this issue

                Dates

                • Created:
                  Updated: