If you would like to use a column in a different data type than the one in your schema and can’t change the data type in your database, you can use custom columns to change the column’s data type in Chartio.
For example, you may have a date column that classified as a string in your schema but would like to use it as a date.
Go to the Data Source list, select your data source, and switch to the Schema tab. As you can see, our ‘Date’ column is classified as a string. In order to use Chartio’s built-in date functions, we’ll need to cast it to a date.
To accomplish this, you can create a custom column. Click the Add Custom Column button at the top right of the table which contains the column you want to change.
For ease of use, we recommend naming your new column the same as the original column. Be sure to select the correct data type from the Type dropdown as well.
Consult the documentation for your database type to determine the correct syntax for casting a column as a date. Some common example are listed below.
PostgreSQL, CSVs, Data Stores
CAST("table_name"."column_name" as date)
Note: If you are getting an error, verify that the resulting date values are in the format YYYY-MM-DD in order for the column to be recognized as a date.
The Data Source in this example is a CSV and we used the format below. Fill in all the information for the new column and click Add Column when finished.
Because we always want to use our new custom column, we’re going to hide the original column in the schema by unchecking the Visible checkbox. This will hide the original column so it won’t be seen in the chart editor.
Now we can use our new column as a date in Interactive Mode.
For more information about creating custom columns and tables, see our Custom Schema documentation.
For examples of how to change a column’s data type in the Data Pipeline, check out our article here.