Re: inet increment w/ int8

From: Ilya A. Kovalenko
Subject: Re: inet increment w/ int8
Date: ,
Msg-id: 091461875.20050419201143@oganer.net
(view: Whole thread, Raw)
In response to: Re: inet increment w/ int8  (Bruce Momjian)
Responses: Re: inet increment w/ int8  (Bruce Momjian)
List: pgsql-hackers

Tree view

inet increment w/ int8  ("Ilya A. Kovalenko", )
 Re: inet increment w/ int8  ("Ilya A. Kovalenko", )
 Re: inet increment w/ int8  (Bruce Momjian, )
  Re: inet increment w/ int8  ("Ilya A. Kovalenko", )
   Re: inet increment w/ int8  (Bruce Momjian, )
    Re: inet increment w/ int8  (Greg Stark, )
     Re: inet increment w/ int8  (Bruce Momjian, )
      Re: inet increment w/ int8  (Greg Stark, )
       Re: inet increment w/ int8  ("Ilya A. Kovalenko", )
        Re: inet increment w/ int8  (Bruno Wolff III, )
      Re: inet increment w/ int8  ("Ilya A. Kovalenko", )
    Re: inet increment w/ int8  (Bruno Wolff III, )
  Re: inet increment w/ int8  (Patrick Welche, )
 Re: inet increment w/ int8  (Bruce Momjian, )
  Re: inet increment w/ int8  (Douglas McNaught, )
   Re: inet increment w/ int8  (Bruce Momjian, )
    Re: inet increment w/ int8  (Stephen Frost, )
    Re: inet increment w/ int8  ("Sander Steffann", )

BM> Would you modify this so it can go in /contrib or pgfoundry?  Is there
BM> general interest for this?
 Actually, I suggested to do such or similar function as internal.
PostgreSQL has inet/cidr - excellent data type and good facilities to
examine and compare inet values, but has no facilities to modify
them (i.e. get-change-return operations).
 There is place for many useful operators and functions to do but
they not invented enough yet (to supplement with existing facilites
and each other).
  Only facility that has no doubt is increment/decrement inet
address value with numeric value. It nicely supplements existing
inet compare operators (that compares two addresses as numeric
values). Also, it can be used to override "+" and "-" operators
between inet and numeric values.
 I understand, that you have more important things to do, so I write
this function, to save your time.
 Maybe, it is good idea, to implement such functions separatelly as
/contrib ... for a start ...
 Live example for inet_inc() (as "+" operator)

(PL/pgSQL)
> -- (try to) Peek address from group pool
>    SELECT next INTO next_ip FROM peer_ranges WHERE
>       group_id = (SELECT id FROM peer_groups WHERE name = $3) AND
>       next < last
>       ORDER BY first LIMIT 1;
>
> -- Return NULL if pool is empty
>    IF NOT FOUND THEN
>       RAISE NOTICE ''Group address pool is empty'';
>       RETURN NULL;
>    END IF;
>
> -- Update pool
>    UPDATE peer_ranges SET next = next_ip + 1 WHERE next = next_ip;
>
>    RETURN next_ip;

where, peer_ranges is:

CREATE TABLE peer_ranges
( group_id  bigint NOT NULL REFERENCES peer_groups (id), first     inet   NOT NULL UNIQUE, next      inet   NOT NULL
UNIQUE,last      inet   NOT NULL UNIQUE
 
);

Thank you,

Ilya A. Kovalenko          (mailto:)




pgsql-hackers by date:

From: Bruce Momjian
Date:
Subject: Re: Problem with PITR recovery
From: Bruce Momjian
Date:
Subject: Re: inet increment w/ int8