LIMIT 0,-1 broken in 5.0

Ask a Question related to MySQL, Design and Development.

  1. #1

    Default LIMIT 0,-1 broken in 5.0

    I have a number of scripts that generate queries where the number of rows I need is dynamic ( LIMIT 0,$rows ).

    Using MySQL 4.0 I can get all the rows by setting $rows to -1. This produces a syntax error in 5.0. Is there something else I can set $rows to to get all rows (other than some arbitrary high number)?



    --
    Brian Wakem
    Email: [url]http://homepage.ntlworld.com/b.wakem/myemail.png[/url]
    Brian Wakem Guest

  2. Similar Questions and Discussions

    1. broken
      i cant watch anything, i try and download the latest version but it says i already have. and apparetnly my yinststarter is broken. please help
    2. Is there a 2gb dbspace limit NT 4.0, IDS 7.3?
      Is there a 2gb dbspace limit on Windows NT 4.0, IDS 7.3?
    3. QBF Limit?
      A client wants an Access 2000 database to store about 300 records. The single table will have about 55 fields. They want to use Query by Form to...
    4. Broken key
      My arrow-down key is broken. I was thinking of letting Linux Redhat 8.0 act as arrow-down key was pressed when I pressed another key, e.g PageDown....
    5. Broken CD
      When I removed my Windows XP Home CD from a storage box I flexed the CD too much and cracked it. I am now unable to read the CD. How do I get a...
  3. #2

    Default Re: LIMIT 0,-1 broken in 5.0

    Brian Wakem <no@email.com> wrote:
    > I have a number of scripts that generate queries where the number of
    > rows I need is dynamic ( LIMIT 0,$rows ).
    >
    > Using MySQL 4.0 I can get all the rows by setting $rows to -1. This
    > produces a syntax error in 5.0.
    According to the manual, both parameters to the LIMIT clause must be
    nonnegative (in all MySQL versions). So in fact pre-5.0 was broken
    (probably casting the argument to unsigned after parsing).

    The correct solution would be to remove the LIMIT clause from the
    statement if one does not need it.


    XL
    --
    Axel Schwenke, Senior Software Developer, MySQL AB

    Online User Manual: [url]http://dev.mysql.com/doc/refman/5.0/en/[/url]
    MySQL User Forums: [url]http://forums.mysql.com/[/url]
    Axel Schwenke Guest

  4. #3

    Default Re: LIMIT 0,-1 broken in 5.0

    Axel Schwenke wrote:
    > Brian Wakem <no@email.com> wrote:
    >> I have a number of scripts that generate queries where the number of
    >> rows I need is dynamic ( LIMIT 0,$rows ).
    >>
    >> Using MySQL 4.0 I can get all the rows by setting $rows to -1. This
    >> produces a syntax error in 5.0.
    >
    > According to the manual, both parameters to the LIMIT clause must be
    > nonnegative (in all MySQL versions). So in fact pre-5.0 was broken
    > (probably casting the argument to unsigned after parsing).
    >
    > The correct solution would be to remove the LIMIT clause from the
    > statement if one does not need it.


    I was afraid that would be the answer. This is not going to straight
    forward to fix as the number -1 does not even appear in the scripts
    themselves but is a result of a calculation, making it impossible to find
    them until they produce an error.

    I will need to have a little think.



    --
    Brian Wakem
    Email: [url]http://homepage.ntlworld.com/b.wakem/myemail.png[/url]
    Brian Wakem Guest

  5. #4

    Default Re: LIMIT 0,-1 broken in 5.0

    Brian Wakem wrote:
    > Axel Schwenke wrote:
    >> Brian Wakem <no@email.com> wrote:
    >>> I have a number of scripts that generate queries where the number of
    >>> rows I need is dynamic ( LIMIT 0,$rows ).
    >>>
    >>> Using MySQL 4.0 I can get all the rows by setting $rows to -1. This
    >>> produces a syntax error in 5.0.
    >>
    >> According to the manual, both parameters to the LIMIT clause must be
    >> nonnegative (in all MySQL versions). So in fact pre-5.0 was broken
    >> (probably casting the argument to unsigned after parsing).
    >>
    >> The correct solution would be to remove the LIMIT clause from the
    >> statement if one does not need it.
    >
    >
    >
    > I was afraid that would be the answer. This is not going to straight
    > forward to fix as the number -1 does not even appear in the scripts
    > themselves but is a result of a calculation, making it impossible to
    > find them until they produce an error.
    >
    > I will need to have a little think.
    >
    >
    >
    $sql = "bla bla without limit";

    if ($row != -1) {
    $sql .= ' LIMIT 0,' . $row;
    }

    Something like htis?
    Snef Guest

  6. #5

    Default Re: LIMIT 0,-1 broken in 5.0

    Snef wrote:
    > Brian Wakem wrote:
    >> Axel Schwenke wrote:
    >>> Brian Wakem <no@email.com> wrote:
    >>>> I have a number of scripts that generate queries where the number of
    >>>> rows I need is dynamic ( LIMIT 0,$rows ).
    >>>>
    >>>> Using MySQL 4.0 I can get all the rows by setting $rows to -1. This
    >>>> produces a syntax error in 5.0.
    >>>
    >>> According to the manual, both parameters to the LIMIT clause must be
    >>> nonnegative (in all MySQL versions). So in fact pre-5.0 was broken
    >>> (probably casting the argument to unsigned after parsing).
    >>>
    >>> The correct solution would be to remove the LIMIT clause from the
    >>> statement if one does not need it.
    >>
    >>
    >>
    >> I was afraid that would be the answer. This is not going to straight
    >> forward to fix as the number -1 does not even appear in the scripts
    >> themselves but is a result of a calculation, making it impossible to
    >> find them until they produce an error.
    >>
    >> I will need to have a little think.
    >>
    >>
    >>
    > $sql = "bla bla without limit";
    >
    > if ($row != -1) {
    > $sql .= ' LIMIT 0,' . $row;
    > }
    >
    > Something like htis?


    Yes it's a rather messy hack really, but the only alternative I can think of
    is to set $rows to a very high number, which would be just as messy. Maybe
    time to toss a coin.



    --
    Brian Wakem
    Email: [url]http://homepage.ntlworld.com/b.wakem/myemail.png[/url]
    Brian Wakem Guest

  7. #6

    Default Re: LIMIT 0,-1 broken in 5.0

    Brian Wakem wrote:
    > Snef wrote:
    >> Brian Wakem wrote:
    >>> Axel Schwenke wrote:
    >>>> Brian Wakem <no@email.com> wrote:
    >>>>> I have a number of scripts that generate queries where the number of
    >>>>> rows I need is dynamic ( LIMIT 0,$rows ).
    >>>>>
    >>>>> Using MySQL 4.0 I can get all the rows by setting $rows to -1. This
    >>>>> produces a syntax error in 5.0.
    >>>>
    >>>> According to the manual, both parameters to the LIMIT clause must be
    >>>> nonnegative (in all MySQL versions). So in fact pre-5.0 was broken
    >>>> (probably casting the argument to unsigned after parsing).
    >>>>
    >>>> The correct solution would be to remove the LIMIT clause from the
    >>>> statement if one does not need it.
    >>>
    >>>
    >>>
    >>> I was afraid that would be the answer. This is not going to straight
    >>> forward to fix as the number -1 does not even appear in the scripts
    >>> themselves but is a result of a calculation, making it impossible to
    >>> find them until they produce an error.
    >>>
    >>> I will need to have a little think.
    >>>
    >>>
    >>>
    >> $sql = "bla bla without limit";
    >>
    >> if ($row != -1) {
    >> $sql .= ' LIMIT 0,' . $row;
    >> }
    >>
    >> Something like htis?
    >
    >
    >
    > Yes it's a rather messy hack really, but the only alternative I can think
    > of
    > is to set $rows to a very high number, which would be just as messy.
    > Maybe time to toss a coin.

    I decided to go for:

    $rows = 1_000_000_000 if $rows == -1;


    --
    Brian Wakem
    Email: [url]http://homepage.ntlworld.com/b.wakem/myemail.png[/url]
    Brian Wakem Guest

  8. #7

    Default Re: LIMIT 0,-1 broken in 5.0



    Brian Wakem wrote:
    > Brian Wakem wrote:
    >
    >> Snef wrote:
    >>> Brian Wakem wrote:
    >>>> Axel Schwenke wrote:
    >>>>> Brian Wakem <no@email.com> wrote:
    >>>>>> I have a number of scripts that generate queries where the number of
    >>>>>> rows I need is dynamic ( LIMIT 0,$rows ).
    >>>>>>
    >>>>>> Using MySQL 4.0 I can get all the rows by setting $rows to -1. This
    >>>>>> produces a syntax error in 5.0.
    >>>>> According to the manual, both parameters to the LIMIT clause must be
    >>>>> nonnegative (in all MySQL versions). So in fact pre-5.0 was broken
    >>>>> (probably casting the argument to unsigned after parsing).
    >>>>>
    >>>>> The correct solution would be to remove the LIMIT clause from the
    >>>>> statement if one does not need it.
    >>>>
    >>>>
    >>>> I was afraid that would be the answer. This is not going to straight
    >>>> forward to fix as the number -1 does not even appear in the scripts
    >>>> themselves but is a result of a calculation, making it impossible to
    >>>> find them until they produce an error.
    >>>>
    >>>> I will need to have a little think.
    >>>>
    >>>>
    >>>>
    >>> $sql = "bla bla without limit";
    >>>
    >>> if ($row != -1) {
    >>> $sql .= ' LIMIT 0,' . $row;
    >>> }
    >>>
    >>> Something like htis?
    >>
    >>
    >> Yes it's a rather messy hack really, but the only alternative I can think
    >> of
    >> is to set $rows to a very high number, which would be just as messy.
    >> Maybe time to toss a coin.
    >
    >
    > I decided to go for:
    >
    > $rows = 1_000_000_000 if $rows == -1;
    >
    >
    How about performance? I only use LIMIT when it us meaningfull.
    LIMIT 0,1000000000 seems a bit strange to me.

    Nevertheless, when it works, it works ;)
    Snef Guest

  9. #8

    Default Re: LIMIT 0,-1 broken in 5.0

    Snef wrote:
    >
    >
    > Brian Wakem wrote:
    >> Brian Wakem wrote:
    >>
    >>> Snef wrote:
    >>>> Brian Wakem wrote:
    >>>>> Axel Schwenke wrote:
    >>>>>> Brian Wakem <no@email.com> wrote:
    >>>>>>> I have a number of scripts that generate queries where the number of
    >>>>>>> rows I need is dynamic ( LIMIT 0,$rows ).
    >>>>>>>
    >>>>>>> Using MySQL 4.0 I can get all the rows by setting $rows to -1. This
    >>>>>>> produces a syntax error in 5.0.
    >>>>>> According to the manual, both parameters to the LIMIT clause must be
    >>>>>> nonnegative (in all MySQL versions). So in fact pre-5.0 was broken
    >>>>>> (probably casting the argument to unsigned after parsing).
    >>>>>>
    >>>>>> The correct solution would be to remove the LIMIT clause from the
    >>>>>> statement if one does not need it.
    >>>>>
    >>>>>
    >>>>> I was afraid that would be the answer. This is not going to straight
    >>>>> forward to fix as the number -1 does not even appear in the scripts
    >>>>> themselves but is a result of a calculation, making it impossible to
    >>>>> find them until they produce an error.
    >>>>>
    >>>>> I will need to have a little think.
    >>>>>
    >>>>>
    >>>>>
    >>>> $sql = "bla bla without limit";
    >>>>
    >>>> if ($row != -1) {
    >>>> $sql .= ' LIMIT 0,' . $row;
    >>>> }
    >>>>
    >>>> Something like htis?
    >>>
    >>>
    >>> Yes it's a rather messy hack really, but the only alternative I can
    >>> think of
    >>> is to set $rows to a very high number, which would be just as messy.
    >>> Maybe time to toss a coin.
    >>
    >>
    >> I decided to go for:
    >>
    >> $rows = 1_000_000_000 if $rows == -1;
    >>
    >>
    > How about performance? I only use LIMIT when it us meaningfull.
    > LIMIT 0,1000000000 seems a bit strange to me.
    >
    > Nevertheless, when it works, it works ;)

    No performance hit apparently:-


    mysql> SELECT * FROM refmap;

    <snip results>

    418536 rows in set (1.17 sec)



    mysql> SELECT * FROM refmap LIMIT 0,1000000000;

    <snip results>

    418536 rows in set (1.17 sec)



    --
    Brian Wakem
    Email: [url]http://homepage.ntlworld.com/b.wakem/myemail.png[/url]
    Brian Wakem Guest

  10. #9

    Default Re: LIMIT 0,-1 broken in 5.0

    Brian Wakem wrote:
    > Brian Wakem wrote:
    >
    > > Snef wrote:
    > >> Brian Wakem wrote:
    > >>> Axel Schwenke wrote:
    > >>>> Brian Wakem <no@email.com> wrote:
    > >>>>> I have a number of scripts that generate queries where the number of
    > >>>>> rows I need is dynamic ( LIMIT 0,$rows ).
    > > > > > >
    > >>>>> Using MySQL 4.0 I can get all the rows by setting $rows to -1. This
    > >>>>> produces a syntax error in 5.0.
    > > > > >
    > >>>> According to the manual, both parameters to the LIMIT clause must be
    > >>>> nonnegative (in all MySQL versions). So in fact pre-5.0 was broken
    > >>>> (probably casting the argument to unsigned after parsing).
    > > > > >
    > >>>> The correct solution would be to remove the LIMIT clause from the
    > >>>> statement if one does not need it.
    > > > >
    > > > >
    > > > >
    > >>> I was afraid that would be the answer. This is not going to straight
    > >>> forward to fix as the number -1 does not even appear in the scripts
    > >>> themselves but is a result of a calculation, making it impossible to
    > >>> find them until they produce an error.
    > > > >
    > >>> I will need to have a little think.
    > > > >
    > > > >
    > > > >
    > >> $sql = "bla bla without limit";
    > >>
    > >> if ($row != -1) {
    > >> $sql .= ' LIMIT 0,' . $row;
    > >> }
    > >>
    > >> Something like htis?
    > >
    > >
    > >
    > > Yes it's a rather messy hack really, but the only alternative I can think
    > > of
    > > is to set $rows to a very high number, which would be just as messy.
    > > Maybe time to toss a coin.
    >
    >
    > I decided to go for:
    >
    > $rows = 1_000_000_000 if $rows == -1;
    And in the instance where there will be more than 1,000,000,000 rows? There is a difference between returning all rows, and returning the minimum number of all rows and a billion rows.

    --

    Murdoc Guest

  11. #10

    Default Re: LIMIT 0,-1 broken in 5.0

    >> I decided to go for:
    >>
    >> $rows = 1_000_000_000 if $rows == -1;
    >
    > And in the instance where there will be more than 1,000,000,000 rows? There is a difference between returning all rows, and returning the minimum number of all rows and a billion rows.
    >
    Do you have any idea how long it would take to put 1,000,000,000 rows
    over the network?. I think you will find that there is absolutely _no_
    difference between a time-out error and a time-out error.

    Best regards
    Dikkie Dik Guest

  12. #11

    Default Re: LIMIT 0,-1 broken in 5.0

    Dikkie Dik wrote:
    > > > I decided to go for:
    > > >
    > > > $rows = 1_000_000_000 if $rows == -1;
    > >
    > > And in the instance where there will be more than 1,000,000,000 rows? There is a difference between returning all rows, and returning the minimum number of all rows and a billion rows.
    > >
    > Do you have any idea how long it would take to put 1,000,000,000 rows over the network?. I think you will find that there is absolutely no difference between a time-out error and a time-out error.
    >
    > Best regards
    Who said anything about pulling the resultset over the network? What if the resultset is used in a stored procedure? The above solution, as previously stated, does not solve the problem.

    --

    Murdoc Guest

  13. #12

    Default Re: LIMIT 0,-1 broken in 5.0

    Murdoc wrote:
    > Dikkie Dik wrote:
    >
    >
    >>>>I decided to go for:
    >>>>
    >>>>$rows = 1_000_000_000 if $rows == -1;
    >>>
    >>>And in the instance where there will be more than 1,000,000,000 rows? There is a difference between returning all rows, and returning the minimum number of all rows and a billion rows.
    >>>
    >>
    >>Do you have any idea how long it would take to put 1,000,000,000 rows over the network?. I think you will find that there is absolutely no difference between a time-out error and a time-out error.
    >>
    >>Best regards
    >
    >
    > Who said anything about pulling the resultset over the network? What if the resultset is used in a stored procedure? The above solution, as previously stated, does not solve the problem.
    >
    I think for all practical purposes it will fix the problem for this
    user. No, it won't fix the problem for all users. But no one suggested
    it for all users.

    --
    ==================
    Remove the "x" from my email address
    Jerry Stuckle
    JDS Computer Training Corp.
    [email]jstucklex@attglobal.net[/email]
    ==================
    Jerry Stuckle Guest

  14. #13

    Default Re: LIMIT 0,-1 broken in 5.0

    Murdoc wrote:
    > Brian Wakem wrote:
    >> I decided to go for:
    >>
    >> $rows = 1_000_000_000 if $rows == -1;
    >
    > And in the instance where there will be more than 1,000,000,000 rows?
    > There is a difference between returning all rows, and returning the
    > minimum number of all rows and a billion rows.

    If the tables in question ever have more than a billion rows then that will
    be the at least of my problems.



    --
    Brian Wakem
    Email: [url]http://homepage.ntlworld.com/b.wakem/myemail.png[/url]
    Brian Wakem Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139