RE: postgres PK serial column insert error

From: Laurence Gellert (geller..arkwing.uoregon.edu)
Date: Mon Aug 02 2004 - 16:21:18 EDT

  • Next message: McDaniel, Joe R.: "Bug in Modeler"

    > You have to know what the primary key value is before you can insert the
    record.

    I won't know the next value until postgres assigns it though a
    mini-transaction it does during the insert. I just want it to be a unique
    number. Building a manual PK handler feels like reinventing the wheel, it
    runs slower, and has opportunity to loose database key integrity.

    So, why does Cayenne require us to build our own primary key management
    system?

    Running a statement like: INSERT INTO login (username, password) VALUES
    ('test', 'abc'); and letting the database set the next value for LoginID of
    serial type should be simple.

    Is there a way to bypass the AUTO_PK_TABLE behavior and have Cayenne ignore
    the PK field for the add method? All I need is a one way ticket to insert
    data into the database. Using the object model already setup is way better
    than writing an INSERT statement. How are people out there handling this
    issue?

    Can somebody give me an example of how they implemented AUTO_PK_TABLE
    behavior in postgres?

    Laurence

    -----Original Message-----
    From: Mike Kienenberger [mailto:mkienen..laska.net]
    Sent: Monday, August 02, 2004 12:33 PM
    To: geller..arkwing.uoregon.edu
    Cc: cayenne-use..bjectstyle.org
    Subject: Re: postgres PK serial column insert error

    Laurence Gellert <geller..arkwing.uoregon.edu> wrote:
    > I would like to do something along the lines of making an INSERT statement
    > like: "INSERT INTO login (username, password) VALUES ('test', 'abc');"
    >
    > Instead, it looks like Cayenne is accessing 'auto_pk_support' for the next
    > login id. This is two trips to the db, instead of one.

    You have to know what the primary key value is before you can insert the
    record.

    Cayenne does this by fetching that value using whichever automatic primary
    key methodology you've specified (by default a database-table-based system).

     While it's true that for a single insert, it'll take two trips, it'll
    prefetch 20 primary key values by default, so for 20 inserts, it's only 21
    trips to the db. (or if you're using batch processing and doing all 20 at
    the same time, only 2 trips for 20 inserts -- probably not the case when
    creating userids, though).

    Sorry I can't help with the actual error you're getting.

    -Mike



    This archive was generated by hypermail 2.0.0 : Mon Aug 02 2004 - 16:21:25 EDT