# Find original SQL statement after dataset moved

**URL:** <https://community.dremio.com/t/find-original-sql-statement-after-dataset-moved/1253>\
**Category:** Uncategorized\
**Created:** [June 6, 2018, 2:56pm UTC](https://community.dremio.com/t/find-original-sql-statement-after-dataset-moved/1253 "2018-06-06T14:56:18Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![dli16](https://avatars.discourse-cdn.com/v4/letter/d/c5a1d2/32.png) [@dli16](https://community.dremio.com/u/dli16)\
**Post date:** [June 6, 2018, 2:56pm UTC](https://community.dremio.com/t/find-original-sql-statement-after-dataset-moved/1253/1 "2018-06-06T14:56:18Z")

</div>

Hello,

We moved a dataset `d` to a new location. When we want to check the Original SQL from there, we got error message shows:

> dataset d version 0000782655026442 at [/dataset/d/version/0000782655026442] not found

I think it didn’t move the `original sql` to the new location. Is there a way I can find that under some folder?

---

<div class="post-metadata">

**Author:** ![dli16](https://avatars.discourse-cdn.com/v4/letter/d/c5a1d2/32.png) [@dli16](https://community.dremio.com/u/dli16)\
**Post date:** [June 6, 2018, 3:04pm UTC](https://community.dremio.com/t/find-original-sql-statement-after-dataset-moved/1253/3 "2018-06-06T15:04:20Z")

</div>

Yes, I clicked that. Then I got error message shown above.

---

<div class="post-metadata">

**Author:** ![HappyCowboy](https://sea2.discourse-cdn.com/flex020/user_avatar/community.dremio.com/happycowboy/32/564_2.png) [@HappyCowboy](https://community.dremio.com/u/HappyCowboy)\
**Post date:** [June 6, 2018, 3:06pm UTC](https://community.dremio.com/t/find-original-sql-statement-after-dataset-moved/1253/4 "2018-06-06T15:06:11Z")

</div>

Sorry, I read your question wrong. 😉 . Ill defer to another Dremio expert on this one.

---

<div class="post-metadata">

**Author:** ![doron](https://sea2.discourse-cdn.com/flex020/user_avatar/community.dremio.com/doron/32/294_2.png) [@doron](https://community.dremio.com/u/doron)\
**Post date:** [June 6, 2018, 3:27pm UTC](https://community.dremio.com/t/find-original-sql-statement-after-dataset-moved/1253/5 "2018-06-06T15:27:03Z")

</div>

Hi,

We would need exact steps to reproduce this such as how it was moved (from one space to another, or to a different folder, did the dataset get renamed?). Does opening the dataset work?

---

<div class="post-metadata">

**Author:** ![dli16](https://avatars.discourse-cdn.com/v4/letter/d/c5a1d2/32.png) [@dli16](https://community.dremio.com/u/dli16)\
**Post date:** [June 6, 2018, 3:31pm UTC](https://community.dremio.com/t/find-original-sql-statement-after-dataset-moved/1253/6 "2018-06-06T15:31:57Z")

</div>

Yes, opening the datasets work. We moved dataset `d` from `/core` to `/core/subset1` through `Add Folder` button. They are all in the same workspace. The `core` is the workspace name.

---

<div class="post-metadata">

**Author:** ![doron](https://sea2.discourse-cdn.com/flex020/user_avatar/community.dremio.com/doron/32/294_2.png) [@doron](https://community.dremio.com/u/doron)\
**Post date:** [June 6, 2018, 4:56pm UTC](https://community.dremio.com/t/find-original-sql-statement-after-dataset-moved/1253/7 "2018-06-06T16:56:48Z")

</div>

Can you describe the dataset - is it a join of multiple datasets for example? Moving datasets works fine when I did a quick test so it might be something about our dataset’s composition.

---

<div class="post-metadata">

**Author:** ![dli16](https://avatars.discourse-cdn.com/v4/letter/d/c5a1d2/32.png) [@dli16](https://community.dremio.com/u/dli16)\
**Post date:** [June 6, 2018, 5:12pm UTC](https://community.dremio.com/t/find-original-sql-statement-after-dataset-moved/1253/8 "2018-06-06T17:12:12Z")

</div>

To produce:

- Create a table `test` with statement like

```auto
select *
from sql.table01

```

The `sql.table01` is a physical table

- Save the table
- Change the SQL statement, make it like:

```auto
select *
from sql.table01
order by col

```

- Save the table
- Move the table to another folder, as described earlier
- Click `Original SQL` button
- Error happen

---

<div class="post-metadata">

**Author:** ![muv](https://avatars.discourse-cdn.com/v4/letter/m/e9a140/32.png) [@muv](https://community.dremio.com/u/muv)\
**Post date:** [June 12, 2018, 12:05pm UTC](https://community.dremio.com/t/find-original-sql-statement-after-dataset-moved/1253/9 "2018-06-12T12:05:53Z")

</div>

@doron, in case it helps, I had a very similar issue with Dremio 2.0.1-201804132205050000-10b1de0.  
I moved a couple of datasets derived from a MongoDB source from one space to another. After which I started to get the same error as @dli16 posted above when trying to open the source SQL of each of the moved datasets.

I did not have time to reproduce and report it, but learned to never move datasets and instead create a new one using a copy of the SQL statement.

---

<div class="post-metadata">

**Author:** ![KeithRyan](https://avatars.discourse-cdn.com/v4/letter/k/ad7895/32.png) [@KeithRyan](https://community.dremio.com/u/KeithRyan)\
**Post date:** [March 6, 2019, 11:54am UTC](https://community.dremio.com/t/find-original-sql-statement-after-dataset-moved/1253/10 "2019-03-06T11:54:37Z")

</div>

@doron I am experiencing the same issue and as @muv states above, my only workaround is to copy the original SQL statement and create as a new query in the Space I would like to move to.  
What I am wondering is, is whether this is the only option? as this could result in lost queries and it appears to me this makes the Move function harmful

---

<div class="post-metadata">

**Author:** ![doron](https://sea2.discourse-cdn.com/flex020/user_avatar/community.dremio.com/doron/32/294_2.png) [@doron](https://community.dremio.com/u/doron)\
**Post date:** [March 6, 2019, 4:33pm UTC](https://community.dremio.com/t/find-original-sql-statement-after-dataset-moved/1253/11 "2019-03-06T16:33:53Z")

</div>

@KeithRyan

What version of Dremio are you using? We have made several fixes to Edit Original SQL in 3.1 to make it more resilient.

---

<div class="post-metadata">

**Author:** ![allan.sene](https://sea2.discourse-cdn.com/flex020/user_avatar/community.dremio.com/allan.sene/32/144_2.png) [@allan.sene](https://community.dremio.com/u/allan.sene)\
**Post date:** [May 31, 2019, 6:30pm UTC](https://community.dremio.com/t/find-original-sql-statement-after-dataset-moved/1253/12 "2019-05-31T18:30:20Z")

</div>

Same problem here. There is any workaround to get this original SQL code?

---

<div class="post-metadata">

**Author:** ![doron](https://sea2.discourse-cdn.com/flex020/user_avatar/community.dremio.com/doron/32/294_2.png) [@doron](https://community.dremio.com/u/doron)\
**Post date:** [May 31, 2019, 6:57pm UTC](https://community.dremio.com/t/find-original-sql-statement-after-dataset-moved/1253/13 "2019-05-31T18:57:59Z")

</div>

@allan.sene  
3.2 should have no issues with original SQL, what version are you using?

You can also get the original sql by running `select * from INFORMATION_SCHEMA.views` - the `VIEW_DEFINITION` column will contain it.
