On Sat, 29 Jan 2005 22:24:46 +0300, Andrey V. Semyonov <wilfre@xxxxxxx> 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? ---------------------------(end of broadcast)--------------------------- TIP 3: if posting/reading through Usenet, please send an appropriate subscribe-nomail command to majordomo@xxxxxxxxxxxxxx so that your message can get through to the mailing list cleanly