Q3) Is there any way of inserting a record into table a that inserts ONLY the primary key columns? The other columns can be filled with the default nulls of the corresponding types.
Hi Yuva,On Jul 15, 10:03 am, “Yuvaraj Athur Raghuvir” <yuvaraj…>wrote:> Q1) What is the q way of deducing that in table a the key combination> (first,3) and (third,3) do not exist?I suppose you want a boolean expression? Perhaps this may help:q)(first;3) in key a0bq)(first;1) in key a1b> Q2) What is the error here? I donot understand why q accepts the assignment> but then flags an error on display.q)$"third" 3 / juxtaposition of symbol with number results inindexing:rq)r1:bc!(third;3) / this is probably what you wantq)r1b| thirdc| 3> Q3) Is there any way of inserting a record into table a that inserts ONLY> the primary key columns? The other columns can be filled with the default> nulls of the corresponding types.q)a upsert r1 / this works once r1 is correctly definedaq)ab c| d--------| -------------first 1| "first item"second 2| "second item"third 3| ""Regarding Q2, I do find the following strange:q)a:1 2 3!1’lengthq)a:1 2 3!`bq)count each (key a; value a)3 1Why are symbols treated differently?Swee Heng</yuvaraj…>
> Regarding Q2, I do find the following strange:
> q)a:1 2 3!1
> 'length
> q)a:1 2 3!`b
> q)count each (key a; value a)
> 3 1
> Why are symbols treated differently?
let’s start from a bit further away
let’s assume you have a splayed directory with some data
for example i created one with tq.q
q)trade
date sym time price size ex
2000.10.02 A 09:30:00.212 1.606254 5 N
2000.10.02 A 09:30:00.224 1.462639 6 N
2000.10.02 A 09:30:00.285 1.782938 3 T
2000.10.02 A 09:30:00.333 2.024403 4 A
2000.10.02 A 09:30:00.413 0.9263389 7 T
2000.10.02 A 09:30:00.443 2.185805 6 T
2000.10.02 A 09:30:00.480 1.840109 0 N
2000.10.02 A 09:30:00.503 0.2203833 4 N
2000.10.02 A 09:30:00.519 1.729938 8 A
2000.10.02 A 09:30:00.528 1.222748 3 A
2000.10.02 A 09:30:00.681 2.213026 2 N
2000.10.02 A 09:30:01.153 1.799983 8 T
2000.10.02 A 09:30:01.313 2.135237 3 A
2000.10.02 A 09:30:01.417 0.7201118 8 A
2000.10.02 A 09:30:01.663 0.5424215 2 T
2000.10.02 A 09:30:01.802 0.1014145 1 T
2000.10.02 A 09:30:02.053 1.174131 2 N
2000.10.02 A 09:30:02.100 1.542879 5 N
2000.10.02 A 09:30:02.119 0.04559833 7 A
2000.10.02 A 09:30:02.192 0.086009 0 T
..
in k though:
q)\
trade
+symtimepricesizeex!trade
that’s weird - looks like column-names map to tablename (list to atom)
let’s check it is what it looks
+trade symtimepricesizeex!trade
!+trade symtimepricesizeex .+trade trade
@.+trade
-11h /so it is indeed a symbol atom
can we make a structure like that in q?
q)ab!e k){$[99h=@y;sublist[x;!y]!sublist[x;. y];~0\>@x;$[.Q.qp y;.Q.ind[y];y]i+!"i"$x[1]&(#y)-i:\*x;abs[x]\<#y;x#y;y]} 'e @ e
,0j
q))\ /no luck yet
q)symtimepricesizeex!trade /let’s try sg we know is already there
k){x[y]z}
'par
@ trade sym /different error message
q))\
q)
q)flipsymtimepricesizeex!trade
date sym time price size ex
2000.10.02 A 09:30:00.212 1.606254 5 N
2000.10.02 A 09:30:00.224 1.462639 6 N
2000.10.02 A 09:30:00.285 1.782938 3 T
2000.10.02 A 09:30:00.333 2.024403 4 A
2000.10.02 A 09:30:00.413 0.9263389 7 T
2000.10.02 A 09:30:00.443 2.185805 6 T
2000.10.02 A 09:30:00.480 1.840109 0 N
2000.10.02 A 09:30:00.503 0.2203833 4 N
2000.10.02 A 09:30:00.519 1.729938 8 A
2000.10.02 A 09:30:00.528 1.222748 3 A
2000.10.02 A 09:30:00.681 2.213026 2 N
2000.10.02 A 09:30:01.153 1.799983 8 T
2000.10.02 A 09:30:01.313 2.135237 3 A
2000.10.02 A 09:30:01.417 0.7201118 8 A
2000.10.02 A 09:30:01.663 0.5424215 2 T
2000.10.02 A 09:30:01.802 0.1014145 1 T
2000.10.02 A 09:30:02.053 1.174131 2 N
2000.10.02 A 09:30:02.100 1.542879 5 N
2000.10.02 A 09:30:02.119 0.04559833 7 A
2000.10.02 A 09:30:02.192 0.086009 0 T
..
cool. we needed the flip
what about our simple example?
q)flipab!c k){+(!+. x)!/:dd[y;z],x}
'c
.:
`c
q))\ /a third error message
we might get the idea that the problem is printing
q)flipab!c; q)ab!c; /and we are right
q)a:ab!`c /no printing here either
so back to original question
my _guess_ is that
q)a:1 2!c or q)1 2!c;
is not an error because a check for the type of the key in this
special case is omitted
q)1 2!c k){$[99h=@y;sublist[x;!y]!sublist[x;. y];~0\>@x;$[.Q.qp y;.Q.ind[y];y]i+!"i"$x[1]&(#y)-i:\*x;abs[x]\<#y;x#y;y]} 'c @ c
,0j
q))\