Solved

Create sequence to auto increment index

Posted on 2006-06-30
3
14,813 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Can I get back uninstalled DB after Windows Restore? 5 354
Help decide on technology stack 3 102
Postgres query - add column 8 207
Postgresql  SQL output set column width 3 313
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.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

809 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