I'm writing numerical lists to a sqlite DB and I'm wondering, if the way
I do it is the fastest possible, since the lists are pretty large and it seems that most of the processing time is spent on writing the data to
the DB instead on the actual computation of the lists.
So I currently do:
sqlite3 db $rstfile2
db eval {CREATE TABLE general(key TEXT, data TEXT)}
db eval {CREATE TABLE results(key TEXT, data TEXT)}
db eval "INSERT INTO general VALUES('dt','$dt')"
db eval "INSERT INTO general VALUES('nsteps','$nsteps')"
db eval "INSERT INTO results VALUES('$step-global','$Im')"
Here, the list "Im" is the large list.
Is this already optimal of are there some tricks to make it much faster?--- Synchronet 3.21f-Linux NewsLink 1.2
Many thanks
Alex
Use sqlite's ability to directly address Tcl variables instead:Thanks Rich! I wasn't aware, that this trick also works for sqlight (I
Care to define what "llength" constitutes "large" for you?
Am 29.04.2026 um 17:50 schrieb Rich:
Use sqlite's ability to directly address Tcl variables instead:Thanks Rich! I wasn't aware, that this trick also works for sqlight (I
know it from Tcl itself when using "expr".
This indeed cut the time by 50%.
I had to put the single quotes back though:
db eval {INSERT INTO results VALUES('$step-global','$Im')}
Without the quotes, I got some weird errors.
I hat to roll back, since the new solution write empty string to the DB.
At least my old command to retrieve the data does returns an empty string:
db eval "SELECT data FROM results WHERE key='$setnum-global'"
I don't understand why...
I'll try again without the single quotes around the variable name.Nope, same result, empty string...
Am 29.04.2026 um 19:13 schrieb meshparts:
Am 29.04.2026 um 17:50 schrieb Rich:
Use sqlite's ability to directly address Tcl variables instead:Thanks Rich! I wasn't aware, that this trick also works for sqlight (I
know it from Tcl itself when using "expr".
This indeed cut the time by 50%.
I had to put the single quotes back though:
db eval {INSERT INTO results VALUES('$step-global','$Im')}
Without the quotes, I got some weird errors.
I hat to roll back, since the new solution write empty string to the DB.
At least my old command to retrieve the data does returns an empty string:
db eval "SELECT data FROM results WHERE key='$setnum-global'"
I don't understand why...
Am 29.04.2026 um 19:44 schrieb meshparts:
Am 29.04.2026 um 19:13 schrieb meshparts:
Am 29.04.2026 um 17:50 schrieb Rich:
Use sqlite's ability to directly address Tcl variables instead:Thanks Rich! I wasn't aware, that this trick also works for sqlight
(I know it from Tcl itself when using "expr".
This indeed cut the time by 50%.
I had to put the single quotes back though:
db eval {INSERT INTO results VALUES('$step-global','$Im')}
Without the quotes, I got some weird errors.
I hat to roll back, since the new solution write empty string to the DB.
At least my old command to retrieve the data does returns an empty
string:
db eval "SELECT data FROM results WHERE key='$setnum-global'"
I don't understand why...
Got it: I'm using a variable in the first argument of VALUES, which is
not supported, when using curly braces.
Am 29.04.2026 um 17:50 schrieb Rich:
Care to define what "llength" constitutes "large" for you?
Well, the size of the list is anything between 1e3 to 1e9 as an order of magnitude.
Am 29.04.2026 um 19:44 schrieb meshparts:
Am 29.04.2026 um 19:13 schrieb meshparts:
Am 29.04.2026 um 17:50 schrieb Rich:
Use sqlite's ability to directly address Tcl variables instead:Thanks Rich! I wasn't aware, that this trick also works for sqlight (I
know it from Tcl itself when using "expr".
This indeed cut the time by 50%.
I had to put the single quotes back though:
db eval {INSERT INTO results VALUES('$step-global','$Im')}
Without the quotes, I got some weird errors.
I hat to roll back, since the new solution write empty string to the DB.
At least my old command to retrieve the data does returns an empty string: >>
db eval "SELECT data FROM results WHERE key='$setnum-global'"
I don't understand why...
Got it: I'm using a variable in the first argument of VALUES, which is
not supported, when using curly braces.
I presume you mean 10e3 to 10e9, as 1 to the third power, and 1 to theexpr 1e3 => 1000
ninth power, are both one... 🙂
meshparts <alexandru.dadalau@meshparts.de> wrote:
Am 29.04.2026 um 19:44 schrieb meshparts:
Am 29.04.2026 um 19:13 schrieb meshparts:
Am 29.04.2026 um 17:50 schrieb Rich:
Use sqlite's ability to directly address Tcl variables instead:Thanks Rich! I wasn't aware, that this trick also works for sqlight (I >>>> know it from Tcl itself when using "expr".
This indeed cut the time by 50%.
I had to put the single quotes back though:
db eval {INSERT INTO results VALUES('$step-global','$Im')}
Without the quotes, I got some weird errors.
I hat to roll back, since the new solution write empty string to the DB. >>>
At least my old command to retrieve the data does returns an empty string: >>>
db eval "SELECT data FROM results WHERE key='$setnum-global'"
I don't understand why...
Got it: I'm using a variable in the first argument of VALUES, which is
not supported, when using curly braces.
Note this sentence from your other posting quoting the sqlite tcl api documentation:
Tcl variable names can appear in the SQL statement of the second
argument in any position where it is legal to put a string or number
literal.
As it is legal to put a string or number literal in the first slot, it
is also legal to put a variable reference there as well.
As to your other posts, I'm not following what problem you are finding.
Is the database storing empty string when the list had X elements? Or
is the list empty (empty string), but the database is storing something
other than "empty string"?
Am 29.04.2026 um 23:56 schrieb Rich:
meshparts <alexandru.dadalau@meshparts.de> wrote:No, the key argument of VALUES is the problem.
Am 29.04.2026 um 19:44 schrieb meshparts:
Am 29.04.2026 um 19:13 schrieb meshparts:
Am 29.04.2026 um 17:50 schrieb Rich:
Use sqlite's ability to directly address Tcl variables instead:Thanks Rich! I wasn't aware, that this trick also works for sqlight (I >>>>> know it from Tcl itself when using "expr".
This indeed cut the time by 50%.
I had to put the single quotes back though:
db eval {INSERT INTO results VALUES('$step-global','$Im')}
Without the quotes, I got some weird errors.
I hat to roll back, since the new solution write empty string to the DB. >>>>
At least my old command to retrieve the data does returns an empty string: >>>>
db eval "SELECT data FROM results WHERE key='$setnum-global'"
I don't understand why...
Got it: I'm using a variable in the first argument of VALUES, which is
not supported, when using curly braces.
Note this sentence from your other posting quoting the sqlite tcl api
documentation:
Tcl variable names can appear in the SQL statement of the second
argument in any position where it is legal to put a string or number
literal.
As it is legal to put a string or number literal in the first slot, it
is also legal to put a variable reference there as well.
As to your other posts, I'm not following what problem you are finding.
Is the database storing empty string when the list had X elements? Or
is the list empty (empty string), but the database is storing something
other than "empty string"?
This works:
set step 1
set Im "1 2 3"
sqlite3 db "test.db"
db eval {CREATE TABLE results(key TEXT, data TEXT)}
db eval "INSERT INTO results VALUES('$step-global',\$Im)"
puts [db eval "SELECT data FROM results WHERE key='$step-global'"]
db close
This does not work:
set step 1
set Im "1 2 3"
sqlite3 db "test.db"
db eval {CREATE TABLE results(key TEXT, data TEXT)}
db eval {INSERT INTO results VALUES('$step-global',$Im)}
puts [db eval "SELECT data FROM results WHERE key='$step-global'"]
db close
The key column contains the literal string "$step-global", which doesYes, I also get it now. Which means, that the key argument is
not match "1-global", so sqlite returns an empty result.
That's why you are getting empty string, you are not selecting using
the string that actually exists in the key column.
Am 30.04.2026 um 00:22 schrieb Rich:
The key column contains the literal string "$step-global", which doesYes, I also get it now. Which means, that the key argument is
not match "1-global", so sqlite returns an empty result.
That's why you are getting empty string, you are not selecting using
the string that actually exists in the key column.
interpreted differently than the variable argument. But it's no
supprise, since the manual only states that the second argument will be replaced with the value when using $.
Am 29.04.2026 um 23:29 schrieb meshparts:
Am 29.04.2026 um 19:44 schrieb meshparts:
Am 29.04.2026 um 19:13 schrieb meshparts:
Am 29.04.2026 um 17:50 schrieb Rich:
Use sqlite's ability to directly address Tcl variables instead:Thanks Rich! I wasn't aware, that this trick also works for sqlight
(I know it from Tcl itself when using "expr".
This indeed cut the time by 50%.
I had to put the single quotes back though:
db eval {INSERT INTO results VALUES('$step-global','$Im')}
Without the quotes, I got some weird errors.
I hat to roll back, since the new solution write empty string to the DB. >>
At least my old command to retrieve the data does returns an empty
string:
db eval "SELECT data FROM results WHERE key='$setnum-global'"
I don't understand why...
Got it: I'm using a variable in the first argument of VALUES, which is
not supported, when using curly braces.
So now I'm doing:
db eval "INSERT INTO results VALUES('$step-global',\$Im)"
Turns out this method is not faster than the original one.
The stated 50% cut in time was due to the previously wrong usage.
So back to the drawing board, still in need of a way to make INSERT of
large lists faster.
There is no need to use "" and escape your variables.
This should work, is faster and save (no code injection).
The eval method will parse your string correctly. Note the {}.
db eval {INSERT INTO results VALUES($step-global,$Im)}
HTH
rene
meshparts <alexandru.dadalau@meshparts.de> wrote:
Well, the size of the list is anything between 1e3 to 1e9 as an order of
magnitude.
I presume you mean 10e3 to 10e9, as 1 to the third power, and 1 to the
ninth power, are both one... :)
Am 30.04.2026 um 11:22 schrieb rene:
There is no need to use "" and escape your variables.
This should work, is faster and save (no code injection).
The eval method will parse your string correctly. Note the {}.
db eval {INSERT INTO results VALUES($step-global,$Im)}
HTH
rene
Well, it doesn't.
You can use my demo below to test your proposal.
I get the error "no such column: global" when not using the single
quotes for the key argument.
file delete test.db
set step 1
set Im "1 2 3"
sqlite3 db "test.db"
db eval {CREATE TABLE results(key TEXT, data TEXT)}
db eval {INSERT INTO results VALUES('$step-global',$Im)}
puts [db eval "SELECT data FROM results WHERE key='$step-global'"]
db close
Ok, I have asked on the sqlite mailing list and the answer is:Many thanks and good to know.
Only alphanumeric names are allowed. No minus signs in the variable name.
| Sysop: | DaiTengu |
|---|---|
| Location: | Appleton, WI |
| Users: | 1,116 |
| Nodes: | 10 (0 / 10) |
| Uptime: | 86:54:45 |
| Calls: | 14,305 |
| Files: | 186,338 |
| D/L today: |
1,018 files (321M bytes) |
| Messages: | 2,525,511 |