我正在尝试加快对 PostgreSQL 数据库中存储的一些 json 数据的查询速度。我继承了一个应用程序,该应用程序查询一个名为 的 PostgreSQL 表,该data表带有一个名为 的字段value,其中值是类型为 json 的 blob jsonb。
它大约有 300 行,但从 5 个 json 元素中选择此数据需要 12 秒。json blob 有点大,但我需要的数据都在 json 嵌套的顶层(如果有帮助的话)。
我尝试添加索引,CREATE INDEX idx_tbl_data ON data USING gin (value);但这没有帮助。我应该使用不同的索引吗?长期愿景是重写应用程序以将数据移出 json,但由于应用程序其他部分的复杂性,这至少需要 30-40 个工作日的工作,所以我想看看是否可以可以在短期内加快速度。
不确定它是否有帮助,但构成此结果集的基础数据不会经常更改。经常发生变化的是 json blob 中更下方的数据。
SELECT
value::json ->> 'name' AS name,
value::json ->> 'mnemonic' AS mnemonic,
value::json ->> 'urlName' AS "urlName",
value::json ->> 'countryCode' AS "countryCode",
value::json #>>'{team}' AS team
FROM
data;
Run Code Online (Sandbox Code Playgroud) 我们每周都会召开一次集成会议,审核未合并到主服务器的分支机构中的代码.作为起点,我们使用它来列出开放分支
git branch -a --no-merged master
我们在门票号码后命名我们的分支机构,因此很难看到我们真正关注的是什么.我回来了
BUG_1231231
BUG_1412434
FEATURE_1231231
FEATURE_1232244
我知道我可以通过运行来添加和查看说明
git branch --edit-description BUG_1231231
git config branch.BUG_1231231
问题是这些描述似乎存储在我本地存储库的配置中.这些描述可以推送到遥控器吗?
下面的代码下载一个网页,查找和元素,然后运行一个正则表达式来解析字符串中的一个数字。它似乎适用于我的 python 3.7 测试系统,但不适用于我的 python 3.5。我正在下载网页,使用 Xpath 查找文本块。xpath 返回类似 'International (21)' 或 'Books (99)' 的内容,我想提取数字,即 21 或 99。
在 python 3.5 中,我返回“ TypeError: '_sre.SRE_Match' object is not subscriptable.'
我不相信错误是版本的差异,但这是唯一已知的差异。xpath 似乎正在工作,因为它返回 ' <_sre.SRE_Match 对象;span=(14, 18), match='(21)'>'当我打印 CountObj 时。
我应该为 python 3.5 做一些调整,有没有更好的方法来编码?
driver = webdriver.Chrome()
driver.get(url); #Download the URL passed from mysql
CatAndCount = driver.find_element_by_xpath('//h2 [@class="searchResultsTitle"]').text
# the above line returns with a name and value like 'International (21)'
CountObj = re.search("\((.*?)\)",CatAndCount) # look for the number, 21 in example …Run Code Online (Sandbox Code Playgroud) 我正在使用DBI并希望将MySQL WARNINGS的日志记录添加到此脚本中.我能够毫无问题地记录真正的MySQL错误,但此时我需要追踪正在生成的MySQL警告.如果mysql语句失败,我可以将错误的sql语句打印到bad_sql.txt并自动生成一封电子邮件.我需要做两个更改,我真的卡住了1)如果语句执行但有一个mysql警告我想要捕获到last_sql_warning.txt 2)如果语句failes做到锁定超时我想重新提交最多查询两次.
这就是现在被转储到日志中的内容.
MiscLibs::MySQL::MySQLDoCmd, MySQL.pm line 564:
-->UPDATE tbl_xxx_files SET ReloadStart=123" WHERE (FileName="image.txt")<--
相关的代码块
#=====================================================================================
# Execute MySQL commands and handle errors
#=====================================================================================
sub MySQLDoCmd ($;$) {
my ($MySQLCmd, $Quite) = @_;
if ( eval { $DBHandle->do($MySQLCmd) } ) {
open (MYFILE2, '>/bb/bin/fa/logs/last_sql_warning.txt');
# trying to write warning to log. As a first pass I was attempting to write
# each statement to the log and include any warnings. What I would like code to
# do is check …Run Code Online (Sandbox Code Playgroud) from bs4 import BeautifulSoup
import codecs
import sys
import urllib.request
site_response= urllib.request.urlopen("http://site/")
html=site_response.read()
file = open ("cars.html","wb") #open file in binary mode
file.write(html)
file.close()
soup = BeautifulSoup(open("cars.html"))
output = (soup.prettify('latin'))
#print(output) #prints whole file for testing
file_output = open ("cars_out.txt","wb")
file_output.write(output)
file_output.close()
fulllist=soup.find_all("div", class_="row vehicle")
#print(fulllist) #prints each row vehicle class for debug
for item in fulllist:
item_print=item.find("span", class_="modelYearSort").string
item_print=item_print + "|" + item.find("span", class_="mmtSort").string
seller_phone=item.find("span", class_="seller-phone")
print(seller_phone)
# item_print=item_print + "|" + item.find("span", class_="seller-phone").string
item_print=item_print + "|" + item.find("span", …Run Code Online (Sandbox Code Playgroud) 我下面有一些 python 代码,它沿着树走下去,但我希望它沿着树向下工作,检查根据值有条件地采取一些路径。我想LandedPrice根据条件获取树的分支fulfillmentChannel
parsed_results['LowestLanded'] = sku_multi_sku['Summary']['LowestPrices']['LowestPrice']['LandedPrice']['Amount']['value']
Run Code Online (Sandbox Code Playgroud)
沿着这棵树走下去,但是值,因为有两个LowestPrice记录/字典为每个 condition和fulfillmentChannel 一对返回一个。我想过滤condition=new,fulfillmentChannel=Amazon所以我只得到一条记录。当我解析 XML 数据时,我可以使用类似于此处的代码来完成LowestPrices/LowestPrice[@condition='new'][@fulfillmentChannel='Merchant']/LandedPrice/Amount"此操作,但无法获得类似的代码来工作。我该如何用字典做到这一点?
"LowestPrices":{
"value":"\n ",
"LowestPrice":[
{
"value":"\n ",
"condition":{
"value":"new" #condtion new
},
"fulfillmentChannel":{
"value":"Amazon" ## fulfilllmentChannel #1
},
"LandedPrice":{
"value":"\n ",
"CurrencyCode":{
"value":"USD"
},
"Amount":{
"value":"19.57"
}
},
"ListingPrice":{
"value":"\n ",
"CurrencyCode":{
"value":"USD"
},
"Amount":{
"value":"19.57"
}
},
"Shipping":{
"value":"\n ",
"CurrencyCode":{
"value":"USD"
},
"Amount":{
"value":"0.00"
}
}
},
{
"value":"\n ",
"condition":{
"value":"new"
},
"fulfillmentChannel":{ …Run Code Online (Sandbox Code Playgroud) python ×3
json ×2
python-3.x ×2
dbi ×1
dictionary ×1
git ×1
jsonb ×1
list ×1
mysql ×1
perl ×1
postgresql ×1
regex ×1
warnings ×1
xpath ×1