Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/76.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
带DNS记录的Postgresql数据库:如何批量增加串行数据_Sql_Postgresql_Dns - Fatal编程技术网

带DNS记录的Postgresql数据库:如何批量增加串行数据

带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

我正在使用带有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 ...
如何批量更新序列号?我想学习如何将它们增加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;