[sqlite] Unexpected behavior with an attached read-only database and BEGIN IMMEDIATE.

2011-11-24 Thread Peter Aronson
BEGIN IMMEDIATE fails when there is a read-only database attached. I'm not saying this is a bug, but it is unexpected behavior and at least mildly inconvenient. Consider the situation where I've opened one database read-write and attach another read-only: sqlite> attach database 'file:ex.db?mode=

Re: [sqlite] Checking for existence of in-memory tables

2011-11-24 Thread Kees Nuyt
On Thu, 24 Nov 2011 12:30:27 -0500, Pavel Ivanov wrote: >>> P.S: I know that one can simply do a CREATE TABLE IF NOT EXISTS... but I >>> still need to know if a table exists or not. >> >> You can easily try this with the sqlite3 command line tool by omitting >> the database file name argument on

Re: [sqlite] Aggregating Forex data

2011-11-24 Thread Simon Slavin
On 24 Nov 2011, at 6:18pm, Rafael Garcia Leiva wrote: >> SELECT MAX(high) AS High, MIN(low) as Low, >>STRFTIME('%Y-%m-%d',date) as Date >>FROM eurusd GROUP BY round(STRFTIME('%s',date) / (23 * 60)) > > Many thanks for the answers. That's exactly what I was looking for! > > Just one fina

Re: [sqlite] [sqlite TOO slow

2011-11-24 Thread Gaurav Vyas
It works!! Thanks a lot Simon! Gaurav On Thu, Nov 24, 2011 at 11:22 AM, Simon Slavin wrote: > > On 24 Nov 2011, at 5:10pm, Jay A. Kreibich wrote: > > > On Thu, Nov 24, 2011 at 08:08:12AM +, Simon Slavin scratched on the > wall: > > > >> It is faster to search integers than it is to search

Re: [sqlite] Aggregating Forex data

2011-11-24 Thread Rafael Garcia Leiva
El 24/11/2011 14:49, 雷钦 escribió: On 2011-11-24 08:02:21 +, Simon Slavin wrote: On 24 Nov 2011, at 7:42am, Rafael Garcia Leiva wrote: CREATE TABLE eurusd ( date TEXT NOT NULL PRIMARY KEY, open REAL NOT NULL, high REAL NOT NULL, lowREAL NOT NULL, close REAL NO

Re: [sqlite] Checking for existence of in-memory tables

2011-11-24 Thread Peter Aronson
Each SQLite database has its own sqlite_master table. If open the :memory: database its sqlite_master table can be accessed as sqlite_master or main.sqlite_master. If you attach it, say, using: Attach database ':memory:' as memory; Then the :memory: database's sqlite_master be accessed with th

Re: [sqlite] Checking for existence of in-memory tables

2011-11-24 Thread Pavel Ivanov
>> P.S: I know that one can simply do a CREATE TABLE IF NOT EXISTS... but I >> still need to know if a table exists or not. > > You can easily try this with the sqlite3 command line tool by omitting > the database file name argument on the command line. > Create a table, insert a row, check sqlite_

Re: [sqlite] Bug

2011-11-24 Thread Jay A. Kreibich
On Wed, Nov 23, 2011 at 10:24:12AM -0800, Wiktor Adamski scratched on the wall: > > ? In the first query, there is an aggregate in the result set, so an > > ? implicit GROUP BY is used. ?The ORDER BY is meaningless, but not an > > ? error (and could be more easily written "ORDER BY 1"; see below).

Re: [sqlite] [sqlite TOO slow

2011-11-24 Thread Simon Slavin
On 24 Nov 2011, at 5:10pm, Jay A. Kreibich wrote: > On Thu, Nov 24, 2011 at 08:08:12AM +, Simon Slavin scratched on the wall: > >> It is faster to search integers than it is to search real numbers. > > Why? Both types are a string of 64 bits. Both types use the same > integer-based log

Re: [sqlite] [sqlite TOO slow

2011-11-24 Thread Jay A. Kreibich
On Thu, Nov 24, 2011 at 08:08:12AM +, Simon Slavin scratched on the wall: > It is faster to search integers than it is to search real numbers. Why? Both types are a string of 64 bits. Both types use the same integer-based logic for the =, <, and > operations. The only real differenc

Re: [sqlite] Checking for existence of in-memory tables

2011-11-24 Thread Kees Nuyt
On Thu, 24 Nov 2011 08:45:12 -0500, Dilip Ranganathan wrote: > Currently I use sqlite to create a bunch of on-disk tables to store my > data. I use Sqlite's master table to determine if a table already exists > based on which I take certain decisions. > > Suppose I switch these to in-memory table

Re: [sqlite] Aggregating Forex data

2011-11-24 Thread 雷钦
On 2011-11-24 08:02:21 +, Simon Slavin wrote: > > On 24 Nov 2011, at 7:42am, Rafael Garcia Leiva wrote: > > > CREATE TABLE eurusd ( > >date TEXT NOT NULL PRIMARY KEY, > >open REAL NOT NULL, > >high REAL NOT NULL, > >lowREAL NOT NULL, > >close REAL NOT NULL > > )

[sqlite] Checking for existence of in-memory tables

2011-11-24 Thread Dilip Ranganathan
Currently I use sqlite to create a bunch of on-disk tables to store my data. I use Sqlite's master table to determine if a table already exists based on which I take certain decisions. Suppose I switch these to in-memory tables (:memory:), how do I go about checking if a table exists? Do in-memory

Re: [sqlite] [sqlite TOO slow

2011-11-24 Thread Gaurav Vyas
Hi, I am gonna try first creating unique index (hid, pid). It will take a bit of time and will keep you posted with the result. Thanks a lot Gaurav On Thu, Nov 24, 2011 at 2:08 AM, Simon Slavin wrote: > > On 24 Nov 2011, at 7:54am, Gaurav Vyas wrote: > > > when I do typeof(hid), it gives "rea

Re: [sqlite] Smart merge

2011-11-24 Thread nadavius
Hi Simon, Thanks for the quick reply, Your solution worked flawlessly! I had to change the Trigger code by adding "FOR EACH ROW" (it would not accept it is a valid trigger else) Cheers, Nadav. nadavius wrote: > > Hi guys, > > I have two tables T1, T2 - identical in fields [Index1 (INT),

Re: [sqlite] [sqlite TOO slow

2011-11-24 Thread Simon Slavin
On 24 Nov 2011, at 7:54am, Gaurav Vyas wrote: > when I do typeof(hid), it gives "real". You might look into why it is not storing integers instead. It is faster to search integers than it is to search real numbers. The hid column in your table should probably be defined with a type of INTEGE

Re: [sqlite] [sqlite TOO slow

2011-11-24 Thread Simon Slavin
On 24 Nov 2011, at 7:56am, Gaurav Vyas wrote: > I used the following syntax to create index > "CREATE UNIQUE INDEX persons_1x > ON persons (pid,hid);" This index cannot be used for a search on your 'hid' column. Imagine you had it written out, and wanted to find all the records with the same '

Re: [sqlite] [sqlite TOO slow

2011-11-24 Thread Petite Abeille
On Nov 24, 2011, at 8:56 AM, Gaurav Vyas wrote: > I used the following syntax to create index > "CREATE UNIQUE INDEX persons_1x > ON persons (pid,hid);" Check you query plan (i.e. explain query plan [1]). I doubt such index has any use as SQLite doesn't support "index skip scans" access plan

Re: [sqlite] Aggregating Forex data

2011-11-24 Thread Simon Slavin
On 24 Nov 2011, at 7:42am, Rafael Garcia Leiva wrote: > CREATE TABLE eurusd ( >date TEXT NOT NULL PRIMARY KEY, >open REAL NOT NULL, >high REAL NOT NULL, >lowREAL NOT NULL, >close REAL NOT NULL > ); > > The granularity of the data is one minute, for example: > > IN