Which type to pick for column that will hold a variety of data types

Posted on

Question :

I’m setting up a Postgres database that will function as a storage place for data records. There’s a column in the records that I’m going to be inserting that contains different kinds of data types; floats, integers, and strings. Due to the variety of data types that this column needs to hold, I have set the type of that column to VARCHAR(50), but I fear that this is not very efficient.

Question: As this column will need to hold a lot of values in the future I’m looking for the best way to deal with the different types. What is the best type setting or way of storing these records performance-wise?

Answer :

Pretty much that is the definition of a varchar field: a field for various types and lengths, limited only by the max length pretty much. It takes anything a number, a character string, nothing. So what are you going to be doing with it? If it is just storage and you will look at it then does it really matter? If you are going to be doing something else with it, you might need to decide if this is really what you want to do.

Leave a Reply

Your email address will not be published. Required fields are marked *