# Best way to create a new type

**URL:** <https://www.starburst.io/community/forum/t/best-way-to-create-a-new-type/176>\
**Category:** Trino\
**Created:** [May 28, 2022, 6:48pm UTC](https://www.starburst.io/community/forum/t/best-way-to-create-a-new-type/176 "2022-05-28T18:48:20Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![x-malet](https://www.starburst.io/community/forum/user_avatar/www.starburst.io/x-malet/32/64_2.png) [@x-malet](https://www.starburst.io/community/forum/u/x-malet)\
**Post date:** [May 28, 2022, 6:48pm UTC](https://www.starburst.io/community/forum/t/best-way-to-create-a-new-type/176/1 "2022-05-28T18:48:20Z")

</div>

Hi everyone !

I’m looking for a way to create a new type in a plugin with two parameters…something like

MY\_TYPE( ‘test’, 123)

what is the best way to do it and, will it be recognize in a SQL line like

CREATE TABLE table as (c MY\_TYPE( ‘test’, 123) ) ??

Thanks !

---

<div class="post-metadata">

**Author:** ![bitsondatadev](https://www.starburst.io/community/forum/user_avatar/www.starburst.io/bitsondatadev/32/6_2.png) [@bitsondatadev](https://www.starburst.io/community/forum/u/bitsondatadev)\
**Post date:** [June 6, 2022, 7:20pm UTC](https://www.starburst.io/community/forum/t/best-way-to-create-a-new-type/176/2 "2022-06-06T19:20:54Z")

</div>

Check out [this commit when they added JSON type in 2014](https://github.com/trinodb/trino/commit/cd0011cb8753a657e1d45755889df3a1d84496fe). Some stuff has likely changed, but honestly, I doubt too much. This would also require adding the type to [SQL in the ANTLR definition in the trino-parser](https://github.com/trinodb/trino/blob/master/core/trino-parser/src/main/antlr4/io/trino/sql/parser/SqlBase.g4). [This was the commit where `JSON` was added](https://github.com/trinodb/trino/commit/074a7088f55f11c8164a3af8d52a722f59e2cd94) but the file has changed a lot since then.

Let me know if there are follow up questions. Unfortunately there’s not a guide we can officially point to for these types of changes yet.

---

<div class="post-metadata">

**Author:** ![x-malet](https://www.starburst.io/community/forum/user_avatar/www.starburst.io/x-malet/32/64_2.png) [@x-malet](https://www.starburst.io/community/forum/u/x-malet)\
**Post date:** [June 10, 2022, 3:35am UTC](https://www.starburst.io/community/forum/t/best-way-to-create-a-new-type/176/3 "2022-06-10T03:35:21Z")

</div>

Thanks Brian!

That was part of the first thing I made (working my way through AntlR, etc…) but I found it pretty bad as I was changing to many things in the core package.

What I managed to do is:

- creating a parametric type
- register my new type using the type signature class.

It was way easier (no change in the core) and way more flexible as I can register as many new type as I want using the parametric type.

Now, my new problem is getting it to the parquet and orc writers! I’m still learning a good way to use the Block class in order to serde my objects…!

Thanks again for pointing me out this commit! It was a good start!

---

<div class="post-metadata">

**Author:** ![bitsondatadev](https://www.starburst.io/community/forum/user_avatar/www.starburst.io/bitsondatadev/32/6_2.png) [@bitsondatadev](https://www.starburst.io/community/forum/u/bitsondatadev)\
**Post date:** [June 13, 2022, 5:47pm UTC](https://www.starburst.io/community/forum/t/best-way-to-create-a-new-type/176/4 "2022-06-13T17:47:52Z")

</div>

Happy to have attempted to help. Although I didn’t feel like I helped too much 😃
