Skip to main content

Queries with IPs

Top networks

CREATE TABLE ip (
  id serial NOT NULL,
  addr cidr NOT NULL,
  hostname character varying(25) NOT NULL
);

SELECT * FROM ip WHERE NOT EXISTS
    (SELECT addr FROM net n WHERE n.addr >> net.addr);

Bigint to IP

create function bigint_to_inet(bigint) returns inet as
$$
select (($1>>24&255)||'.'||($1>>16&255)||'.'||($1>>8&255)||'.'||($1>>0&255))::inet
$$ language sql;