Uploaded image for project: 'MariaDB Server'
  1. MariaDB Server
  2. MDEV-9677

Error in counting in sequence engine

Details

    Description

      When you count from high to low the Values starts not from "from" Value every time. see sample

      MariaDB [mysql]> select Version();
      +-----------------------+
      | Version()             |
      +-----------------------+
      | 10.1.12-MariaDB-debug |
      +-----------------------+
      1 row in set (0.00 sec)
      

      MariaDB [mysql]> SELECT * FROM seq_15_to_1_step_2;
      +-----+
      | seq |
      +-----+
      |  15 |
      |  13 |
      |  11 |
      |   9 |
      |   7 |
      |   5 |
      |   3 |
      |   1 |
      +-----+
      8 rows in set (0.00 sec)
      

      MariaDB [mysql]> SELECT * FROM seq_15_to_1_step_3;
      +-----+
      | seq |
      +-----+
      |  13 |
      |  10 |
      |   7 |
      |   4 |
      |   1 |
      +-----+
      5 rows in set (0.01 sec)
      

      Attachments

        Activity

          It has actually been documented, although wording could be clearer:
          https://mariadb.com/kb/en/mariadb/sequence/

          To use a sequence in a statement, you select from the table named by a pattern seq_FROM_to_TO or seq_FROM_to_TO_step_STEP.

          A sequence can go backward too. In this case the final value will always be 1, so that a descending sequence has the same values as an ascending sequence:

          In fact, of course, it should be not "will always be 1", but "will always be the TO value"; but anyway, it works so by design.

          greenman, do you think it makes sense to put it better and maybe add a more generic example?

          elenst Elena Stepanova added a comment - It has actually been documented, although wording could be clearer: https://mariadb.com/kb/en/mariadb/sequence/ To use a sequence in a statement, you select from the table named by a pattern seq_FROM_to_TO or seq_FROM_to_TO_step_STEP. A sequence can go backward too. In this case the final value will always be 1, so that a descending sequence has the same values as an ascending sequence: In fact, of course, it should be not "will always be 1", but "will always be the TO value"; but anyway, it works so by design. greenman , do you think it makes sense to put it better and maybe add a more generic example?
          greenman Ian Gilfillan added a comment -

          Clarified wording and added further examples to demonstrate descending order and from/to.

          greenman Ian Gilfillan added a comment - Clarified wording and added further examples to demonstrate descending order and from/to.

          People

            greenman Ian Gilfillan
            Bernd Buffen Bernd Buffen
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Git Integration

                Error rendering 'com.xiplink.jira.git.jira_git_plugin:git-issue-webpanel'. Please contact your Jira administrators.