Fanatic23
Fanatic23

Reputation: 3428

SQL in KDB or am I crazy?

I am trying to see if I can use KDB for some of my current work. I have a fair bit of code in legacy SQL and prospect of reuse seems exciting.

Which is when I came across: http://code.kx.com/q/interfaces/q-client-for-odbc/

This link only speaks of SQL select - is it OK to use this for insert and delete as well? What about performance?

Upvotes: 2

Views: 2458

Answers (2)

xbsd
xbsd

Reputation: 2538

It is seldom used, but there is a way to use ANSI SQL with KDB. Just prefix the query with s)

q)t:([]col1:1 1 2 2;col2:10 10 20 20; col3:5.0 2.0 2.3 2.4; grp:aabc)

q)t
col1 col2 col3 grp`
------------------
1    10   5    a  
1    10   2    a  
2    20   2.3  b  
2    20   2.4  c

q) /standard select
q)select from t
col1 col2 col3 grp
------------------`
1    10   5    a  
1    10   2    a  
2    20   2.3  b  
2    20   2.4  c

q)/SQL type select with select *
q)select * from t
'rank

q) /Prefix the query with s)
q)s)select * from t
col1 col2 col3 grp
------------------
1    10   5    a  
1    10   2    a  
2    20   2.3  b  
2    20   2.4  c

Now - this feature is rarely used and the parser is not optimized for this type of usage and resources are scarce. You'd probably spend more time debugging issues with this than you would just by converting your code to Q. Hope this helps.

Another option is to use the qodbc server -- http://code.kx.com/q/interfaces/q-server-for-odbc/

Upvotes: 3

IMSoP
IMSoP

Reputation: 97718

Based on your question, I'm not sure this will do what you are hoping for. You seem to want to reuse SQL code on a non-SQL database.

This driver does not run SQL against the current database, it allows you to connect to an external database, and pull back data using the SQL capability of that other database. (ODBC is a standardised driver system for connecting to various kinds of databases, sending queries, and returning data).

This would only be useful if you intended to leave two different databases running side-by-side, and needed them to interact at the database level (rather than, as @millimoose mentions above, connecting to them individually from your application).

Upvotes: 3

Related Questions