summaryrefslogtreecommitdiff
path: root/sql
diff options
context:
space:
mode:
authorYorhel <git@yorhel.nl>2022-08-26 10:39:43 +0200
committerYorhel <git@yorhel.nl>2022-08-26 10:39:43 +0200
commit71afe313e98395fefc6528ef1fea69b799613310 (patch)
tree4aa8764a2da2238d93561e6b2ddf6013b38c06f6 /sql
parent007e7d1c6839c55f578a5db10c3536c12327f06b (diff)
SQL: Add formatting function for ipinfo values
Diffstat (limited to 'sql')
-rw-r--r--sql/func.sql12
1 files changed, 12 insertions, 0 deletions
diff --git a/sql/func.sql b/sql/func.sql
index 842d477b..af51303a 100644
--- a/sql/func.sql
+++ b/sql/func.sql
@@ -10,6 +10,18 @@
-- with that, either.
+-- Handy function to format an ipinfo type for human consumption.
+CREATE OR REPLACE FUNCTION fmtip(n ipinfo) RETURNS text AS $$
+ SELECT COALESCE(COALESCE((n).country, 'X')||':'||(n).asn||COALESCE(':'||(n).as_name,'')||'/', (n).country||'/', '')
+ || abbrev((n).ip)
+ || CASE WHEN (n).anonymous_proxy THEN ' ANON' ELSE '' END
+ || CASE WHEN (n).sattelite_provider THEN ' SAT' ELSE '' END
+ || CASE WHEN (n).anycast THEN ' ANY' ELSE '' END
+ || CASE WHEN (n).drop THEN ' DROP' ELSE '' END
+$$ LANGUAGE SQL IMMUTABLE;
+
+
+
CREATE OR REPLACE FUNCTION search_gen_vn(vnid vndbid) RETURNS text AS $$
SELECT coalesce(string_agg(t, ' '), '') FROM (
SELECT t FROM (