ksql

assign		v: ...
view		view v ...   (e.g. alternate key:  view u 'a'key t)
			view t.b a+2 (but can't insert on column views)
(\\i v to see antecedents and dependents of v)

literal		int(2) float(2.3) varchar('don''t') varbinary(0x616263)

datetime	date'1998-12-31' time'12:34:56' timestamp'2000-01-03 12:34:56'
 absolute	timestamp second hour minute date week month quarter half year
 relative	time hhmmss hhmm hh     day'mon'      mth'jan' qtr'q1' hlf'h1'
 translate	absolute.{absolute | relative} e.g. date.quarter second.day etc.
 dateadd	date {+ | -} n {months | quarters | halfs | years} e.g. d+3 months

function	\f:{...}	/ table[`field] (table.field causes reference error)
function call	f[x](or f x) f[x,y] ...

list		(...,...)
create table	([key's]var's)	e.g. t:([f:('a','b')]g:(2,3))
access field	t[key's].field	e.g. t['b'].g

 select f's <by g's> from t where c's		
 update f's <by g's> from t where c's
 delete from t where c's	# delete rows
 delete f's from t			# delete cols
 t {insert|+|-|min|max} u	# update old; append new
 t insert1 u				# append only (doesn't check key)
 t insert2 u				# update only (discard new)

fields that name tables are eponymous fkey.
select, update, insert and create scalar extend.
update, delete and insert amend(no result) iff 't'.

 <field's> key 't'
 <(field's,table's)> fkey 't'
 <field> asc 't'
 <field's> index 't'

key and fkey enable select f.g from t(and t[f].g)
asc and index enable fast lookup(f[...]= within in t[f].g)
asc and index are for readonly tables. redo after insert.
index for repeats. '' index 't' to clear all indices

field
 translate		fkey.field (also table[key's].field)
 reference		table.field (also . table for single field)
 
function
 aggregate
  monadic		count avg sum sumf prd min max first last variance deviation median
  dyadic		<weights>avg <weights>sum covariance correlation
 atomic
  monadic		- not abs exp log sqr sqrt sin cos tan floor ceiling null lower upper trim
  dyadic		+(also strings) - * / % min max exp log < = > <= <> >= and or like fill
  other			in(list) within(low,high) (buckets){floor|ceiling} (i[,n])substring
 uniform
  integrate		<moving>sums prds <moving>avgs <moving>mins <moving>maxs <init>fills
  differentiate		<init>deltas <init>ratios prev next <n>rank
  parallel		f each  f eachleft  f eachright
 list/table		reverse <f>asc <f>desc <n>first <n>last <n>drop <n>rand skew enlist at
			distinct union intersect not cross table 'f'last
 meta			meta <f's>vars <f's>key <(f's,t's)>fkey <f's>index

niladic			$ tables views funcs keywords
			current_date current_time current_timestamp current_user current_database

BNF(<x> is optional; x's is commalist) 
<: | v: | view v | :> e | {load|save|show}''
 e	d | d e | f e | d f e | delete {v's <from e> | from e <where e's>}
      | {select | update} <{a|e}'s> <by {a|e}'s> <from e> <where e's>
 d	literal | v | d.v | d[e's] | (e's) | ([a's] a's) | c | niladic
 f	function | f {each | eachleft | eachright}
 c	case <e> {when e then e}+ <else e> end
 a	<fkey>v:e
 v	variable

vars''(or't')	# list of variables(in 't')
meta''(or't')	# table of vars and types(in 't')
show''(or't')	# show kdb viewer(or 't')
save'd.kdb'	# database(checkpoint: save'') or table(csv txt l)
load'd.kdb'	# database(kdb mdf mdb dsn xls), script(s t) or table(csv txt l dbf)
''fkey''	# heuristic fkey all tables
:...		# milliseconds to execute ...

create tables with [key's] and fkeys
emp:([emp:('a','j')]emp boss:('j','j'),salary:(2,1))
select from emp where salary>boss.salary

load tables with:
 ('types','delim')load file  # names in first row
 ('names','types','delim')load file
 types are 'IFSDTZ' for int,float,symbol(varchar),date,time,timestamp

save tables|splayed with:
 'dir'{save|rsave}t's

upsert tables with union, +, -, min, max
t:([k:('a','b')]r:(2,3))
u:([k:('a','c')]r:(5,6))
t union u
t+u
t-u
t min u
t max u

t union|not|intersect y		treat list y as single record
table x     # make table out of atom,list,dict(or table)

expand tables with insert and fills
t:([date:(1,4)]qty:(2,5))
update 0 fills qty from([date:asc 6])insert t

generate random data
 <n>rand list	# from list
 <n>rand i	# from [0,i)
 <n>rand f	# from [0,f)
 <n>rand ''	# random varchar(11)
 <n>rand '  '	# random varchar(2) ...
(-n)rand x	# distinct
  n skew w	# skewed according to weights w

nulls(0N 0n)
ksql: null arithmetic; 2-value logic(nulls compare <)
ansi: null arithmetic; 3-value logic; sum avg min max ignore nulls

x fill y	# atomic
<x>fills y	# integral (backfills first non-null)
'case' executes all the pieces

utilities

.d.l`         ksql console

.d.r"..."     execute string/(f;args)/(enum;values)
 .d.r(`load;,`sp.s)
 .d.r(`insert;(`sp;(`s9;`p9;2)))
 i.e. .d.r calls all ksql routines

.d.vex[dir]   directory exist?

strings:.d.cut[",";string]
string:.d.join[",";strings]

.d.sd	string from date       .d.ds	date from string
.d.st	string from time       .d.ts	time from string
.d.sz	string from timestamp  .d.zs	timestamp from string

t:.d.tk[1;.+(`a`b;(`w`e`r;(();();())))]
.d.upsert[,;t;(`e;2 3)] / also :+*&|
