What is the “best” way to store international addresses in a database?

后端 未结 6 531
梦如初夏
梦如初夏 2020-12-04 23:46

What is the \"best\" way to store international addresses in a database? Answer in the form of a schema and an explanation of the reasons why you chose to normalize

6条回答
  •  自闭症患者
    2020-12-05 00:42

    Plain freeform text.

    Validating all the world's post/zip codes is too hard; a fixed list of countries is too politically sensitive; mandatory state/region/other administrative subdivision is just plain inappropriate (all too often I'm asked which county I live in--when I don't, because Greater London is not a county at all).

    More to the point, it's simply unnecessary. Your application is highly unlikely to be modelling addresses in any serious way. If you want a postal address, ask for the postal address. Most people aren't so stupid as to put in something other than a postal address, and if they do, they can kiss their newly purchased item bye-bye.

    The exception to this is if you're doing something that's naturally constrained to one country anyway. In this situation, you should ask for, say, the { postcode, house number } pair, which is enough to identify a postal address. I imagine you could achieve similar things with the extended zip code in the US.

提交回复
热议问题