Syntax Question

Currently the trades table has a trade_id identifier which is a character vector type.
Notice that all trade_id’s are of a different format. Some numerical, others alphanumeric.
Update the table to add a GUID identifier column called global_id. This will ensure uniqueness,
storage efficiency, and will provide better query performance. How can the trades table be
updated to add this column.

I answered: update global_id:count[trades]?0Ng from trades

But I was told the correct answer is: update global_id:count[trades]?0Ng from `trades

Why the tick mark on the trades table? The rest of the logic makes sense, but I thought ` was reserved for symbols or file paths. Thanks!

See: QSQL query templates | Basics | kdb+ and q documentation - kdb+ and q documentation

  • table is passing the value
  • `table is passing the name (of a global variable)

by name, the table or dictionary is amended in place (in memory or on disk) as a side effect, and its name returned as the result

q)trades:([] a:1 2)

// By value - returns result
q)update b:3 4 from trades
a b
---
1 3
2 4
// Change not persisted
q)trades
a
-
1
2

//--------------------------------
// By name - returns name
q)update b:3 4 from `trades
`trades

// Change persisted
q)trades
a b
---
1 3
2 4
q)

Omitting the backtick and running that command would give return the trade table with the global_id column added, but it would not be persisted in the trades table

update global_id:count[trades]?0Ng from trades

The backtick in front of trades will persist the result in the trades table

update global_id:count[trades]?0Ng from `trades

See this link for more info