Showing results for 
Search instead for 
Did you mean: 

what's the use of 'resolving a foreign key'? (from enum to

New Contributor
Hi guys, 

working my way through through Q for Mortals, and have a question on

Followed along and setup a foreign key from `tdetails` pointing to `kt`

then following the tutorial: 

When you wish to resolve a foreign key – i.e., get the actual values instead of enumerated values – apply value to the enumerated column.

q)meta update value eid from tdetailsc  | t f a---| -----eid| j    sc | j    

Observe that there is no longer an entry in the f column.


What is the use of the above command? 

Even without doing `meta update value eid from tdetails` I I can query `tdetails` using dot notation, e.g.: select, sc from tdetails  and automatically get `name` merged in from the  `kt`-table. This seems to be the same as after doing the above command. 

I've read that enums and their underlying values are not the same (which makes perfect sense), but they behave the same in almost any context. So what's the use of explicitly translating enums to values using the above? Moreover, when changing anything about the enums (adding an enum for example) would I need to rerun this command? 




New Contributor II

There are a few reasons why you might want to resolve a foreign key:

1.       You might want to persist the table to disk and not require the dependency on the other table (if you persisted the tdetails table without persisting the kt table in the same database then you’d have an un-resolvable column)

2.       meta doesn’t tell the whole story as the types are very different:

q)type each flip tdetails

eid| 21

sc | 7

q)type each flip update value eid from tdetails

eid| 7

sc | 7

                You might require type 7 for compatibility/consistency with something else.