如何在BigQuery上以字符串类型提取Postgres Hstore

时间:2018-10-02 09:49:06

标签: google-bigquery

我从具有const icon = '<svg aria-hidden="true" data-prefix="fas" data-icon="paragraph" class="svg-inline--fa fa-paragraph fa-w-14 " role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 448 512"><path fill="currentColor" d="M408 32H177.531C88.948 32 16.045 103.335 16 191.918 15.956 280.321 87.607 352 176 352v104c0 13.255 10.745 24 24 24h32c13.255 0 24-10.745 24-24V112h32v344c0 13.255 10.745 24 24 24h32c13.255 0 24-10.745 24-24V112h40c13.255 0 24-10.745 24-24V56c0-13.255-10.745-24-24-24z"></path></svg>'; class App extends React.Component { constructor(props) { super(props); } handleClick(event) { event.stopPropagation(); console.log(event.target); } render() { return ( <div> <button onClick={this.handleClick}> <span dangerouslySetInnerHTML={{__html: icon}} /> </button> </div> ) } } ReactDOM.render(<App />, document.getElementById('root')); 类型的Postgres下载数据,并将其上传到具有STRING类型的Bigquery上。该列如下所示。

hstore

如何使用BigQuery查询获取网站网址字段"bar"=>"12356","website_url"=>"http://www.google.com","baz"=>"1722.0"

2 个答案:

答案 0 :(得分:2)

您可以按以下示例使用REGEXP_EXTRACT(str, r'"website_url"=>"(.*?)".')

#standardSQL
WITH `project.dataset.table` AS (
  SELECT '"bar"=>"12356","website_url"=>"http://www.google.com","baz"=>"1722.0"' str
)
SELECT 
  REGEXP_EXTRACT(str, r'"website_url"=>"(.*?)".') url
FROM `project.dataset.table` 

有结果

Row url  
1   http://www.google.com    

答案 1 :(得分:0)

您可以使用REGEXP_EXTRACT函数从字段中提取相关的字符串并将其捕获为新字段。例如:

REGEXP_EXTRACT(MYFIELD, 'www.([^\.]+)\.com') AS website_url

在示例中使用时,将返回:

www.google.com