Category: How do I do X?

This solution is summarized from an archived support forum post. This information may have changed. If you notice an error, please let us know in Discord.

How do I insert datetime type on PG database?


I am trying to insert a time value from Input1 on Appsmith into a time column on my database. However, I am getting an error message stating that the query preparation failed. The solution is to use moment to convert the DateTime field since the database only accepts the DateTime field in string format. Additionally, I need to update the default text in Input2 to reflect this solution and turn off prepared statements.


The issue with the provided query is that the database expects the time value in the DateTime format rather than the time format. To solve this, the moment library can be used to convert the time format to the DateTime format.

The following code demonstrates how to use moment to convert the time value before inserting it into the database:

// import moment library
const moment = require('moment');

// get input from Appsmith
const input1 = moment(input1.text, 'HH:mm').format('YYYY-MM-DD HH:mm:ss');

// insert data into the database
INSERT INTO public."TTKHACHHANG" ("sdt", "gio_gian_so")
VALUES ({{input1.value}},'{{input2.text}}');

It is also suggested to turn off prepared statements to avoid any other query preparation issues.