From: | "Ilya A(dot) Kovalenko" <shadow(at)oganer(dot)net> |
---|---|
To: | Bruce Momjian <pgsql-hackers(at)postgresql(dot)org> |
Subject: | Re: inet increment w/ int8 |
Date: | 2005-04-19 12:11:43 |
Message-ID: | 091461875.20050419201143@oganer.net |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
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:shadow(at)oganer(dot)net)
From | Date | Subject | |
---|---|---|---|
Next Message | Bruce Momjian | 2005-04-19 14:34:54 | Re: [HACKERS] Implementation of SQLCODE and SQLERRM variables |
Previous Message | Oleg Bartunov | 2005-04-19 11:23:37 | Re: Problem with PITR recovery |