Solved

Create sequence to auto increment index

Posted on 2006-06-30
3
14,819 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

Question has a verified solution.

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

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 video Micro Tutorial shows how to password-protect PDF files with free software. Many software products can do this, such as Adobe Acrobat (but not Adobe Reader), Nuance PaperPort, and Nuance Power PDF, but they are not free products. This vide…

729 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