Solved

Create sequence to auto increment index

Posted on 2006-06-30
3
14,792 Views
Last Modified: 2011-08-18
I am new to postgresql. I know it doesn't do auto increment on index. I am not sure how to say this: how do I create a sequence on command line so that I can get the next index # in my table FILE_RECORD.

Thanks a lot

0
Comment
Question by:yue520
  • 3
3 Comments
 
LVL 22

Expert Comment

by:earth man2
Comment Utility
create table x ( the_index_column serial );
create table y ( the_index_column bigserial );
insert into x ( the_index ) values ( default );
insert into y ( the_index ) values ( default );
0
 
LVL 22

Expert Comment

by:earth man2
Comment Utility
Doh that should be
create table x ( the_index_column serial );
create table y ( the_index_column bigserial );
insert into x ( the_index_column ) values ( default );
insert into y ( the_index_column ) values ( default );
0
 
LVL 22

Accepted Solution

by:
earth man2 earned 50 total points
Comment Utility
treacle=> create table file_record ( "index#" bigserial primary key, col1 text );
NOTICE:  CREATE TABLE will create implicit sequence "file_record_index#_seq" for serial column "file_record.index#"
NOTICE:  CREATE TABLE / PRIMARY KEY will create implicit index "file_record_pkey" for table "file_record"
CREATE TABLE
treacle=> insert into file_record( col1 ) values ( 'PostgreSQL does  auto increment on index' );
INSERT 98359 1
treacle=> select * from file_record;
 index# |                   col1                  
--------+------------------------------------------
      1 | PostgreSQL does  auto increment on index
(1 row)
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Best database to use for Maps is PostgreSQL. This is an open source database. Comes as a package with most Linux OS. For more info visit the following site: http://www.postgresql.org/ (http://www.postgresql.org/) This requires some add-o…
Many developers have database experience, but are new to PostgreSQL. It has some truly inspiring capabilities. I have several years' experience with Microsoft's SQL Server. When I began working with MySQL, I wanted a quick-reference to MySQL (htt…
Steps to create a PostgreSQL RDS instance in the Amazon cloud. We will cover some of the default settings and show how to connect to the instance once it is up and running.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now