Results 1 to 2 of 2
  1. #1
    Join Date
    Sep 2003
    Posts
    7

    Unhappy Unanswered: inet datatype: minimum, increment, ...???

    Hi folks,

    I'm using the 'inet' datatype of postgresql and there are some problems with it, that need to be solved:
    I have a column of type inet where I need to select the smallest value in range x-z from thats not in the table.
    For explanation: This is a table of computers with ip-adress. We've got a subnet from our University that we may use. So we have an upper and a lower bound for ips. We also have some servers and switches that have fixed adresses, so we can only use .10 to .250 for pcs.
    Now, if we get a new PC, I need to select the lowest number of available ips thats unused. I need to keep the upper area en block for dynamic use with dhcp.

    The problem is, that you cant increment 'inet' and also cant take the minimum from an inet column!

    thanks for any hints in the right direction!!!
    [one solution would be a 2nd table with all available ips, but in my eyes that would be a hack]

  2. #2
    Join Date
    Sep 2003
    Location
    Wisconsin, USA
    Posts
    34
    I did:

    CREATE TABLE test (
    ipfield inet
    );
    INSERT INTO test (ipfield) VALUES ('192.168.1.50');
    INSERT INTO test (ipfield) VALUES ('192.168.1.51');
    INSERT INTO test (ipfield) VALUES ('192.168.1.52');


    with that data I can do:
    SELECT * FROM test WHERE ipfield > '192.168.1.10' ORDER BY ipfield LIMIT 1;

    this will return 192.168.1.50, which is effectively the same as min();

    if you do INSERT INTO test (ipfield) VALUES ('192.168.1.48');
    it will return 48.

    You can also do
    SELECT * FROM test WHERE ipfield < '192.168.1.250' ORDER BY ipfield DESC LIMIT 1;
    and it will return 192.168.1.52, which is effectively the same as max();

    hope that helps.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •