Thread Subject:
SQL

Subject: SQL

From: james bejon

Date: 7 Mar, 2011 21:07:04

Message: 1 of 6

Dear All,

I have an application which uses the database toolbox to repeatedly query a plain text file using SQL. (Frustratingly, I can't find the code I modified to do this, but it was on the mathworks.com site. The key requirement was creating a schema.ini file, so Matlab knows which columns contain which kinds of variable).

Anyway, in total, each run of the application requires about 100 SQL queries. However, the network I'm using is pretty slow; so this is a fairly time consuming process. The question, then, is as follows. Is there a way of using SQL to query a Matlab variable (as opposed to a text file or database table). Can I, for instance, load up the data file as a cell and then point the SQL query at the cell?

Thanks,

James.

Subject: SQL

From: Kirill

Date: 8 Mar, 2011 03:42:00

Message: 2 of 6

I don’t think so. Unless somebody will write a driver for it.
Running queries on plain text file is usually quite slow because
driver needs to run full file scan. I would load data into database
e.g. Access and create indices for the queried variables – this should
increase performance dramatically.

BTW, here is connection strings to a CSV file:

DRIVER={Microsoft Text Driver (*.txt; *.csv)};DBQ=\\server\folder

and a query

select MyVar from MyTable.csv where … and so on and so forth …

Kirill

Subject: SQL

From: Husam Aldahiyat

Date: 8 Mar, 2011 05:26:04

Message: 3 of 6

"james bejon" wrote in message <il3hdo$a57$1@fred.mathworks.com>...
> Dear All,
>
> I have an application which uses the database toolbox to repeatedly query a plain text file using SQL. (Frustratingly, I can't find the code I modified to do this, but it was on the mathworks.com site. The key requirement was creating a schema.ini file, so Matlab knows which columns contain which kinds of variable).
>
> Anyway, in total, each run of the application requires about 100 SQL queries. However, the network I'm using is pretty slow; so this is a fairly time consuming process. The question, then, is as follows. Is there a way of using SQL to query a Matlab variable (as opposed to a text file or database table). Can I, for instance, load up the data file as a cell and then point the SQL query at the cell?
>
> Thanks,
>
> James.

If you have enough memory then I suppose you could perform the query 'select *' to import the table into MATLAB. Then, you could replace the 100 queries with MATLAB commands.

Subject: SQL

From: james bejon

Date: 8 Mar, 2011 07:25:04

Message: 4 of 6

Thanks to both of you.

@Husam: Yes, true enough. I just like using the SQL because: a] it's quite easy, and b] as the application runs, it makes a log of the SQL it generates, which is then very easy to check/debug.

@Kirill: OK, I'll give that a go. I didn't realise it would make a difference, but what you're saying makes sense.

Subject: SQL

From: james bejon

Date: 8 Mar, 2011 23:01:20

Message: 5 of 6

Hmmm...have changed the code so it points to an Access database (and indexed the table). Unfortunately, however, there's no improvement speed-wise.

Subject: SQL

From: Kirill

Date: 11 Mar, 2011 17:18:15

Message: 6 of 6

If your CSV files is not very big, say less than 10-100MB, you may
lose time on overhead: network, compiling queries, connection to the
database etc. You may run profiler to check. In this case it would
be faster to load entire file in the memory and manipulate it with
Matlab commands.

There are also exotic solutions like mounting a disk in computer
memory, copy database there and manipulate it with SQL queries.
Should work too, I guess.

Kirill

Tags for this Thread

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

rssFeed for this Thread

Contact us