带DNS记录的Postgresql数据库:如何批量增加串行数据
我正在使用带有Postgresql后端的PDN。我有多个区域,每个SOA记录看起来有点像这样: pdns=# SELECT content FROM records WHERE type = 'SOA'; ns1.example.com. hostmaster.example.com. 2014031201 14400 1800 604800 3600 ns1.otherzone.tld. hostmaster.otherzone.tld. 2014022403 14400 1800 604800 3600 ...带DNS记录的Postgresql数据库:如何批量增加串行数据,sql,postgresql,dns,Sql,Postgresql,Dns,我正在使用带有Postgresql后端的PDN。我有多个区域,每个SOA记录看起来有点像这样: pdns=# SELECT content FROM records WHERE type = 'SOA'; ns1.example.com. hostmaster.example.com. 2014031201 14400 1800 604800 3600 ns1.otherzone.tld. hostmaster.otherzone.tld. 2014022403 14400 1800 60480
如何批量更新序列号?我想学习如何将它们增加1,或者如何将它们设置为特定的值,例如,今天的值是2014032800。对我来说似乎建模不好-或者更确切地说,他们已经将数据非规范化,以便高效查询,但代价是使SQL中的操作变得非常困难 您需要: 匹配并提取SOA 增加它 重建原始字符串形式 由于域名中不允许使用空格,因此可以使用模式匹配来实现这一点,如string\u to\u数组、regexp\u split\u to\u表等 比如:
CREATE OR REPLACE FUNCTION increment_soa(text) RETURNS text AS $$
SELECT
array_to_string(
array_cat(
part[1:2],
array_cat(
ARRAY[(part[3]::integer + 1)::text],
part[4:7]
)
),
' '
)
FROM (
SELECT string_to_array($1, ' ')
) soa_parts(part)
$$ LANGUAGE sql;