cancel
Showing results for 
Search instead for 
Did you mean: 

Tables in conditional evaluation

Daniel_o_keeffe
New Contributor
I'm trying to exectute a simple conditional evaluation statement. I have a table t listed in tables[].

 $ [t; [action one]; [action two]

I keep getting a type error. Is there some unique way to use tables in conditional evaluation?? I've tried if t not null, t in tables[],  count t > 0, etc, It keeps giving me the same error.  Evaluation works for variables but I can't get it to recognise the table, and this is the only way I can think to get the function to work.

I just need to check if the table exists. i know this is probably pretty simple i just can't figure it out.

All help appreciated.
6 REPLIES 6

charlie
New Contributor II
New Contributor II
q)$[`t in key `.;`present;`missing]
`missing
q)t:([]a:0 1)
q)$[`t in key `.;`present;`missing]
`present
or with tables[] cmd

q)$[`t in tables[];`present;`missing]
`present
q)delete t from `.;
q)$[`t in tables[];`present;`missing]
`missing



showvik
New Contributor

You can use .Q.qt also to know if its table or not. It returns bollean result.

On May 12, 2014 12:32 AM, "Daniel o keeffe" <doktordiversity@gmail.com> wrote:
>
> I'm trying to exectute a simple conditional evaluation statement. I have a table t listed in tables[].
>
>  $ [t; [action one]; [action two]
>
> I keep getting a type error. Is there some unique way to use tables in conditional evaluation?? I've tried if t not null, t in tables[],  count t > 0, etc, It keeps giving me the same error.  Evaluation works for variables but I can't get it to recognise the table, and this is the only way I can think to get the function to work.
>
> I just need to check if the table exists. i know this is probably pretty simple i just can't figure it out.
>
> All help appreciated.
>
> --
> You received this message because you are subscribed to the Google Groups "Kdb+ Personal Developers" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to personal-kdbplus+unsubscribe@googlegroups.com.
> To post to this group, send email to personal-kdbplus@googlegroups.com.
> Visit this group at http://groups.google.com/group/personal-kdbplus.
> For more options, visit https://groups.google.com/d/optout.

manni_patel
New Contributor

$[count tableName;...

q)a:([]a:`a`b`c;b:1 2 3)
q)
q)
q)a
a b
---
a 1
b 2
c 3
q)$[`a in tables`;`true;`false]
`true
q)

Daniel_o_keeffe
New Contributor
Thanks guys. It was, inevitably, a backtick before the tablename. But I'd still be here clueless if it wasn't pointed out:)

Just out of interest, the difference between tables in system "a" and system "b", a being function local and b being global is that about it?? If tables[] is system "a" I assume there is an alternative command for system "b"? Its just when i define a table in my function I don't see why it should still be available outside the function, wheras variables are not.


Thanks

sohagan
New Contributor
system"b" is not tables its views, equivalent to views[], or \b.
http://code.kx.com/wiki/Reference/SystemCommands#.5Cb_-_views.2Fdependencies
http://code.kx.com/wiki/Reference/view
http://code.kx.com/wiki/Reference/views

HTH,
Sean