Results 1 to 3 of 3
  1. #1
    Join Date
    Jun 2003
    Location
    Nicosia, Cyprus
    Posts
    6

    Unanswered: i am definitely wrong :(

    I've got two tables: the first one has the following structure:

    ip_network | character varying(15) | not null
    ip_mask | numeric(2,0) | not null
    chunk_id | numeric(4,0) | not null

    When i create the second one, with the following query:

    create table ip_allocations (alloc_id numeric(10) not null primary key default max(alloc_id)+1,userid numeric (8) not null,chunk_id numeric(4) references ip_networks (chunk_id) on delete cascade,ip_net varchar(15) not null, ip_mask numeric (2) not null, constraint ip_mask_check check (ip_mask between 0 and 32));

    i get this error:
    ERROR: cannot use column references in DEFAULT clause

    I am so desperate about all this as i've spent lots of time trying to workaround this and got squat Does anyone know what i did wrong?

    Thanks a lot

  2. #2
    Join Date
    Dec 2002
    Posts
    15
    default max(alloc_id)+1

    That is the problem, and not something you would want to do even if you could. MAX() is no guarantee of uniqueness, as it is susceptible to race conditions. Use a sequence instead - simplist is just to use the SERIAL datatype. All this is explain in the postgresql manual.

  3. #3
    Join Date
    Jun 2003
    Location
    Nicosia, Cyprus
    Posts
    6

    It worked!!!

    Thanks a lot, it worked when changed the query to:
    create table ip_allocations (alloc_id serial not null primary key,userid numeric (8) not null,chunk_id numeric(4) references ip_networks (chunk_id) on delete cascade,ip_net varchar(15) not null, ip_mask numeric (2) not null, constraint ip_mask_check check (ip_mask between 0 and 32));


Posting Permissions

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