gpt4 book ai didi

sql - 使用 EXTENSION address_standardizer 的 parse_address 的错误输出

转载 作者:行者123 更新时间:2023-11-29 13:40:59 24 4
gpt4 key购买 nike

我正在尝试清理和解析地址,但在使用相同扩展名“address_standardizer”的两个查询之间没有得到解析结果。在我的主要查询中,只解析了某些城市。州和 zip 都很好。然而,在测试为什么它缺少大多数城市时,我在测试查询中看到了城市。

我正在使用相同的基本查询 here修改为:

SELECT city, (a).num, (a).street, (a).city, (a).state, (a).zip, (a).zipplus
FROM (SELECT city, parse_address(city) As a
from add_data
where city ~ ', *\D\D \d{5}$') AS p;

这导致:

city                    |num|street |city|state |zip  |zipplus
HONOLULU, HI 96819 | | | |HI |96819|
NEW YORK, NY 10018 | | | |NY |10018|
NEWHALL, CA 91321 | | | |CA |91321|
LONG BEACH, CA 90815 | | | |CA |90815|
LYNNFIELD, MA 01940 | | | |MA |01940|
CHATTANOOGA, TN 37407 | | | |TN |37407|

所以我测试了:

select city, parse_address(city) as cty
from add_data
where city ~ ', *\D\D \d{5}$';

这给了我预期的城市、州和 zip 解析:

city                        |cty
BEVERLY HILLS, CA 90213 |(,,,"BEVERLY HILLS",,CA,90213,""US)
OXNARD, CA 93031 |(,,,"OXNARD",,CA|93031,""US)
STREETSBOSO, OH 44241 |(,,,"STREETSBOSO",,OH,44241,""US)
OMAHA, NE 68114 |(,,,"OMAHA",,NE,68114,""US)
CHATTANOOGA, TN 37401 |(,,,"CHATTANOOGA",,TN,37401,""US)
CUYAHOCA HEIGHTS, OH 44125 |(,,,"CUYAHOCA HEIGHTS",,OH,44125,""US)

我不确定我的查询在哪里会丢失正在解析的城市,而它仍然处理状态和 zipper 。我将如何重写查询以获得正确的解析结果?

最佳答案

parse_address 需要一个完整的输入,或者一些地址部分缺失的指示。

首先,它有助于显示输出列名称:我们看到城市未被解析,因为它在 address1 列中,这是街道信息的聚合。

select (parse_address('BEVERLY HILLS, CA 90213')).*;
num | street | street2 | address1 | city | state | zip | zipplus | country
-----+--------+---------+---------------+------+-------+-------+---------+---------
| | | BEVERLY HILLS | | CA | 90213 | | US
(1 row)

如果我们添加街道信息,则可以正确识别城市。

select (parse_address('123 ab street BEVERLY HILLS, CA 90213')).*;
num | street | street2 | address1 | city | state | zip | zipplus | country
-----+-----------+---------+---------------+---------------+-------+-------+---------+---------
123 | ab street | | 123 ab street | BEVERLY HILLS | CA | 90213 | | US
(1 row)

要正确解析不包含街道的地址的城市名称,您需要通过添加前导逗号来明确告知没有街道信息。

select (parse_address(',BEVERLY HILLS, CA 90213')).*;
num | street | street2 | address1 | city | state | zip | zipplus | country
-----+--------+---------+----------+---------------+-------+-------+---------+---------
| | | | BEVERLY HILLS | CA | 90213 | | US
(1 row)

请注意,对于非标准街道类型或复杂情况,也需要在街道和城市之间添加逗号:

select (parse_address('123 ab MystreetType BEVERLY HILLS, CA 90213')).*;
num | street | street2 | address1 | city | state | zip | zipplus | country
-----+-------------------------+---------+-----------------------------+-------+-------+-------+---------+---------
123 | ab MystreetType BEVERLY | | 123 ab MystreetType BEVERLY | HILLS | CA | 90213 | | US
(1 row)


select (parse_address('123 ab MystreetType, BEVERLY HILLS, CA 90213')).*;
num | street | street2 | address1 | city | state | zip | zipplus | country
-----+-----------------+---------+---------------------+---------------+-------+-------+---------+---------
123 | ab MystreetType | | 123 ab MystreetType | BEVERLY HILLS | CA | 90213 | | US

关于sql - 使用 EXTENSION address_standardizer 的 parse_address 的错误输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55435425/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com