From: | Dawid Kuroczko <qnex42(at)gmail(dot)com> |
---|---|
To: | "Andrey V(dot) Semyonov" <wilfre(at)mail(dot)ru> |
Cc: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: inet-type sequence |
Date: | 2005-01-29 22:13:08 |
Message-ID: | 758d5e7f05012914136f05f8d9@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
On Sat, 29 Jan 2005 22:24:46 +0300, Andrey V. Semyonov <wilfre(at)mail(dot)ru> wrote:
> Hi there.
> How do I create a sequence of type inet for automatic assignment an
> IP/32 to a new row?
> Neither nextval() nor CREATE SEQUENCE seem for me to work with type inet
> (PostgreSQL 8.0.0, pgAdmin III v 1.2.0).
>
> ---------------------------(end of broadcast)---------------------------
> TIP 8: explain analyze is your friend
>
First of all you need a way to convert bigint to inet, say, something
like:
CREATE OR REPLACE FUNCTION bigint_to_inet(i bigint) RETURNS inet AS $$
BEGIN RETURN ((i / 16777216)||'.'||(i % 16777216 / 65536)||'.'||(i
% 65536 / 256)||'.'||(i % 256))::inet; END;
$$ LANGUAGE plpgsql IMMUTABLE;
then create a sequence:
CREATE SEQUENCE foo_inetaddrs_seq START 192*16777216::bigint+168*65536;
CREATE TABLE foo (
inetaddrs inet default
bigint_to_inet(netval('foo_inetaddrs_seq')) PRIMARY KEY,
--- rest with whatever...
);
Something like this?
From | Date | Subject | |
---|---|---|---|
Next Message | Bruno Wolff III | 2005-01-29 22:14:28 | Re: Scanning the PGSQL DB |
Previous Message | PFC | 2005-01-29 22:09:44 | Re: Splitting queries across servers |