cancel
Showing results for 
Search instead for 
Did you mean: 

Not understanding "sym" in "Q for Mortals" example

DevonMcC
New Contributor
Hi - I'm working through the examples in chapter 14 (Introduction to Kdb+) in Borror's "Q for Mortals" but am not able to replicate the example where we save, then load, a splayed table with an enumerated symbol column.

First we create and save the table:
q)`:/db/t/ set .Q.en[`:/db;] ([] s1:`a`b`c; v:10 20 30; s2:`x`y`z)

Then we exit and restart our q session and load the table:
q)\l /db
`db
q)sym
'2020.04.09T19:19:44.026 sym
  [0]  sym
       ^

This last step is meant to return the values of "sym".  This is on Windows 7.

Am I missing something?  Is the example missing something?

Thanks,

Devon
3 REPLIES 3

User
Not applicable
Hi Devon,

When you run the command 
`:/db/t/ set .Q.en[`:/db;] ([] s1:`a`b`c; v:10 20 30; s2:`x`y`z)

This will create a directory 't' (the table), along with a file called 'sym', in C:\db (when using windows). After you run the above command are you able to see these files have been created on disk?
You should be able to see the values in sym, as the \l command loads the sym file along with the table, into q from your /db directory. If you can't see the values it would seem the file was not created (in the directory you are loading at least). I would check if the files exist where you saved them, if not, perhaps your set command did not work, did you have any errors when saving?

If you run the below commands do you get anything returned?
q)get`:/db/sym
`a`b`c`x`y`z

q)get`:/db/t
s1 v  s2
--------
0  10 3
1  20 4
2  30 5


When running your save command, this will also create the sym variable in memory (.Q.en is what creates 'sym' in memory and on disk), after running it are you able to see the value of sym as below (this is without any load statements)
q)`:/db/t/ set .Q.en[`:/db;] ([] s1:`a`b`c; v:10 20 30; s2:`x`y`z)
`:/db/t/
q)sym
`a`b`c`x`y`z

Thanks,
Adam

DevonMcC
New Contributor
Hi - thanks for the reply.

I get exactly what you show in your examples.  The thing that does not work for me is the "\l /db" part in the QfM example after I exit and restart my q session.

Looking at it some more, I realize there may be an issue with q confusing my system drive C: with my working drive E:.  I seem to have near duplicates of the /db directory on both drives.

OK - if I remove the existing /db directories and re-do the example from scratch, it works.  It looks like there was pollution from leftover /db tables from earlier examples.

Thanks again!

> I realize there may be an issue with q confusing my system drive C: with my working drive E:

If you're on Windows you can avoid such problems by including a drive letter in the path, e.g. `:C:/db, `:E:/backup/db/sym etc. Please note that you have to use forward slashes, even on Windows.