E
E
Egor Mikheev2016-03-01 23:45:46
MySQL
Egor Mikheev, 2016-03-01 23:45:46

How to correctly split a postal address into elements in MySQL?

Hello, I can’t figure out how to correctly atomize the mailing address through substring_index.
There is a line:
Arkhangelsk, st. Mayakovsky, d. 45
We select the street:

concat(substring_index(substring_index(substring_index(`houseProfile`.`adressHouse`,',',2),',',-(1)),' ',-(1)),' ',substring_index(substring_index(substring_index(`houseProfile`.`adressHouse`,',',2),',',-(1)),'.',1)) AS `улица`,

We get: Mayakovsky st
. But in the case of: Arkhangelsk, st. Belomorskaya flotilla, 12 - it turns out: flotilla st.
Is it possible to somehow process it so that in this case the same thing turned out as it should?
You can, of course, also through PHP, but in principle I want to here
SET FOREIGN_KEY_CHECKS=0;
-- ----------------------------
-- Table structure for `test`
-- ----------------------------
DROP TABLE IF EXISTS `test`;
CREATE TABLE `test` (
  `adress` text
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

-- ----------------------------
-- Records of test
-- ----------------------------
INSERT INTO `test` VALUES ('г. Архангельск, ул. Полярная, д. 32');
INSERT INTO `test` VALUES ('г. Архангельск, ул. Советская, д. 22');
INSERT INTO `test` VALUES ('г. Архангельск, ул. Беломорской флотилии, д. 13');
INSERT INTO `test` VALUES ('г. Архангельск, ул. Терпких игрыстых вин, д. 13');
INSERT INTO `test` VALUES ('г. Архангельск, ул. тут-просто тест-такой, д. 13');

Answer the question

In order to leave comments, you need to log in

3 answer(s)
D
Dimonchik, 2016-03-02
@dimonchik2013

stackoverflow.com/questions/4078838/mysql-array-da...

E
Egor Mikheev, 2016-03-02
@ogregor

Damn, this question has already been, but the answer has not been received:
https://toster.ru/q/260915

E
entermix, 2016-03-02
@entermix

Use regular expressions:
www.mysql.ru/docs/man/Regexp.html

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question