# Errors writing KNIME string to PostgreSQL uuid field

**URL:** <https://forum.knime.com/t/errors-writing-knime-string-to-postgresql-uuid-field/36064>\
**Category:** KNIME Analytics Platform\
**Created:** [September 15, 2021, 4:38am UTC](https://forum.knime.com/t/errors-writing-knime-string-to-postgresql-uuid-field/36064 "2021-09-15T04:38:38Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![ettobias](https://forum-cdn.knime.com/letter_avatar_proxy/v4/letter/e/bbe5ce/32.png) [@ettobias](https://forum.knime.com/u/ettobias)\
**Post date:** [September 15, 2021, 4:38am UTC](https://forum.knime.com/t/errors-writing-knime-string-to-postgresql-uuid-field/36064/1 "2021-09-15T04:38:39Z")

</div>

I’ve tried to find a solution to my issue in these forums, via search engine, and anything else I can think of with no success, so I’m posting my first topic to see if I can get a solution here.

I am reading from a Postgres table in a “1.0” database, manipulating field names, adding a constant column value, and writing to a “2.0” database table. It looks to me like KNIME doesn’t like, or know how to handle the Postgres uuid data type as I get the following error:

ERROR DB Insert 0:13 Execute failed: Batch entry 0 INSERT INTO “###”."###" (“MyPK”, “###”, “###”, “###”, “###”) VALUES (‘2a6210c6-971d-4f1a-8752-12daa4b7e3b4’,’###’,NULL,NULL,3) was aborted: ERROR: column “MyPK” is of type uuid but expression is of type character varying  
Hint: You will need to rewrite or cast the expression.

(I’ve replaced table and field names in the error message, with the exception of the uuid/guid I’m trying to insert into.)

I can paste the SQL statement directly into PgAdmin and it works fine, but not in KNIME using a DB Insert node. I’ve also tried adding the braces in the string (i.e., “{}”), but that doesn’t help.

It looks to me like this is an issue between JDBC and SQL, based on some articles I’ve found, but all of the solutions make changes inside Java… not inside KNIME.

How do I handle this so the string-encoded uuid will insert?

---

<div class="post-metadata">

**Author:** ![mlauber71](https://forum-cdn.knime.com/user_avatar/forum.knime.com/mlauber71/32/73590_2.png) [@mlauber71](https://forum.knime.com/u/mlauber71)\
**Post date:** [September 15, 2021, 9:47am UTC](https://forum.knime.com/t/errors-writing-knime-string-to-postgresql-uuid-field/36064/2 "2021-09-15T09:47:07Z")

</div>

@ettobias welcome to the KNIME forum

The solution might very well look something like this:

> [@Insert JSON value into Postgresql database table](https://forum.knime.com/t/insert-json-value-into-postgresql-database-table/22346/3):
>
> Hello [Tokbanov](https://forum.knime.com/u/Tokbanov), in order to write a KNIME JSON cell into a Postgres JSON column you need to do the following: In the PostgreSQL Connector node you need to add the speciy the JDBC Parameter stringtype=unspecified [image] and you need to add the following mapping JSON-\>String-\>Varchar to the [Output Type Mapping](https://docs.knime.com/latest/db_extension_guide/index.html#type_mapping) tab Once this is done you should be able to write JSON cells into JSON columns in the database. When you want to read the data back into KNIME you can use the [DB Type…](https://docs.knime.com/latest/db_extension_guide/index.html#db_type_mapper)

Since KNIME might not have a data type uuid you would have to store it as a string and when insertig it into Postgres make sure it is recognized as uuid.

You might also upload the KNIME file into a temporary Postgres table and then convert it into uuid with somethink like:

> CAST(\<your\_variable\> AS uuid) AS \<your\_target\_variable\>

I might see if I can come up with an example how to do that

---

<div class="post-metadata">

**Author:** ![mlauber71](https://forum-cdn.knime.com/user_avatar/forum.knime.com/mlauber71/32/73590_2.png) [@mlauber71](https://forum.knime.com/u/mlauber71)\
**Post date:** [September 15, 2021, 10:19am UTC](https://forum.knime.com/t/errors-writing-knime-string-to-postgresql-uuid-field/36064/3 "2021-09-15T10:19:07Z")

</div>

A solution could be something like this. You upload the file with the UUID into a emporary table and then insert it into the target table

 ![image](https://forum-cdn.knime.com/uploads/default/original/3X/8/c/8c436bf26a00e26ee642c495caf1b63191d1b48c.png)

The CAST() command would convert it into a uuid

 ![image](https://forum-cdn.knime.com/uploads/default/original/3X/7/0/70558a0e2472f82b3fa333bd9ebd85c65d19209c.png)

> **[Example how to use H2 database with a uuid unique identifier – mlauber71](https://hub.knime.com/mlauber71/spaces/Forum/latest/2021/kn_forum_36064_db_h2_use_uuid_unique_identifier~VCI3c0n2bgE1CVkY)**
>
> Example how to use H2 database with a uuid unique identifier

---

<div class="post-metadata">

**Author:** ![bruno29a](https://forum-cdn.knime.com/user_avatar/forum.knime.com/bruno29a/32/28802_2.png) [@bruno29a](https://forum.knime.com/u/bruno29a)\
**Post date:** [September 15, 2021, 12:33pm UTC](https://forum.knime.com/t/errors-writing-knime-string-to-postgresql-uuid-field/36064/4 "2021-09-15T12:33:56Z")

</div>

Hi @ettobias , the solution presented by @mlauber71 is an excellent one, but I just wanted to comment on what you said:

> [@ettobias](#):
>
> I can paste the SQL statement directly into PgAdmin and it works fine, but not in KNIME using a DB Insert node.

Well, you’re not really comparing the same thing here. The DB Insert node will read from a Knime table, and therefore will try to match the column types, as opposed to executing an INSERT statement via PgAdmin where it’s not having to compare the types.

If you really want to test what you said, try to execute the same INSERT statement you are executing in PgAmin in Knime using the [DB SQL Executor](https://hub.knime.com/knime/extensions/org.knime.features.database/latest/org.knime.database.node.manipulation.executor.DBExecutorNodeFactory) node. Then you will be comparing apple to apple.

But for your task, I would load your data into a temp table, be it using an H2 virtual instance (as @mlauber71 's suggestion), or on your Postgres server, and then do INSERT SELECT casting as uuid INTO your\_destination\_table via the DB SQL Executor mentioned above.

---

<div class="post-metadata">

**Author:** ![ettobias](https://forum-cdn.knime.com/letter_avatar_proxy/v4/letter/e/bbe5ce/32.png) [@ettobias](https://forum.knime.com/u/ettobias)\
**Post date:** [September 15, 2021, 12:38pm UTC](https://forum.knime.com/t/errors-writing-knime-string-to-postgresql-uuid-field/36064/5 "2021-09-15T12:38:15Z")

</div>

Ah, great idea. I hate feeling like a noobie at software, even if I am new to it. I’m the master of several other pieces of software, so it annoys me to no end to have to ask noobie questions. 🙂

I’ll check this out for sure and come back with my results. I did think about the data type mapping, but couldn’t figure out how to get it to work. A temp table I _definitely_ should have thought of… but lesson learned. Wish me luck!

---

<div class="post-metadata">

**Author:** ![ettobias](https://forum-cdn.knime.com/letter_avatar_proxy/v4/letter/e/bbe5ce/32.png) [@ettobias](https://forum.knime.com/u/ettobias)\
**Post date:** [September 15, 2021, 12:40pm UTC](https://forum.knime.com/t/errors-writing-knime-string-to-postgresql-uuid-field/36064/6 "2021-09-15T12:40:47Z")

</div>

I get that it is comparing apples and oranges. My point was that the syntax was correct. 🙂 I realize that there are additional layers between KNIME and Postgres. I was more noting that at the very least I made sure the syntax that was being generated was correct and I wasn’t making some bonehead mistake that was breaking the SQL statement. 🙂

And DB SQL Executor node is also something I probably should have thought of. As I said in my prior response to @mlauber71, I hate being a noobie in software, but we all have to put in our time. Thank you for the response and pointer. I’ll try it out too.

---

<div class="post-metadata">

**Author:** ![bruno29a](https://forum-cdn.knime.com/user_avatar/forum.knime.com/bruno29a/32/28802_2.png) [@bruno29a](https://forum.knime.com/u/bruno29a)\
**Post date:** [September 15, 2021, 12:41pm UTC](https://forum.knime.com/t/errors-writing-knime-string-to-postgresql-uuid-field/36064/7 "2021-09-15T12:41:54Z")

</div>

No worries @ettobias . Let us know what you find out, we’ll be interested 🙂

---

<div class="post-metadata">

**Author:** ![ettobias](https://forum-cdn.knime.com/letter_avatar_proxy/v4/letter/e/bbe5ce/32.png) [@ettobias](https://forum.knime.com/u/ettobias)\
**Post date:** [September 15, 2021, 12:47pm UTC](https://forum.knime.com/t/errors-writing-knime-string-to-postgresql-uuid-field/36064/8 "2021-09-15T12:47:41Z")

</div>

Oh… and I absolutely _love_ your ManU logo, @bruno29a , if we’re permitted a single sentence of non-support type conversation in the forums. 😄

---

<div class="post-metadata">

**Author:** ![mlauber71](https://forum-cdn.knime.com/user_avatar/forum.knime.com/mlauber71/32/73590_2.png) [@mlauber71](https://forum.knime.com/u/mlauber71)\
**Post date:** [September 15, 2021, 12:49pm UTC](https://forum.knime.com/t/errors-writing-knime-string-to-postgresql-uuid-field/36064/9 "2021-09-15T12:49:30Z")

</div>

> [@bruno29a](#):
>
> But for your task, I would load your data into a temp table, be it using an H2 virtual instance (as @mlauber71 's suggestion), or on your Postgres server, and then do INSERT SELECT casting as uuid INTO your\_destination\_table via the DB SQL Executor mentioned above.

I think in oder for this solution to work it would have to happen on the same (Postgres) server as the final table. I just used H2 because one can use it in-memory and stand-alone so as to create a complete KNIME example - and it has a varaible type of uuid.

---

<div class="post-metadata">

**Author:** ![bruno29a](https://forum-cdn.knime.com/user_avatar/forum.knime.com/bruno29a/32/28802_2.png) [@bruno29a](https://forum.knime.com/u/bruno29a)\
**Post date:** [September 15, 2021, 12:52pm UTC](https://forum.knime.com/t/errors-writing-knime-string-to-postgresql-uuid-field/36064/10 "2021-09-15T12:52:06Z")

</div>

Hi @mlauber71 , that is correct, it would have to be on the same postgres server (which should not be an issue). I’m just not sure if we can cast the type uuid from postgres in H2, so that is why I prefer dealing with Postgres in this case.

---

<div class="post-metadata">

**Author:** ![mlauber71](https://forum-cdn.knime.com/user_avatar/forum.knime.com/mlauber71/32/73590_2.png) [@mlauber71](https://forum.knime.com/u/mlauber71)\
**Post date:** [September 15, 2021, 12:57pm UTC](https://forum.knime.com/t/errors-writing-knime-string-to-postgresql-uuid-field/36064/11 "2021-09-15T12:57:42Z")

</div>

@ettobias even after years of working with KNIME I still learn something new every day (never used uuid with KNIME before …). That is part of the joy of KNIME 🙂

And often there are several ways to solve a problem with KNIME since it is a **platform** and can integrate a lot of code and functions.

The DB / SQL part is designed as to work with a lot of databases using the same surface so people would have an easier time. Of course there are specific settings and functions in individual DB systems that sometimes are not fully covered by KNIME nodes in their initial setting. And you can use SQL via the special KNIME nodes or just write plain SQL and send it to the database. You still would have to take into consideration how the database does work. This is especially true if you use Big Data systems (the code would work but you are better off if you take the inner workings of eg. Cloudera into consideration).

With KNIME you come up with a working solution, and next time you might think of a better one (but thank to backward compatibility your old solution will still work).

And also this forum and community is there to help out. So just enjoy using KNIME and asking challenging questions.

---

<div class="post-metadata">

**Author:** ![ettobias](https://forum-cdn.knime.com/letter_avatar_proxy/v4/letter/e/bbe5ce/32.png) [@ettobias](https://forum.knime.com/u/ettobias)\
**Post date:** [September 15, 2021, 8:32pm UTC](https://forum.knime.com/t/errors-writing-knime-string-to-postgresql-uuid-field/36064/12 "2021-09-15T20:32:14Z")

</div>

So it turns out this is much simpler than expected. The other forum article you sent me to @mlauber71 gave a suggestion that fixed it without needing anything further. It turns out that JDBC is explicitly casting the GUID as a string in the prepared statement it sends to Postgres.

By setting the “stringtype” JDBC parameter to “unspecified” the prepared statement sends the parameter values through without strongly typing them, so Postgres then interprets the string based on its format…which looks like a GUID/UUID, so Postgres runs the insert and casts it to uuid.

I may still try out the other suggestions just to learn more about KNIME, but for those looking for a solution to Postgres and GUID/UUID handling in KNIME, just add “stringtype=undefined” in the JDBC parameter tab of the connection.

 ![Untitled](https://forum-cdn.knime.com/uploads/default/original/3X/5/e/5e031f08045be3cd270e368bed887a15d65520dd.png)

---

<div class="post-metadata">

**Author:** ![bruno29a](https://forum-cdn.knime.com/user_avatar/forum.knime.com/bruno29a/32/28802_2.png) [@bruno29a](https://forum.knime.com/u/bruno29a)\
**Post date:** [September 15, 2021, 8:41pm UTC](https://forum.knime.com/t/errors-writing-knime-string-to-postgresql-uuid-field/36064/13 "2021-09-15T20:41:38Z")

</div>

That was quite very much simpler indeed @ettobias 😃

Thank you for sharing.

---

<div class="post-metadata">

**Author:** ![system](https://forum-cdn.knime.com/uploads/default/original/1X/ab3ccf34482a0329361734a18199390177204f15.png) [@system](https://forum.knime.com/u/system)\
**Post date:** [September 22, 2021, 8:41pm UTC](https://forum.knime.com/t/errors-writing-knime-string-to-postgresql-uuid-field/36064/14 "2021-09-22T20:41:47Z")

</div>

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