# Parametric table name?

**URL:** <https://forum.kx.com/t/parametric-table-name/9801>\
**Category:** Community Support\
**Tags:** kdb-and-q\
**Created:** [May 8, 2015, 4:46pm UTC](https://forum.kx.com/t/parametric-table-name/9801 "2015-05-08T16:46:00Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![reactgary](https://avatars.discourse-cdn.com/v4/letter/r/50afbb/32.png) [@reactgary](https://forum.kx.com/u/reactgary)\
**Post date:** [May 8, 2015, 4:46pm UTC](https://forum.kx.com/t/parametric-table-name/9801/1 "2015-05-08T16:46:00Z")

</div>

Hi,

I wonder if there is a way to create parametric table (i.e. using the string store in a variable as the table name of a table).

For example in a master table I have something like this.

masterTable

instrutment\_id | sym

* * *

1001 | `AAA

1002 | `BBB

1003 | `CCC&nbsp;

Now for every stock in the master table, I would like to make a table to hold its order book. So I would like to make a few table, and I would like to have their names as

AAABook

BBBBook

CCCBook..

etc.

Any suggestions on how I can achieve this without interfacing with an external language?

Appreciate any helps.

Gary&nbsp;

---

<div class="post-metadata">

**Author:** ![pressjonny0](https://avatars.discourse-cdn.com/v4/letter/p/ccd318/32.png) [@pressjonny0](https://forum.kx.com/u/pressjonny0)\
**Post date:** [May 8, 2015, 4:50pm UTC](https://forum.kx.com/t/parametric-table-name/9801/2 "2015-05-08T16:50:00Z")

</div>

q)mas:(id:1001 1002 1003;sym:`AAA`BBB`CCC)&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;

q){@[`.;`$string,“Book”;:;(a:();b:())]} each exec sym from mas &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;

`.`.`.

q)\a&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;

`AAABook`BBBBook`CCCBook`mas

q)AAABook &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;

a b

* * *

>

---

<div class="post-metadata">

**Author:** ![reactgary](https://avatars.discourse-cdn.com/v4/letter/r/50afbb/32.png) [@reactgary](https://forum.kx.com/u/reactgary)\
**Post date:** [May 8, 2015, 7:28pm UTC](https://forum.kx.com/t/parametric-table-name/9801/3 "2015-05-08T19:28:00Z")

</div>

Thanks Jonny,

I am new to kdb so wondering what does it mean by `. in the second statement.

Also is it a protected execution or a functional @ apply? I read the q for mortal and couldn’t find any clue…

Or are there other material mentioned this better?

Thanks

Gary

---

<div class="post-metadata">

**Author:** ![david\_demner](https://avatars.discourse-cdn.com/v4/letter/d/7993a0/32.png) [@david\_demner](https://forum.kx.com/u/david_demner)\
**Post date:** [May 8, 2015, 7:53pm UTC](https://forum.kx.com/t/parametric-table-name/9801/4 "2015-05-08T19:53:00Z")

</div>

@ is amend and `. refers to the global context so youre effectively amending the global text\<o:p\>\</o:p\>

\<o:p\> \</o:p\>

Another to write it would be\<o:p\>\</o:p\>

\<o:p\> \</o:p\>

q){(`$string,“Book”) set (a:();b:())} each exec sym from mas\<o:p\>\</o:p\>

`AAABook`BBBBook`CCCBook\<o:p\>\</o:p\>

\<o:p\> \</o:p\>

\<o:p\> \</o:p\>

\<o:p\> \</o:p\>

**From:** [personal-kdbplus@googlegroups.com](mailto:personal-kdbplus@googlegroups.com) [[mailto:personal-kdbplus@googlegroups.com](mailto:personal-kdbplus@googlegroups.com)] **On Behalf Of** Gary Chow  
**Sent:** Friday, May 8, 2015 11:29 AM  
**To:** [personal-kdbplus@googlegroups.com](mailto:personal-kdbplus@googlegroups.com)  
**Subject:** Re: [personal kdb+] Parametric table name?\<o:p\>\</o:p\>

\<o:p\> \</o:p\>

Thanks Jonny,\<o:p\>\</o:p\>

\<o:p\> \</o:p\>

I am new to kdb so wondering what does it mean by `. in the second statement.\<o:p\>\</o:p\>

Also is it a protected execution or a functional @ apply? I read the q for mortal and couldn’t find any clue…\<o:p\>\</o:p\>

\<o:p\> \</o:p\>

Or are there other material mentioned this better?\<o:p\>\</o:p\>

\<o:p\> \</o:p\>

Thanks\<o:p\>\</o:p\>

\<o:p\> \</o:p\>

Gary

---

<div class="post-metadata">

**Author:** ![Enoch\_Lam](https://avatars.discourse-cdn.com/v4/letter/e/eada6e/32.png) [@Enoch\_Lam](https://forum.kx.com/u/Enoch_Lam)\
**Post date:** [May 9, 2015, 3:19am UTC](https://forum.kx.com/t/parametric-table-name/9801/5 "2015-05-09T03:19:00Z")

</div>

It is an apply, the backtick means the root namespace.

---

<div class="post-metadata">

**Author:** ![reactgary](https://avatars.discourse-cdn.com/v4/letter/r/50afbb/32.png) [@reactgary](https://forum.kx.com/u/reactgary)\
**Post date:** [May 9, 2015, 9:05am UTC](https://forum.kx.com/t/parametric-table-name/9801/6 "2015-05-09T09:05:00Z")

</div>

On Saturday, May 9, 2015 at 10:19:57 AM UTC+8, Enoch Lam wrote:

> It is an apply, the backtick means the root namespace.

Thanks Enoch and Jonny!&nbsp;

---

<div class="post-metadata">

**Author:** ![reactgary](https://avatars.discourse-cdn.com/v4/letter/r/50afbb/32.png) [@reactgary](https://forum.kx.com/u/reactgary)\
**Post date:** [May 9, 2015, 11:47am UTC](https://forum.kx.com/t/parametric-table-name/9801/7 "2015-05-09T11:47:00Z")

</div>

Hi Enoch,

Thank you very much for your reply

So the bracket () in

(aaa) set value

sort of act as the dereferencing, and value will be assigned to the variable name stored as symbol in the variable name. Am I correct.

So now I have a further question. Is the bracket () in the statement specific to the verb “set”, or does it work in similar way in some other verb too? Or is it itself some sort of adverb or verb?

Thanks so much.

Gary

---

<div class="post-metadata">

**Author:** ![josepablocam](https://avatars.discourse-cdn.com/v4/letter/j/85f322/32.png) [@josepablocam](https://forum.kx.com/u/josepablocam)\
**Post date:** [May 10, 2015, 7:03pm UTC](https://forum.kx.com/t/parametric-table-name/9801/8 "2015-05-10T19:03:00Z")

</div>

Gary,

not quite. (…) isn’t doing anything special beyond grouping elements in the expression to make sure that things evaluate correctly. If you have `somesym set …, this works fine, but if you wanted to build the name out of a string (which requires that you cast to symbol before setting) then you need the parenthesis there to make sure it casts to symbol first. Otherwise, you end up trying to set with your left-operand as string and casting the result to a symbol, which results in a type error. For example

q)`$“this” set 1

'type

q)(`$“this”) set 1

`this

Hope this helps
