In Python if I wanted a sequence from 0 - 9 (inclusive) I would use xrange(0,10) . Is there a way I can do this in MySQL?
相关问题
- how to define constructor for Python's new Nam
- streaming md5sum of contents of a large remote tar
- SQL join to get the cartesian product of 2 columns
- sql execution latency when assign to a variable
- How to get the background from multiple images by
You can use LAST_INSERT_ID() to simulate sequences in MySQL.
Read up more here as well as some discussion on it here
Since there is no such thing as xrange, one could use a separate table stored with integer (as previously answered), or just make a stored procedure to do the job:
Usage:
The above is obviously going to be slower than creating a ready table with integers. It's more flexible though.
If Python is your programming language, you can map that same Python range to create an INSERT statement of the form:
Not exactly what you asked for, but a single line of Python code that will handle any range up to the maximum length of a MySQL statement.
Try an integers table variant. This one is taken from Xaprb:
If you made that last
select
a view named, say,xrange999
, then you can simply:(of course, you can do that with just the ten-row
integers
table, but I find a thousand integers a little more useful.)