# Node red write into postgres in other format

**URL:** <https://discourse.nodered.org/t/node-red-write-into-postgres-in-other-format/97841>\
**Category:** General\
**Created:** [27 June 2025 15:10 UTC](https://discourse.nodered.org/t/node-red-write-into-postgres-in-other-format/97841 "2025-06-27T15:10:58Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![bobdion](https://avatars.discourse-cdn.com/v4/letter/b/b2d939/32.png) [@bobdion](https://discourse.nodered.org/u/bobdion)\
**Post date:** [27 June 2025 15:10 UTC](https://discourse.nodered.org/t/node-red-write-into-postgres-in-other-format/97841/1 "2025-06-27T15:10:58Z")

</div>

i got a node that insert a line into the database

INSERT INTO public."TB\_ALERTE"("TR\_SENSORNAME", "TR\_INFO","TR\_DATEHEURE") VALUES ( 'SENSOR/ TOILETTE' , 'ON','{{msg.payload}}');  
the payload is coming from a function

const d = new Date();  
msg.payload = d.toLocaleString();  
return msg;

but the problem is the value written in the db is not readable

6& #x2F;27& #x2F;2025, 10:36:23 AM

i put some space in the text because your website correct it

how can i be able to see the date like that  
6/27/2025, 11:10:22 AM

thanks

---

<div class="post-metadata">

**Author:** ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)\
**Post date:** [27 June 2025 15:36 UTC](https://discourse.nodered.org/t/node-red-write-into-postgres-in-other-format/97841/2 "2025-06-27T15:36:43Z")

</div>

Welcome to the forum @bobdion.

What datatype is your TR\_DATEHEURE field?

For timestamp fields, since you are trying to store the current date/time, you could use the Progres current\_timestamp function  
So that would be something like

```auto
INSERT INTO public."TB_ALERTE"("TR_SENSORNAME", "TR_INFO","TR_DATEHEURE") 
VALUES ( 'SENSOR/ TOILETTE' , 'ON', CURRENT_TIMESTAMP);

```

---

<div class="post-metadata">

**Author:** ![bobdion](https://avatars.discourse-cdn.com/v4/letter/b/b2d939/32.png) [@bobdion](https://discourse.nodered.org/u/bobdion)\
**Post date:** [27 June 2025 15:42 UTC](https://discourse.nodered.org/t/node-red-write-into-postgres-in-other-format/97841/3 "2025-06-27T15:42:40Z")

</div>

the field is a text not a timestamp

---

<div class="post-metadata">

**Author:** ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)\
**Post date:** [27 June 2025 15:51 UTC](https://discourse.nodered.org/t/node-red-write-into-postgres-in-other-format/97841/4 "2025-06-27T15:51:23Z")

</div>

If you send the function node output to a debug node, what does it show?

I get this but of course my locale may be different to yours.

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/2/a/2a9c20b1fea3244117e5f96e21d6461c6964eedd.png)

---

<div class="post-metadata">

**Author:** ![bobdion](https://avatars.discourse-cdn.com/v4/letter/b/b2d939/32.png) [@bobdion](https://discourse.nodered.org/u/bobdion)\
**Post date:** [27 June 2025 16:03 UTC](https://discourse.nodered.org/t/node-red-write-into-postgres-in-other-format/97841/5 "2025-06-27T16:03:06Z")

</div>

yes the result is good

---

<div class="post-metadata">

**Author:** ![bobdion](https://avatars.discourse-cdn.com/v4/letter/b/b2d939/32.png) [@bobdion](https://discourse.nodered.org/u/bobdion)\
**Post date:** [27 June 2025 16:04 UTC](https://discourse.nodered.org/t/node-red-write-into-postgres-in-other-format/97841/6 "2025-06-27T16:04:23Z")

</div>

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/9/d/9dfd983e5f925294122b418a511afcf224690070.png)  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/5/2/52c7a5c48155e498fb93ff4a2decc0bd439aaae0.png)

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [27 June 2025 16:05 UTC](https://discourse.nodered.org/t/node-red-write-into-postgres-in-other-format/97841/7 "2025-06-27T16:05:55Z")

</div>

Looks like the postgres Database or something else is converting special characters to Unicode Hex Character Code `&#x2f;` (/).

Saying that you should store all timestamps in a database as universal time, and when you need to display read the universal time and convert to local time. This will cause you less issues further down the line.

---

<div class="post-metadata">

**Author:** ![bobdion](https://avatars.discourse-cdn.com/v4/letter/b/b2d939/32.png) [@bobdion](https://discourse.nodered.org/u/bobdion)\
**Post date:** [27 June 2025 16:15 UTC](https://discourse.nodered.org/t/node-red-write-into-postgres-in-other-format/97841/8 "2025-06-27T16:15:34Z")

</div>

ok but the problem will i get other problem like that with different function  
there is a way to change that in postgres

---

<div class="post-metadata">

**Author:** ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)\
**Post date:** [27 June 2025 16:22 UTC](https://discourse.nodered.org/t/node-red-write-into-postgres-in-other-format/97841/9 "2025-06-27T16:22:13Z")

</div>

Yes the unicode representation of / is `&#x2f;`.

Postgres cannot store unicode, it needs utf-8 encoded strings.  
It's not clear where the string gets unicode encoded.

Can you execute SHOW SERVER\_ENCODING in Progres?  
Which node-red config node are you using? Does the config allow an encoding setting?

---

<div class="post-metadata">

**Author:** ![bobdion](https://avatars.discourse-cdn.com/v4/letter/b/b2d939/32.png) [@bobdion](https://discourse.nodered.org/u/bobdion)\
**Post date:** [27 June 2025 17:01 UTC](https://discourse.nodered.org/t/node-red-write-into-postgres-in-other-format/97841/10 "2025-06-27T17:01:15Z")

</div>

i did what you say with current\_timestamp

and its working

i will leave it like that and if in the future i got another problem i will come back here

lol

thanks

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [25 September 2025 17:01 UTC](https://discourse.nodered.org/t/node-red-write-into-postgres-in-other-format/97841/11 "2025-09-25T17:01:58Z")

</div>

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