# Passing UUID() to MySQL

**URL:** <https://forum.inductiveautomation.com/t/passing-uuid-to-mysql/92430>\
**Category:** Ignition\
**Created:** [June 27, 2024, 2:12am UTC](https://forum.inductiveautomation.com/t/passing-uuid-to-mysql/92430 "2024-06-27T02:12:29Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Eric\_Bauer](https://avatars.discourse-cdn.com/v4/letter/e/ebca7d/32.png) [@Eric\_Bauer](https://forum.inductiveautomation.com/u/Eric_Bauer)\
**Post date:** [June 27, 2024, 2:12am UTC](https://forum.inductiveautomation.com/t/passing-uuid-to-mysql/92430/1 "2024-06-27T02:12:29Z")

</div>

Hello,

I would like to pass the UUID() to MySQL in a query to automatically create GUID's during insert queries. I've tried it like this

```python
sql = 'INSERT INTO tblMapGraphics(uidClusterId, iBlockNum, iRowNum, iColNum) VALUES (? , ?, ?, ?)'
			args = [uuid(), BlockId, row, col]
			
			system.db.runPrepUpdate(sql, args,db)

```

UUID() is not a define variable, so that throws an error. If I enclose the function in quotes, then MySQL interprets it as a string and does not create the GUID.

Can anyone help me with the proper syntax?

---

<div class="post-metadata">

**Author:** ![richardNZ15](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/richardnz15/32/33373_2.png) [@richardNZ15](https://forum.inductiveautomation.com/u/richardNZ15)\
**Post date:** [June 27, 2024, 3:17am UTC](https://forum.inductiveautomation.com/t/passing-uuid-to-mysql/92430/2 "2024-06-27T03:17:17Z")

</div>

if UUID() is a function in MySQL, then you need to include it as a plain string in your query I think.

So instead of a "?" for your first entry in VALUES, try directly putting in UUID()

---

<div class="post-metadata">

**Author:** ![nminchin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nminchin/32/6911_2.png) [@nminchin](https://forum.inductiveautomation.com/u/nminchin)\
**Post date:** [June 27, 2024, 5:23am UTC](https://forum.inductiveautomation.com/t/passing-uuid-to-mysql/92430/3 "2024-06-27T05:23:01Z")

</div>

Or, if you need the uuid later, I would create this in the script with `str(java.util.System.UUID.randomUUID()) `

---

<div class="post-metadata">

**Author:** ![Eric\_Bauer](https://avatars.discourse-cdn.com/v4/letter/e/ebca7d/32.png) [@Eric\_Bauer](https://forum.inductiveautomation.com/u/Eric_Bauer)\
**Post date:** [June 27, 2024, 1:48pm UTC](https://forum.inductiveautomation.com/t/passing-uuid-to-mysql/92430/4 "2024-06-27T13:48:03Z")

</div>

Hi Richard. This suggestion works perfectly. Thanks for the advice. I thought my only option might be to write stored procedures for everything. This is much better for my application.

Thanks!

Eric

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [June 27, 2024, 1:54pm UTC](https://forum.inductiveautomation.com/t/passing-uuid-to-mysql/92430/5 "2024-06-27T13:54:58Z")

</div>

Note that many databases cannot return UUIDs that are auto-generated by your database (but [see the exception here](https://forum.inductiveautomation.com/t/bug-postgre-getkey-error-returning-uuid-key/79458/18)). But the whole point of UUIDs is that they can be generated at any point with extreme confidence of no collisions. That means if you need the UUID later in your code, you should generate it with java as Nick shows, and hang onto it.

(If your DB supports UUID columns, **don't** stringify it.)

---

<div class="post-metadata">

**Author:** ![Eric\_Bauer](https://avatars.discourse-cdn.com/v4/letter/e/ebca7d/32.png) [@Eric\_Bauer](https://forum.inductiveautomation.com/u/Eric_Bauer)\
**Post date:** [June 27, 2024, 4:38pm UTC](https://forum.inductiveautomation.com/t/passing-uuid-to-mysql/92430/6 "2024-06-27T16:38:42Z")

</div>

Thanks Phil. I'm not too deep into this yet. I'll test it tonight and rework if this is a problem for me.

Eric
