how to append a row to a table

How to append a row to a q table?

cheers

dinesh

http://code.kx.com/wiki/JB:QforMortals2/queries_q_sql#Insert

Showvik

Hi ,

?

?

If?u want to append all the rows of a table into another table then :

?

q)tab1: (a: 2 3 4; b: 5 6 7; c: 89 78 67)
q)tab1
a b c

2 5 89
3 6 78
4 7 67
q)tab2: (a: 6 7 8 ;b: 89 87 67; c:12 34 23)
q)tab3: tab1 , tab2
q)show tab3
a b? c

2 5? 89
3 6? 78
4 7? 67
6 89 12
7 87 34
8 67 23

?

But above is the case in which you can only append the row if the column name are same.?but if your column name are different then:

q)tab4: (x: 2 4 6; y: 4 6 8; z: 7 9 3)
q)tab1,tab4
'mismatch??? --------> Error?
q)tab1 , 'tab4
a b c? x y z

2 5 89 2 4 7
3 6 78 4 6 9
4 7 67 6 8 3

?

The above statement is?true for?appending one table columns to another.

?

again another one is upsert: which is always use for update the existing table row and insert new row into table:

?

q)t1:(x:1 2 3; y:4 5 6; z:10 20 30)

q)t1 upsert (x: enlist 4; y:enlist 10; z:enlist 30)
x y? z

1 4? 10
2 5? 20
3 6? 30
4 10 30

?

?

Thanks

Hari Om

?