Skip to main content Skip to footer

Search Crosser Knowledge Base

Casting datatypes with Database Executer modules

When inserting data into a database from a flow, you want to make sure that all columns are inserted with the correct data type. The database modules from Crosser are built with SDKs which often handle casting and data type conversion by themselves. In cases where it does not work, or you want to apply specific casting/conversion, the database Executer modules come in handy.

Let’s assume you want to insert the timestamp from the incoming message as timestamptz, and values as jsonB instead of a JSON string into a PostgreSQL table.

Incoming message

{
  "crosser": {
    "success": true
  },
  "result": [],
  "toDb": {
    "id": 123456,
    "ip": "10.10.4.100",
    "machine": "Blender_1",
    "time": "2024-11-22T12:40:36.6649230Z",
    "values": "{\"A\":1,\"CT\":\"something_else\"}"
  }
}

PostGres Executer query

INSERT INTO machine_logs (id, values, time, machine, ip)
VALUES (@toDb.id, (@toDb.values)::jsonb, (@toDb.time)::timestamptz, @toDb.machine, @toDb.ip);

Note: The above query is tailored towards PostgreSQL and might vary for other relational database systems.

About the author

David Nienhaus | Senior Solution Engineer

David is a Senior Solution Engineer at Crosser. He has over 10 years experience working with software integration and digitization projects for critical infrastructure.
His engineering background gives him the understanding and focus needed to solve customer use cases in the most efficient and successful way.