Better way to use a large constant

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Better way to use a large constant

Cecil Westerhof-5
I have the following query:
SELECT   *
,        abs(random()) / (250 * 1000 * 1000 * 1000 * 1000 * 1000) + 1 AS
randomiser
FROM     stock
ORDER BY randomiser + julianday("Last Used")
LIMIT    <SOME VALUE>

I prefer to use something I never used or long ago. That is why I use the
random. Randomiser gives a value between 1 and 37.

I use:
    (250 * 1000 * 1000 * 1000 * 1000 * 1000)
because I find that more clear as:
​    250000000000000000​

​But is there a better way?​

--
Cecil Westerhof
_______________________________________________
sqlite-users mailing list
[hidden email]
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
Reply | Threaded
Open this post in threaded view
|

Re: [EXTERNAL] Better way to use a large constant

Hick Gunter
Try 250E15. Just 1 constant instead of 6 constants and 5 multiplication operations (for each and every row).

-----Ursprüngliche Nachricht-----
Von: sqlite-users [mailto:[hidden email]] Im Auftrag von Cecil Westerhof
Gesendet: Dienstag, 05. September 2017 13:49
An: SQLite mailing list <[hidden email]>
Betreff: [EXTERNAL] [sqlite] Better way to use a large constant

I have the following query:
SELECT   *
,        abs(random()) / (250 * 1000 * 1000 * 1000 * 1000 * 1000) + 1 AS
randomiser
FROM     stock
ORDER BY randomiser + julianday("Last Used")
LIMIT    <SOME VALUE>

I prefer to use something I never used or long ago. That is why I use the random. Randomiser gives a value between 1 and 37.

I use:
    (250 * 1000 * 1000 * 1000 * 1000 * 1000) because I find that more clear as:
​    250000000000000000​

​But is there a better way?​

--
Cecil Westerhof
_______________________________________________
sqlite-users mailing list
[hidden email]
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users


___________________________________________
 Gunter Hick
Software Engineer
Scientific Games International GmbH
FN 157284 a, HG Wien
Klitschgasse 2-4, A-1130 Vienna, Austria
Tel: +43 1 80100 0
E-Mail: [hidden email]

This communication (including any attachments) is intended for the use of the intended recipient(s) only and may contain information that is confidential, privileged or legally protected. Any unauthorized use or dissemination of this communication is strictly prohibited. If you have received this communication in error, please immediately notify the sender by return e-mail message and delete all copies of the original communication. Thank you for your cooperation.


_______________________________________________
sqlite-users mailing list
[hidden email]
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
Reply | Threaded
Open this post in threaded view
|

Re: [EXTERNAL] Better way to use a large constant

Cecil Westerhof-5
2017-09-05 13:55 GMT+02:00 Hick Gunter <[hidden email]>:

> Try 250E15. Just 1 constant instead of 6 constants and 5 multiplication
> operations (for each and every row).
>

​Strange: I thought I did something like that, but maybe I did something
wrong.
Is quit a while back, so I do not know what I did exactly.

It gives a  float instead of an integer, but that is in my case not a
problem.

​If it will become a proclem I always can use CAST.

I just changed it to: 2.5E17.




> -----Ursprüngliche Nachricht-----
> Von: sqlite-users [mailto:[hidden email]]
> Im Auftrag von Cecil Westerhof
> Gesendet: Dienstag, 05. September 2017 13:49
> An: SQLite mailing list <[hidden email]>
> Betreff: [EXTERNAL] [sqlite] Better way to use a large constant
>
> I have the following query:
> SELECT   *
> ,        abs(random()) / (250 * 1000 * 1000 * 1000 * 1000 * 1000) + 1 AS
> randomiser
> FROM     stock
> ORDER BY randomiser + julianday("Last Used")
> LIMIT    <SOME VALUE>
>
> I prefer to use something I never used or long ago. That is why I use the
> random. Randomiser gives a value between 1 and 37.
>
> I use:
>     (250 * 1000 * 1000 * 1000 * 1000 * 1000) because I find that more
> clear as:
> ​    250000000000000000​
>
> ​But is there a better way?​
>

--
Cecil Westerhof
_______________________________________________
sqlite-users mailing list
[hidden email]
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
Reply | Threaded
Open this post in threaded view
|

Re: [EXTERNAL] Better way to use a large constant

Hick Gunter
From https://sqlite.org/lang_expr.html

" If a numeric literal has a decimal point or an exponentiation clause or if its magnitude is less than -9223372036854775808 or greater than 9223372036854775807, then it is a floating point literal."

-----Ursprüngliche Nachricht-----
Von: sqlite-users [mailto:[hidden email]] Im Auftrag von Cecil Westerhof
Gesendet: Dienstag, 05. September 2017 14:16
An: SQLite mailing list <[hidden email]>
Betreff: Re: [sqlite] [EXTERNAL] Better way to use a large constant

2017-09-05 13:55 GMT+02:00 Hick Gunter <[hidden email]>:

> Try 250E15. Just 1 constant instead of 6 constants and 5
> multiplication operations (for each and every row).
>

​Strange: I thought I did something like that, but maybe I did something wrong.
Is quit a while back, so I do not know what I did exactly.

It gives a  float instead of an integer, but that is in my case not a problem.

​If it will become a proclem I always can use CAST.

I just changed it to: 2.5E17.




> -----Ursprüngliche Nachricht-----
> Von: sqlite-users
> [mailto:[hidden email]]
> Im Auftrag von Cecil Westerhof
> Gesendet: Dienstag, 05. September 2017 13:49
> An: SQLite mailing list <[hidden email]>
> Betreff: [EXTERNAL] [sqlite] Better way to use a large constant
>
> I have the following query:
> SELECT   *
> ,        abs(random()) / (250 * 1000 * 1000 * 1000 * 1000 * 1000) + 1 AS
> randomiser
> FROM     stock
> ORDER BY randomiser + julianday("Last Used")
> LIMIT    <SOME VALUE>
>
> I prefer to use something I never used or long ago. That is why I use
> the random. Randomiser gives a value between 1 and 37.
>
> I use:
>     (250 * 1000 * 1000 * 1000 * 1000 * 1000) because I find that more
> clear as:
> ​    250000000000000000​
>
> ​But is there a better way?​
>

--
Cecil Westerhof
_______________________________________________
sqlite-users mailing list
[hidden email]
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users


___________________________________________
 Gunter Hick
Software Engineer
Scientific Games International GmbH
FN 157284 a, HG Wien
Klitschgasse 2-4, A-1130 Vienna, Austria
Tel: +43 1 80100 0
E-Mail: [hidden email]

This communication (including any attachments) is intended for the use of the intended recipient(s) only and may contain information that is confidential, privileged or legally protected. Any unauthorized use or dissemination of this communication is strictly prohibited. If you have received this communication in error, please immediately notify the sender by return e-mail message and delete all copies of the original communication. Thank you for your cooperation.


_______________________________________________
sqlite-users mailing list
[hidden email]
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users