Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Create sequence to auto increment index

Posted on 2006-06-30
3
Medium Priority
?
14,826 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 200 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

Will your db performance match your db growth?

In Percona’s white paper “Performance at Scale: Keeping Your Database on Its Toes,” we take a high-level approach to what you need to think about when planning for database scalability.

Question has a verified solution.

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

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…
By, Vadim Tkachenko. In this article we’ll look at ClickHouse on its one year anniversary.
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.
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…

705 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