Skip to content

delete

Delete rows or columns from a table, entries from a dictionary, or objects from a namespace

delete    from x
delete    from x where pw
delete ps from x

delete is a qSQL query template and varies from regular q syntax

For the functional form of delete, see Functional qSQL.

If x is the name of a table, dictionary, or namespace as a symbol, delete updates it in place and returns the name. Otherwise it returns a modified copy.

Table rows

delete    from x
delete    from x where pw

Where

  • x is a table
  • pw is a condition

deletes from x the rows matching pw, or all rows if there is no Where phrase.

q)show t:([] a:`a`b`c; n:1 2 3)
a n
---
a 1
b 2
c 3
q)delete from t where a=`c
a n
---
a 1
b 2
q)delete from `t where a=`a
`t
q)t
a n
---
b 2
c 3

You can't combine a list of columns with a Where phrase.

q)delete n from t where a=`c
'nyi
  [0]  delete n from t where a=`c
                               ^

Deleting rows removes column attributes

Deleting rows removes the attributes of all columns, so reapply them as needed.

q)s:([] a:`s#1 2 3; b:4 5 6)
q)meta delete from s where a=2
c| t f a
-| -----
a| j
b| j

Table columns

delete ps from x

Where

  • x is a table
  • ps is a list of column names

deletes columns ps from x. The remaining columns keep their attributes.

q)show t:([] a:`a`b`c; n:1 2 3)
a n
---
a 1
b 2
c 3
q)delete n from t
a
-
a
b
c

You can't delete all the columns of a table.

q)delete a,n from t
'rank
  [0]  delete a,n from t
       ^

Dictionary entries

delete    from x
delete ps from x

Where

  • x is a dictionary
  • ps is a list of keys

deletes from x the entries for ps, or all entries if you omit ps. delete ignores keys in ps that are not in x.

q)show d:`a`b`c!til 3
a| 0
b| 1
c| 2
q)delete b,z from d
a| 0
c| 2
q)delete b from `d
`d
q)d
a| 0
c| 2

Namespace objects

delete    from x
delete ps from x

Where

  • x is the name of a namespace
  • ps is a symbol atom or vector of names defined in it

deletes the named objects from the namespace, or all objects if you omit ps.

q).test.a:1
q).test.b:2
q)key `.test
``a`b
q)delete a from `.test
`.test
q)key `.test
``b

qSQL expressions don't support Cond

Enclose the Cond expression in a lambda, or use Vector Conditional instead. See Cond in qSQL.


qSQL, Functional qSQL