【问题标题】:Cloud Spanner - Read rows, but no returned columns?Cloud Spanner - 读取行,但没有返回列?
【发布时间】:2019-06-29 20:39:36
【问题描述】:

是否可以使用返回的数据返回列名?

例如https://cloud.google.com/spanner/docs/reads#single_read_methods:

def query_data(instance_id, database_id):
    """Queries sample data from the database using SQL."""
    spanner_client = spanner.Client()
    instance = spanner_client.instance(instance_id)
    database = instance.database(database_id)

    with database.snapshot() as snapshot:
        results = snapshot.execute_sql(
            'SELECT SingerId, AlbumId, AlbumTitle FROM Albums')

        for row in results:
            print(u'SingerId: {}, AlbumId: {}, AlbumTitle: {}'.format(*row))

row 变量不包含有关列的任何信息?

【问题讨论】:

    标签: google-cloud-spanner


    【解决方案1】:

    execute_sql 返回一个包含字段属性的StreamedResultSethttps://googleapis.github.io/google-cloud-python/latest/spanner/streamed-api.html

    【讨论】:

      【解决方案2】:

      找出问题所在。

      当您第一次执行查询然后立即读取字段而没有获取任何行时,字段属性会失败而不给出警告。

      你需要读一行所以内部参数

      _meta_data

      用数据填充。

      【讨论】:

        猜你喜欢
        • 2017-07-07
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2023-02-16
        • 2021-12-10
        • 1970-01-01
        • 2012-04-07
        • 2020-06-10
        相关资源
        最近更新 更多