开发者社区 > 大数据与机器学习 > 大数据计算 MaxCompute > 正文

pyodps 在查询一个SQL语句时,如果查询字段是以0开头的字符串,就会报错!!

部分语句如下:

with o.execute_sql("select * from table_name where a='01234556'").open_reader() as reader:
for record in reader:   
     print(record)

报错内容如下:

Traceback (most recent call last): File "D:/Python36/odps/venv/dataworks/odps111.py", line 42, in for record in reader: File "D:\Python36\odps\venv\lib\site-packages\odps\models\instance.py", line 823, in iter for record in self.read(): File "D:\Python36\odps\venv\lib\site-packages\odps\models\instance.py", line 846, in read for record in reader[::step]: File "D:\Python36\odps\venv\lib\site-packages\odps\readers.py", line 88, in _iter record = next(self) File "D:\Python36\odps\venv\lib\site-packages\odps\tunnel\io\reader.py", line 206, in next record = self.read() File "D:\Python36\odps\venv\lib\site-packages\odps\tunnel\io\reader.py", line 200, in read record[i] = self._read_field(self._columns[i].type) File "D:\Python36\odps\venv\lib\site-packages\odps\types.py", line 447, in setitem self._set(key, value) File "D:\Python36\odps\venv\lib\site-packages\odps\types.py", line 423, in _set val = validate_value(value, data_type) File "D:\Python36\odps\venv\lib\site-packages\odps\types.py", line 1454, in validate_value res = data_type.validate_composite_values(value) File "D:\Python36\odps\venv\lib\site-packages\odps\types.py", line 1087, in validate_composite_values self.validate_value(value) File "D:\Python36\odps\venv\lib\site-packages\odps\types.py", line 1058, in validate_value scaled_val = val.quantize(to_scale, _decimal.ROUND_HALF_UP) decimal.InvalidOperation: [<class 'decimal.InvalidOperation'>]

Process finished with exit code 1

展开
收起
2jt3rmcqdmp74 2023-02-27 22:19:51 339 0
1 条回答
写回答
取消 提交回答
  • 月移花影,暗香浮动

    可以使用双引号将字段名括起来,例如:

    SELECT "0fieldname" FROM table_name;

    2023-03-01 10:58:56
    赞同 展开评论 打赏

MaxCompute(原ODPS)是一项面向分析的大数据计算服务,它以Serverless架构提供快速、全托管的在线数据仓库服务,消除传统数据平台在资源扩展性和弹性方面的限制,最小化用户运维投入,使您经济并高效的分析处理海量数据。

相关电子书

更多
DataWorks调度任务迁移最佳实践-2020飞天大数据平台实战应用第一季 立即下载
DataWorks商业化资源组省钱秘籍-2020飞天大数据平台实战应用第一季 立即下载
基于DataWorks数据服务构建疫情大屏-2020飞天大数据平台实战应用第一季 立即下载