# Use temporary table

**URL:** https://discuss.tryton.org/t/use-temporary-table/5314
**Category:** Developer
**Created:** [June 2, 2022, 2:41pm UTC](https://discuss.tryton.org/t/use-temporary-table/5314 "2022-06-02T14:41:25Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![bell](https://discuss-cdn.tryton.org/letter_avatar_proxy/v4/letter/b/c67d28/32.png) [@bell](https://discuss.tryton.org/u/bell)
#### Post date: [June 2, 2022, 2:41pm UTC](https://discuss.tryton.org/t/use-temporary-table/5314/1 "2022-06-02T14:41:25Z")

</div>

Thanks for the help.  
Is it possible to work with temporary tables inTryton?

---

<div class="post-metadata">

### Author: ![ced](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/ced/32/1237_2.png) [@ced](https://discuss.tryton.org/u/ced)
#### Post date: [June 2, 2022, 2:44pm UTC](https://discuss.tryton.org/t/use-temporary-table/5314/2 "2022-06-02T14:44:44Z")

</div>

The table handler has nothing for that in standard. Mainly because we have never had the need.

---

<div class="post-metadata">

### Author: ![bell](https://discuss-cdn.tryton.org/letter_avatar_proxy/v4/letter/b/c67d28/32.png) [@bell](https://discuss.tryton.org/u/bell)
#### Post date: [June 2, 2022, 2:51pm UTC](https://discuss.tryton.org/t/use-temporary-table/5314/3 "2022-06-02T14:51:16Z")

</div>

There is a need to perform quite complex calculations in a temporary table. Without this table, there are a lot of nested queries.

---

<div class="post-metadata">

### Author: ![ced](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/ced/32/1237_2.png) [@ced](https://discuss.tryton.org/u/ced)
#### Post date: [June 2, 2022, 2:55pm UTC](https://discuss.tryton.org/t/use-temporary-table/5314/4 "2022-06-02T14:55:32Z")

</div>

I do not see any advantage of temporary table when you have python-sql and CTE that abstract the queries. The database engine will materialize or not the sub-queries if it find it is needed.

---

<div class="post-metadata">

### Author: ![bell](https://discuss-cdn.tryton.org/letter_avatar_proxy/v4/letter/b/c67d28/32.png) [@bell](https://discuss.tryton.org/u/bell)
#### Post date: [June 2, 2022, 3:04pm UTC](https://discuss.tryton.org/t/use-temporary-table/5314/5 "2022-06-02T15:04:58Z")

</div>

I can see that the calculations in the temporary table are much faster than with a lot of sub-queries.

---

<div class="post-metadata">

### Author: ![ced](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/ced/32/1237_2.png) [@ced](https://discuss.tryton.org/u/ced)
#### Post date: [June 2, 2022, 3:13pm UTC](https://discuss.tryton.org/t/use-temporary-table/5314/6 "2022-06-02T15:13:38Z")

</div>

Of course if you duplicate the sub-queries. But using a CTE this should not happen except for some cases where it will be better to materialize it (see [Tryton / python-sql · GitLab](https://python-sql.tryton.org/bug82)).
