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 8555625
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T15:09:59+00:00 2026-06-11T15:09:59+00:00

My objective is to get a primary key field automatically inserted when inserting new

  • 0

My objective is to get a primary key field automatically inserted when inserting new row in the table.

How to get a sequence going from session to session in PostgreSQL?

 doubleemploi@hanbei:/home/yves$ psql -d test
 Mot de passe : 
 psql (8.4.13)
 Saisissez « help » pour l''aide.

 test=> create sequence test001 start 10;
 CREATE SEQUENCE
 test=> select currval('test001');
 ERREUR:  la valeur courante (currval) de la séquence « test00 » n''est pas encore définie dans cette session
 --- current value not yet defined this session (???)
 test=> select setval('test001', 10);
 setval 
 --------
      10
 (1 ligne)

 test=> select currval('test00');
  currval 
 ---------
       10
 (1 ligne)

 test=> \q
 test@hanbei:/home/yves$ psql -d test
 Mot de passe : 
 psql (8.4.13)
 Saisissez « help » pour l''aide.

 test=> select currval('test001');
 ERREUR:  la valeur courante (currval) de la séquence « test00 » n''est pas encore définie dans cette session
  • 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-11T15:10:00+00:00Added an answer on June 11, 2026 at 3:10 pm

    This may be simpler than you think …

    My objective is to get a primary key field automatically inserted when
    inserting new row in the table.

    Just set the default value of the column:

    ALTER TABLE tbl ALTER COLUMN tbl_id SET DEFAULT nextval('my_seq'::regclass);
    

    Or simpler yet, create the table with a serial type for primary key to begin with:

    CREATE TABLE tbl(
      tbl_id serial PRIMARY KEY
     ,col1 txt
      -- more columns
    );
    

    It creates a dedicated sequence and sets the default for tbl_id automatically.

    In Postgres 10 or later, consider an IDENTITY column instead. See:

    • Auto increment table column

    This way tbl_id is assigned the next value from the attached sequence automatically if you don’t mention it in the INSERT. Works with any session, concurrent or not.

    INSERT INTO tbl(col1) VALUES ('foo');
    

    If you want the new tbl_id back to do something with it:

    INSERT INTO tbl(col1) VALUES ('foo') RETURNING tbl_id;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm new to objective C and I just wanted to get a general clarification
I'm trying to URL encode a string to form a GET request from objective-c.
Here is my table structure MyTable ----------- ObjectID int (Identity), -- Primary Key FileName
The objective is to get an array of MemberExpressions from two LambdaExpressions. The first
My objective is get the View from my custom Preference to add a KeyListener
My objective is to get the answer from up to 6000 Urls in the
I need a simple function in objective C to get data from a webserver,
I'm new in objective-c and makefiles, currently I'm trying to get an objective-c and
I can't seem to figure out how to get Objective-c to auto box my
In Objective-c/Cocoa, how do I get the icon that Finder uses for the desktop

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.