Category: How do I do X?
Updated

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 to save numeric data as string(varchar) in SQL table?

Issue

I am developing an application using postgresql and have a table for company data. When I update a record with a national code that begins with 0, I get a format error because it's saved as varchar. When creating a new record, the national code saves without the initial 0. How can I fix this? With the help of a community member, I turned off prepared statements and added quotes to ensure correct formatting of the DB values being passed in the query, which resolved the issue.

Resolution

The issue mentioned by the developer is related to the national code data of a record in the enterprise table, which is saved as varchar, but begins with 0. When updating that record, the developer receives an error related to the format of the national code data that begins with 0. When creating a new record and saving it, the national code is saved without the initial 0.

The solution to this issue involves disabling the prepared statements button and making sure that all database values being passed in the queries are in the correct format. For a varchar, the value should be something like '{{nationalCodeInput.text}}' with quotes added.

The solution can be implemented by modifying the code responsible for updating the record in the enterprise table and ensuring that correct values are being passed in the queries. With the necessary changes made, the code should be able to handle the national code data that begins with 0 without any format errors.