Python 3.x Python Simple Salesforce选择为不工作
我正在尝试标准的选择。。。AS调用使用Python Salesforce API重命名查询输出中的列,并引发以下错误:Python 3.x Python Simple Salesforce选择为不工作,python-3.x,simple-salesforce,Python 3.x,Simple Salesforce,我正在尝试标准的选择。。。AS调用使用Python Salesforce API重命名查询输出中的列,并引发以下错误: ... unexpected token: 'AS'", 'errorCode': 'MALFORMED_QUERY'} 到目前为止,来自SOQL的大多数本机语言调用都是在API中工作的,而且似乎,从,选择。。。AS是有效的SOQL 查询大纲: from simple_salesforce import Salesforce sf = Salesforce(username
... unexpected token: 'AS'", 'errorCode': 'MALFORMED_QUERY'}
到目前为止,来自SOQL的大多数本机语言调用都是在API中工作的,而且似乎,从,选择。。。AS是有效的SOQL
查询大纲:
from simple_salesforce import Salesforce
sf = Salesforce(username=myusername, password=mypassword, security_token=mytoken)
query = "select closedate as Date from opportunity"
query_list = sf.query_all(query)['records']
编辑
即使按照上面链接中的建议将新列名放在引号内,错误仍然存在:
query = "select closedate as \"Date\" from Opportunity"
谢谢语法似乎不正确
根据此处记录的别名符号尝试
query=“select closedate from Opportunity”
:语法似乎不正确
根据此处记录的别名符号尝试
query=“select closedate from Opportunity”
:如Terminus所述,SOQL在大多数上下文(包括您的上下文)中都不可能使用SOQL字段别名。我见过的唯一一种在SOQL中使用别名的情况是在聚合查询中。例如,在apex中,您可以编写:
AggregateResult myResult = [SELECT count(Id) SpecialName FROM Contact];
system.debug(myResult);
并收到结果:
DEBUG|AggregateResult:{SpecialName=1630}
OrderedDict([('totalSize', 1),
('done', True),
('records',
[OrderedDict([('attributes',
OrderedDict([('type', 'AggregateResult')])),
('SpecialName', 6587)])])])
在python中,通过simple salesforce可以看到:
sf.query_all('SELECT count(Id) SpecialName FROM Contact')
结果是:
DEBUG|AggregateResult:{SpecialName=1630}
OrderedDict([('totalSize', 1),
('done', True),
('records',
[OrderedDict([('attributes',
OrderedDict([('type', 'AggregateResult')])),
('SpecialName', 6587)])])])
如果这回答了您的问题,请将其标记为已回答。正如Terminus提到的,SOQL字段别名在大多数上下文中都是不可能的,包括您的上下文。我见过的唯一一种在SOQL中使用别名的情况是在聚合查询中。例如,在apex中,您可以编写:
AggregateResult myResult = [SELECT count(Id) SpecialName FROM Contact];
system.debug(myResult);
并收到结果:
DEBUG|AggregateResult:{SpecialName=1630}
OrderedDict([('totalSize', 1),
('done', True),
('records',
[OrderedDict([('attributes',
OrderedDict([('type', 'AggregateResult')])),
('SpecialName', 6587)])])])
在python中,通过simple salesforce可以看到:
sf.query_all('SELECT count(Id) SpecialName FROM Contact')
结果是:
DEBUG|AggregateResult:{SpecialName=1630}
OrderedDict([('totalSize', 1),
('done', True),
('records',
[OrderedDict([('attributes',
OrderedDict([('type', 'AggregateResult')])),
('SpecialName', 6587)])])])
如果这回答了您的问题,请将其标记为已回答。Oracle SQL与SOQL不同;不幸的是,您链接的问题无法帮助您。事实上,根据目前的情况,除非对聚合函数的结果进行别名,否则不可能在SOQL中对列进行别名;不幸的是,您链接的问题无法帮助您。事实上,根据目前的情况,除非对聚合函数的结果进行别名处理,否则不可能在SOQL中对列进行别名处理。它是否在select语句中描述别名表示法?它是否在select语句中描述别名表示法?