I need to store different versions of not very long strings for different languages (2-4 languages) in a Postgres table.
What is the best way of doing that? Array or JSON or something like that?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
First make sure that the database locale can deal with different languages. Use a UTF-8 server-encoding. Optionally, set
LC_COLLATE = 'C'to be on neutral ground, or use the collation of your main language to have a default sort order. Start by reading the chapter Collation Support in the manual.I would strongly suggest to use the latest version of Postgres (9.1 at time of writing) for superior collation support.
As for the table structure: keep it simple. It sounds like there is a low, fixed number of languages to deal with. You could just have a column for each language then:
This is pretty efficient, even with many languages. NULL storage is very cheap.
If you have a varying number of languages to deal with, or many updates for individual language strings, a separate table might be the better solution. This solution assumes that you have a "primary language", where the string is always present:
Not treating the master language special and keeping all language variants in the same table might make handling in your app simpler. But it really depends on requirements.