搜索

首页  >  问答  >  正文

在Google BigQuery中删除双引号并将数据类型转换为字符串的方法

<p>这些值是JSON对象类型,我想将它们更改为字符串并删除双引号符号。我尝试了replace和trim函数,但它们需要字符串作为输入。<br />我还尝试了replace、trim和cast函数,但它们要求输入为字符串格式。<br />选择replace(cast([列名] as string), """) from [表名]</p>
P粉481035232P粉481035232494 天前519

全部回复(1)我来回复

  • P粉966979765

    P粉9669797652023-08-16 10:29:05

    要将JSON列转换为STRING,您可以使用JSON_EXTRACT_SCALAR函数。示例:

    WITH sample AS (
      SELECT JSON '[{"day_of_week": "SUNDAY", "from": "06:00:00", "to": "15:00:00"}]' as json_data
    )
    SELECT
      JSON_EXTRACT_SCALAR(j.day_of_week) as day_of_week,
      JSON_EXTRACT_SCALAR(j.from) as `from`,
      JSON_EXTRACT_SCALAR(j.to) as `to`
    FROM sample, UNNEST(JSON_EXTRACT_ARRAY(sample.json_data)) j
    

    输出结果:

    回复
    0
  • 取消回复