1

I have a kdb table with column name type and want to select data by a giving type. It's like:

select from table where type=giving_type

it issues an error of : 'type, because type is a reserved word in q.

Then how to do this?

Thomas Smyth - Treliant
  • 4,993
  • 6
  • 25
  • 36
zjc
  • 11
  • 4
  • 2
    functional select or lookup via dictionary syntax (`table[\`giving_type]`) are your only choices. Best to avoid using keywords as column names, really – Manish Patel Nov 18 '16 at 13:04
  • While its technically possible to do this (solutions provided above and below), the behavior is undefined. Other built-in functions may fail. Its strongly recommended to choose another column name. – user2242865 Nov 18 '16 at 19:18
  • 1
    By the way .Q.id will fix these column names for you http://code.kx.com/wiki/DotQ/DotQDotid – Chromozorz Nov 20 '16 at 21:15
  • @Chromozorz, I don't known how to apply .Q.id on database on disk, and so I finally rebuild the whole database. – zjc Dec 05 '16 at 08:33
  • xcols/xcol will work on disk... `column`names xcol `:/path/to/partitioned/table – Chromozorz Dec 12 '16 at 15:31

2 Answers2

2

you could use a functional select:

?[`table;enlist (=;enlist `giving_type;`type);0b;()]
hellomichibye
  • 4,112
  • 2
  • 23
  • 23
0

Generally you should avoid using kdb reserved words such as "type" as the column name.

In this particular case where the table does have "type" as column name, functional select is the solution.

You can find the functional form of a select query via the parse function:

parse "select from table where type=giving_type"

clony
  • 136
  • 2