Solved

Create sequence to auto increment index

Posted on 2006-06-30
3
14,812 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
ID: 17026145
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
ID: 17026146
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
ID: 17026183
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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

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.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

777 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