# Data Explorer \`int\_list\` replaces 1st element with 0

**URL:** <https://meta.discourse.org/t/data-explorer-int-list-replaces-1st-element-with-0/146552>\
**Category:** Support\
**Tags:** data-explorer\
**Created:** [2 באפריל,‏ 2020,‏ 8:31am UTC](https://meta.discourse.org/t/data-explorer-int-list-replaces-1st-element-with-0/146552 "2020-04-02T08:31:37Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![AstonJ](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/astonj/32/215041_2.png) [@AstonJ](https://meta.discourse.org/u/AstonJ)\
**Post date:** [2 באפריל,‏ 2020,‏ 8:31am UTC](https://meta.discourse.org/t/data-explorer-int-list-replaces-1st-element-with-0/146552/1 "2020-04-02T08:31:37Z")

</div>

Not sure if this is a bug or whether I’m doing something wrong, but it seems the first element in an `int_list` array is always replaced with 0 in a [data explorer](https://meta.discourse.org/t/32566?silent=true) query.

Eg:

```plaintext
-- int_list :categories = "3, 5, 6"

```

gets changed to `[0, 5, 6]`

looking at:

> <https://github.com/discourse/discourse-data-explorer/blob/main/plugin.rb#L942>

If I do that in console I get the expected output:

```plaintext
string = "3,5,6"
value = string.split(',').map { |s| s.downcase == '#null' ? nil : s.to_i }
=> [3, 5, 6]

```

You can reproduce with this query:

```plaintext
-- [params]
-- int_list :categories = "3, 5, 6"

SELECT *
FROM topics 
WHERE topics.category_id = ANY (ARRAY [:categories] )

```

To break it (so you can view the error) simply remove the closing bracket, eg:

```plaintext
-- [params]
-- int_list :categories = "3, 5, 6"

SELECT *
FROM topics 
WHERE topics.category_id = ANY (ARRAY [ :categories )

```

```plaintext
PG::SyntaxError: ERROR: syntax error at or near ")"
LINE 12: WHERE topics.category_id = ANY (ARRAY [ 0,5,6 )
                                                         ^

```

(Look at the array)

---

<div class="post-metadata">

**Author:** ![simon](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/simon/32/339122_2.png) [@simon](https://meta.discourse.org/u/simon)\
**Post date:** [2 באפריל,‏ 2020,‏ 5:22pm UTC](https://meta.discourse.org/t/data-explorer-int-list-replaces-1st-element-with-0/146552/2 "2020-04-02T17:22:31Z")

</div>

It looks like what is happening when you set a default value for an `int_list` parameter in this way:

```plaintext
-- int_list :categories = "3, 5, 6"

```

is that the following gets run:

```plaintext
'"1'.downcase.to_i

```

That will return `0`.

You can get around the issue by leaving the quotes off the default parameter:

```plaintext
-- int_list :categories = 3, 5, 6

```

That value still gets interpreted as a string before being split into an array. Maybe the plugin should strip outer quotation marks if they get added to a string input.

---

<div class="post-metadata">

**Author:** ![AstonJ](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/astonj/32/215041_2.png) [@AstonJ](https://meta.discourse.org/u/AstonJ)\
**Post date:** [2 באפריל,‏ 2020,‏ 5:42pm UTC](https://meta.discourse.org/t/data-explorer-int-list-replaces-1st-element-with-0/146552/3 "2020-04-02T17:42:04Z")

</div>

Thanks Simon! 😃

_I was sure I had tried that… and looking again now I see that changing default parameters in the body and clicking on `save and run` has no effect - you either have to refresh the page after saving or change the values in the box for the field as well (which I totally forgot about)._

---

<div class="post-metadata">

**Author:** ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)\
**Post date:** [3 באפריל,‏ 2020,‏ 1:36am UTC](https://meta.discourse.org/t/data-explorer-int-list-replaces-1st-element-with-0/146552/4 "2020-04-03T01:36:10Z")

</div>

FWIW I find params really fiddly to reason about, I wonder if we should shift this to full UX vs magic comments @riking

---

<div class="post-metadata">

**Author:** ![riking](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/riking/32/170938_2.png) [@riking](https://meta.discourse.org/u/riking)\
**Post date:** [3 באפריל,‏ 2020,‏ 2:00am UTC](https://meta.discourse.org/t/data-explorer-int-list-replaces-1st-element-with-0/146552/5 "2020-04-03T02:00:49Z")

</div>

Yup, totally makes sense to do that, the magic comments were optimizing for minimum # of plugin-sourced DB migrations, which are much less of a problem these days.

---

<div class="post-metadata">

**Author:** ![system](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/system/32/443519_2.png) [@system](https://meta.discourse.org/u/system)\
**Post date:** [21 באפריל,‏ 2024,‏ 1:17am UTC](https://meta.discourse.org/t/data-explorer-int-list-replaces-1st-element-with-0/146552/6 "2024-04-21T01:17:24Z")

</div>



---

<div class="post-metadata">

**Author:** ![system](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/system/32/443519_2.png) [@system](https://meta.discourse.org/u/system)\
**Post date:** [4 ביוני,‏ 2024,‏ 12:33pm UTC](https://meta.discourse.org/t/data-explorer-int-list-replaces-1st-element-with-0/146552/7 "2024-06-04T12:33:48Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
