在postgresql 9.4中,新的JSONB被合并.
在postgresql 9.3中的实时数据库中,我有一个JSON列.
我想将其迁移到JSONB.
假设我首先将数据库迁移到9.4(使用pg_upgrade).接下来我该怎么办?
我想要一个漂亮的打印摘要,说明正在运行的测试,类似于
rspec --color --format doc
Run Code Online (Sandbox Code Playgroud)
minitest能做到吗?
是否有任何有效的区别
Content-Encoding: UTF-8
Content-Type: text/html; charset=utf-8
Run Code Online (Sandbox Code Playgroud)
?
显然||=不行
def x?
@x_query ||= expensive_way_to_calculate_x
end
Run Code Online (Sandbox Code Playgroud)
因为如果它原来是false或nil,然后expensive_way_to_calculate_x将得到反复执行.
目前我知道的最好方法是将值放入Array:
def x?
return @x_query.first if @x_query.is_a?(Array)
@x_query = [expensive_way_to_calculate_x]
@x_query.first
end
Run Code Online (Sandbox Code Playgroud)
有更传统或更有效的方法吗?
更新我意识到我想要记忆nil除了false- 这一直回到https://rails.lighthouseapp.com/projects/8994/tickets/1830-railscachefetch-does-not-work-with-false-boolean - 缓存价值 - 我向安德鲁马歇尔道歉,他给出了一个完全正确的答案.
JDBC规范中有什么允许的吗?要转义并且不是参数占位符?
例如,Postgres允许您?用作运算符:
SELECT * FROM tbl WHERE tbl.data ? 'abc'
Run Code Online (Sandbox Code Playgroud)
JDBC驱动程序可以让你使用吗?作为运营商仍然是符合JDBC的?
我必须手动执行SQL才能使用TRUNCATE命令,这似乎很奇怪.DHH是否保护我免受伤害?
也许你已经看过了......
2012-03-07T15:36:25+00:00 heroku[web.1]: Stopping process with SIGTERM 2012-03-07T15:36:36+00:00 heroku[web.1]: Stopping process with SIGKILL 2012-03-07T15:36:36+00:00 heroku[web.1]: Error R12 (Exit timeout) -> Process failed to exit within 10 seconds of SIGTERM 2012-03-07T15:36:38+00:00 heroku[web.1]: Process exited with status 137
我可以告诉heroku发送SIGQUIT吗?或者,我可以告诉独角兽将其SIGTERM视为优雅的关闭吗?
这在我的MongoDB日志中反复重复.一些说明:
new Date(5610408224193773570) 总是一样的verbose = true 在配置文件中注释掉了可能是我的oplog太大了,所以每次辅助查询它需要4秒钟?
Wed May 25 00:35:58 [dur] lsn set 1552362
Wed May 25 00:36:02 [conn14] getmore local.oplog.rs cid:265112601668423723 getMore: { ts: { $gte: new Date(5610408224193773570) } } bytes:20 nreturned:0 3979ms
Wed May 25 00:36:06 [conn14] getmore local.oplog.rs cid:265112601668423723 getMore: { ts: { $gte: new Date(5610408224193773570) } } bytes:20 nreturned:0 3979ms
Wed May 25 00:36:11 [conn14] getmore local.oplog.rs cid:265112601668423723 getMore: { ts: { $gte: new Date(5610408224193773570) } …Run Code Online (Sandbox Code Playgroud) 有没有办法ARel将(清理,可能是别名等)列名称写入CONCAT()其他SQL函数?
以下是使用AVG()的方法 ...
?> name = Arel::Attribute.new(Arel::Table.new(:countries), :name)
=> #<struct Arel::Attributes::Attribute [...]
?> population = Arel::Attribute.new(Arel::Table.new(:countries), :population)
=> #<struct Arel::Attributes::Attribute [...]
?> Country.select([name, population.average]).to_sql
=> "SELECT `countries`.`name`, AVG(`countries`.`population`) AS avg_id FROM `countries`"
Run Code Online (Sandbox Code Playgroud)
(是的,我知道avg_id每一行都是一样的,只是想说明我的问题)
那么如果我想要一个不同的功能呢?
?> Country.select(xyz).to_sql # Arel::Concat.new(name, population) or something?
=> "SELECT CONCAT(`countries`.`name`, ' ', `countries`.`population`) AS concat_id FROM `countries`"
Run Code Online (Sandbox Code Playgroud)
谢谢!
这是对Postgres 9.1.6的慢查询,即使最大计数为2,两行已经由主键标识:(4.5秒)
EXPLAIN ANALYZE SELECT COUNT(*) FROM tbl WHERE id IN ('6d48fc431d21', 'd9e659e756ad') AND data ? 'building_floorspace' AND data ?| ARRAY['elec_mean_monthly_use', 'gas_mean_monthly_use'];
QUERY PLAN
----------------------------------------------------------------------------------------------------------------------------------------------------
Aggregate (cost=4.09..4.09 rows=1 width=0) (actual time=4457.886..4457.887 rows=1 loops=1)
-> Index Scan using idx_tbl_on_data_gist on tbl (cost=0.00..4.09 rows=1 width=0) (actual time=4457.880..4457.880 rows=0 loops=1)
Index Cond: ((data ? 'building_floorspace'::text) AND (data ?| '{elec_mean_monthly_use,gas_mean_monthly_use}'::text[]))
Filter: ((id)::text = ANY ('{6d48fc431d21,d9e659e756ad}'::text[]))
Total runtime: 4457.948 ms
(5 rows)
Run Code Online (Sandbox Code Playgroud)
嗯,也许如果我先用主键部分做一个子查询... :(不,仍然是4.5秒以上)
EXPLAIN ANALYZE SELECT COUNT(*) FROM ( SELECT * FROM tbl WHERE …Run Code Online (Sandbox Code Playgroud) ruby ×4
postgresql ×3
activerecord ×2
arel ×1
encoding ×1
heroku ×1
http ×1
http-headers ×1
indexing ×1
inlining ×1
jdbc ×1
jsonb ×1
logging ×1
memoization ×1
minitest ×1
mongodb ×1
null ×1
replication ×1
signals ×1
sql ×1
subquery ×1
testing ×1
unicorn ×1
utf-8 ×1