Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9082097
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T20:28:30+00:00 2026-06-16T20:28:30+00:00

According to the SQLite docs , the only way to get an auto-increment column

  • 0

According to the SQLite docs, the only way to get an auto-increment column is on the primary key.

I need a compound primary key, but I also need auto-incrementing. Is there a way to achieve both of these in SQLite?

Relevant portion of my table as I would write it in PostgreSQL:

CREATE TABLE tstage (
    id                   SERIAL NOT NULL,
    node                 INT REFERENCES nodes(id) NOT NULL,
    PRIMARY KEY (id,node),
    -- ... other columns
);

The reason for this requirement is that all nodes eventually dump their data to a single centralized node where, with a single-column PK, there would be collisions.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T20:28:32+00:00Added an answer on June 16, 2026 at 8:28 pm

    The documentation is correct.
    However, it is possible to reimplement the autoincrement logic in a trigger:

    CREATE TABLE tstage (
        id    INT,  -- allow NULL to be handled by the trigger
        node  INT REFERENCES nodes(id) NOT NULL,
        PRIMARY KEY (id, node)
    );
    
    CREATE TABLE tstage_sequence (
        seq INTEGER NOT NULL
    );
    INSERT INTO tstage_sequence VALUES(0);
    
    CREATE TRIGGER tstage_id_autoinc
    AFTER INSERT ON tstage
    FOR EACH ROW
    WHEN NEW.id IS NULL
    BEGIN
        UPDATE tstage_sequence
        SET seq = seq + 1;
    
        UPDATE tstage
        SET id = (SELECT seq
                  FROM tstage_sequence)
        WHERE rowid = NEW.rowid;
    END;
    

    (Or use a common my_sequence table with the table name if there are multiple tables.)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to retrieve data from core data (sqlite database) according to primary key.
According to SQLite documentation I can write: SELECT * FROM docs WHERE docs MATCH
I trying to open an SQLITE database in read-only mode according this link: Connection
I have a SQLite database. According to this answer you need version 3.6.19+, which
I need a query that subtracts or adds according to a condition for SQLite
According to docs at http://code.google.com/p/minify/wiki/UriRewriting $min_serveOptions['rewriteCssUris'] = false; I should be able to add
I experience some strange errors with jdbc, SQLite and java's DriveManager . According to
According to the sqlite3 docs , fetchall() returns a list (empty if no rows
The new Sparx Systems Enterprise Architect 9 supports now sqlite. And according to the
I am trying to get my local sqlite db up and running on GAE.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.