# Dynamic @select with Query.jl

**URL:** <https://discourse.julialang.org/t/dynamic-select-with-query-jl/25242>\
**Category:** Data\
**Tags:** query\
**Created:** [June 13, 2019, 11:55am UTC](https://discourse.julialang.org/t/dynamic-select-with-query-jl/25242 "2019-06-13T11:55:22Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![tencnivel](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tencnivel/32/8662_2.png) [@tencnivel](https://discourse.julialang.org/u/tencnivel)\
**Post date:** [June 13, 2019, 11:55am UTC](https://discourse.julialang.org/t/dynamic-select-with-query-jl/25242/1 "2019-06-13T11:55:22Z")

</div>

Hello,

I’m using Query,jl with LINQ style query command.  
I try to pass a dynamic selection of variables to `@select`

For example, instead of writing this:

```julia
data_table =
    @from i in data begin
    @select {i.id, i.lastname, i.login} 
    @collect JuliaDB.table
 end

```

I would like to dynamically build the curly brackets argument passed to @select.  
This first attempt doesn’t work:

```julia
parsed_ex = Meta.parse("{i.id, i.lastname, i.login}")
data_table =
    @from i in data begin
    @select parsed_ex
    @collect JuliaDB.table
 end

```

Any idea?

---

<div class="post-metadata">

**Author:** ![simeonschaub](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/simeonschaub/32/216566_2.png) [@simeonschaub](https://discourse.julialang.org/u/simeonschaub)\
**Post date:** [June 13, 2019, 12:14pm UTC](https://discourse.julialang.org/t/dynamic-select-with-query-jl/25242/2 "2019-06-13T12:14:58Z")

</div>

You should be able to do:

```julia
@eval @from i in data begin
    @select $parsed_ex
    @collect JuliaDB.table
end

```

This is because the macro only gets passed the variable name and nothing else. `@eval` will insert the expression before it is compiled. It’s a bit hacky, but should work. Next time, please include a self contained example, this will make it much easier to help you.

---

<div class="post-metadata">

**Author:** ![tencnivel](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tencnivel/32/8662_2.png) [@tencnivel](https://discourse.julialang.org/u/tencnivel)\
**Post date:** [July 9, 2019, 10:12am UTC](https://discourse.julialang.org/t/dynamic-select-with-query-jl/25242/3 "2019-07-09T10:12:54Z")

</div>

The code you gave is almost working, it’s just missing the ‘$’ sign on one of the variable.

Here is the corrected version:

```julia
parsed_ex = Meta.parse("{i.id, i.lastname, i.login}")
data_table = @eval @from i in $data begin
    @select $parsed_ex
    @collect JuliaDB.table
 end

```

NOTE:  
The performance of this are actually terrible. My original motivation was to rename data using a dynamic set of names. What I ended up doing is renaming the table after the linq filter:

```julia
 rename!(data, f => t for (f, t) = zip(vector_of_old_symbols,
                                                       vector_of_new_symbols))

```
