* Erick Papadakis
> i need to set up an auto_increment field inside mysql. for various
> reasons, the maximum size is 3.

Could you say something about these reasons...?

> but i don't want this to be ONLY integers
> because that limits me until 999 numbers only.

Well... using three _bytes_, the unsigned range for mediumint is 0 -
16777215.

If you want to restrict the _visual_ width of the column to be three
characters, then you are right, the limit for integers are 999.

auto_increment works with integers only.

> since i have all
> flexibility for these three digits or letters, i want to include numbers
> and some characters into it as well. e.g.,
>
>   m78
>   23a
>   1pt
>   1~8
>   !76
>
> ...etc can all be valid keys for me.
>
> how can i generate such numbers on the fly? if not inside mysql, then
> inside php?

I don't think you can do this in an efficient way inside mysql, but using
PHP you should be able to calculate a number into a three character string.
One way may be to use a base 36 integer... in python it would be something
like this:

>>> import string
>>> def base36(x):
...   d = string.digits+string.lowercase
...   a = x/(36*36)
...   b = (x-(a*36*36))/36
...   c = x-(a*36*36)-(b*36)
...   return d[a]+d[b]+d[c]
...
>>> base36(9999)
'7pr'
>>> int('7pr',36)
9999
>>>

The max value would be 46655:

>>> base36(46655)
'zzz'

You could use a SMALLINT (2 bytes only) and auto_increment, and convert the
integer value to the base36() value before you display it on the screen.
This would ensure max three characters in this column.

--
Roger
sql


---------------------------------------------------------------------
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/           (the list archive)

To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php

Reply via email to