Skip site navigation (1) Skip section navigation (2)

Re: Squences with letters aswell as numbers

From: Michael Fuhr <mike(at)fuhr(dot)org>
To: NubeY <dominic_wormald(at)yahoo(dot)co(dot)uk>
Cc: pgsql-novice(at)postgresql(dot)org
Subject: Re: Squences with letters aswell as numbers
Date: 2006-03-01 03:40:05
Message-ID: 20060301034005.GA16010@winnie.fuhr.org (view raw or flat)
Thread:
Lists: pgsql-novice
On Tue, Feb 28, 2006 at 08:46:45AM -0800, NubeY wrote:
> create sequence group_seq;
> select setval('group_seq', (select max(group_ID) from groups));
> 
> However I'd like to create a sequence that has this kind of output
> 
> g1
> g2
> g3
> g4
> g5
> 
> where g doesn't change

Any reason you can't append the sequence value to a string as in
the following example?

CREATE SEQUENCE foo_seq;

CREATE TABLE foo (
  id   text PRIMARY KEY DEFAULT 'f' || nextval('foo_seq'),
  val  text NOT NULL
);

INSERT INTO foo (val) VALUES ('a');
INSERT INTO foo (val) VALUES ('b');
INSERT INTO foo (val) VALUES ('c');

SELECT * FROM foo;
 id | val 
----+-----
 f1 | a
 f2 | b
 f3 | c
(3 rows)

-- 
Michael Fuhr

In response to

pgsql-novice by date

Next:From: Michael FuhrDate: 2006-03-01 04:24:40
Subject: Re: Select with Regular Expressions
Previous:From: Michael GlaesemannDate: 2006-03-01 02:50:45
Subject: Re: Newbie basic and silly question

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group