English 中文(简体)
Passing db path to l or .Q.l using a variable
原标题:
  • 时间:2011-07-04 13:44:15
  •  标签:
  • kdb
  • q-lang

I m writing a q script that loads a db in a particular path and does some processing on it. The location of the db is currently hardcoded in the script, but I want to pass the db path as an argument and get it to load from the path in the variable.

Currently it looks like this:

q) l /path/to/dbDir        #Works

I figured out that .Q.l should let us do this using a variable, so I tried using the following in the script,

dbPath:`$.z.x 0
.Q.l hsym dbPath            #Fails

When running with argument /path/to/dbDir, the script always fails with some unreadable stuff and:

 :/path/to/dbDir: No such file or directory

Could someone please help?

最佳回答

.Q.l is synonymous with l which only takes a single argument, which is not an hsym but a file or directory name.

Incidentally the unreadable stuff was the function definition, followed by a type error (as it was not expecting an hsym)

问题回答

x ... is always equivalent to system"x ...", which is the general solution to the "how do i pass a variable to a command question

in your case, you want

system"l ",.z.x 0

(btw, i don t think .Q.l is involved in l of code, only of data, so don t try to use it to load extra .q files)

Okay, it seems to work when we try .Q.l without the hsym like this:

dbPath:`$.z.x 0
.Q.l dbPath




相关问题
Concat string with number in kdb+ q

I can append a string with number. temp:30 text:"Current temperature is ",string temp show text type text Result "Current temperature is 30" 10h However, if I append one more ...

How do I save a program in kdb/q?

Most of the examples seem to be run in REPL mode. Is it possible to load myprog.q from disk?

Q (kdb): nested where query

What are the ways to in Q to use the results of a nested query in a where clause? I m looking for something similar to SQL statement. select from food where type_id in ( select type_id from ...

Passing db path to l or .Q.l using a variable

I m writing a q script that loads a db in a particular path and does some processing on it. The location of the db is currently hardcoded in the script, but I want to pass the db path as an argument ...

How to convert tic data to 5 minute OHLC?

I am learning KDB+ and have loaded the tic data into the table W as below. My question is, how to transfer the data into 5 (or n) minutes OHLCVA? "Stk_ID","Date","Time","Price","Chg","Vol","Amt","Ty" ...

KDB Find first date with data in each table of a process

I am trying to find first date where we have data available per process over IPC. I tried below but it isn t efficient. Is there a better way to find this? select min date from ({select date from x ...

热门标签