t.column not working?

Why can’t the table address this column?

p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #d0d2da; background-color: #161821; background-color: rgba(22, 24, 33, 0.95)}span.s1 {font-variant-ligatures: no-common-ligatures}

q))meta t

c    | t f a

-----| -----

stock| s    

name | s    

q))t.stock

't.stock

  [3]  t.stock

       ^

Hi,

It could be that inside the error trap you aren’t referencing the actual table. Is “t” just the variable that represents the table inside a function?

q)tab

stock name


test  ross

q)

q)

q)f1 `test

'length

  [1]  f1:{tab upsert x}

               ^

q))

q))meta tab

c    | t f a

-----| -----

stock| s

name | s

q))

q))

q))tab.stock

,`test

q))

q)f2 tab

'length

  [1]  f2:{x upsert (“test”;“ross”)}

             ^

q))meta x

c    | t f a

-----| -----

stock| s

name | s

q))

q))

q))x.stock

'x.stock

  [3]  x.stock

Using the function f1, I was able to access the columns using tab directly. However it seems that using tab as the input “x” I am unable to address the columns. As to why this is exactly I’m not 100%, but it appears that without using the table directly q is unable to locate the table to address the columns, in this way.

Hope this helps (if only a little)

Ross

As an alternative,

Within thesecond function, you could access the column using x`stock e.g.<o:p></o:p>

<o:p> </o:p>

q)tab:( stock:1#test;name:1#ross)<o:p></o:p>

q){x upsert (“test”;“ross”)}tab<o:p></o:p>

'length<o:p></o:p>

  [1]  {x upsert(“test”;“ross”)}<o:p></o:p>

         ^<o:p></o:p>

q))x.stock<o:p></o:p>

'x.stock<o:p></o:p>

  [3]  x.stock<o:p></o:p>

       ^<o:p></o:p>

q))x`stock<o:p></o:p>

,`test<o:p></o:p>

On Monday, January 15, 2018 at 10:26:07 AM UTC, Ross Edens wrote:

Hi,

It could be that inside the error trap you aren’t referencing the actual table. Is “t” just the variable that represents the table inside a function?

q)tab

stock name


test  ross

q)

q)

q)f1 `test

'length

  [1]  f1:{tab upsert x}

               ^

q))

q))meta tab

c    | t f a

-----| -----

stock| s

name | s

q))

q))

q))tab.stock

,`test

q))

q)f2 tab

'length

  [1]  f2:{x upsert (“test”;“ross”)}

             ^

q))meta x

c    | t f a

-----| -----

stock| s

name | s

q))

q))

q))x.stock

'x.stock

  [3]  x.stock

Using the function f1, I was able to access the columns using tab directly. However it seems that using tab as the input “x” I am unable to address the columns. As to why this is exactly I’m not 100%, but it appears that without using the table directly q is unable to locate the table to address the columns, in this way.

Hope this helps (if only a little)

Ross

Dot notation only works on globals, it looks like your “t” is a local variable. 

You could instead use

q){ x.col1}[tab]

{ x.col1}

'x.col1

q))\

q){ x`col1}[tab]

ab`c

Assuming your table is not keyed. 

Terry

Ross & Terry,

if table t is assigned in a function I assume dot notation should work in that function! 

foo2 results in an error and foo3, though very similar, does not result in an error

Is there a page in the documentation that discusses dot vs. tick notation? 

Until I understand more it seems that the safest thing to do is use `tick notation to reference a column inside a function.

-Anuj

p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #d0d2da; background-color: #161821; background-color: rgba(22, 24, 33, 0.95)}span.s1 {font-variant-ligatures: no-common-ligatures}

q)foo2:{t:flip symnamesector!("SSS";";")0:sp500.csv; tf:t.sym}

q)foo2

't.sym

  [1]  foo2:{t:flip symnamesector!("SSS";";")0:sp500.csv; tf:t.sym}

                                                                    ^

q))foo3:{ t:(a:1,2;b:3,4); t.a}

q))foo3

1 2

q))foo4:{t:flip symnamesector!("SSS";";")0:sp500.csv; tf:t`sym}

q))foo4

AAALAAPAAPLABBVABCABTACNADBEADIADMADPADSADSKAEEAEPAESAETAFLAGNAIGAIVAIZAJGAKAMALBALGNALKALLALLEALXNAMATAMDAMEAMGAMGNAMPAMTAMZNANDVANSSA..

Hi ag,

I believe that as foo3 was called whilst still in break mode i.e. q)), it could access table t directly and run successfully. If you exit break mode and try, it should fail just like foo2. e.g.

q)foo3:{ t:(a:1,2;b:3,4); t.a}

q)foo3

't.a

  [1]  foo3:{ t:(a:1,2;b:3,4); t.a}

As for documentation the following links may be helpful, although a definitive answer as to why dot notation works in this way appears hard to come by:

http://code.kx.com/q4m3/2_Basic_Data_Types_Atoms/#257-constituents-and-dot-notation

https://stackoverflow.com/questions/24423100/dot-notation-with-dates

Hope this helps,

Ross

I think foo3 worked because you have a global t table lying around and it accessed that. 

Check 

q)t in key .

If it’s true then you have a global that it’s accessing, not the local. Delete the global and try again and I imagine foo3 would fail

q)delete t from .

Terry

Yes sorry,

Ignore the part about break mode for foo3. It is likely you have a global t that it is accessing as Terry said.

Ross