Serial data type not starting at 1

Started by Tielman J de Villiersover 24 years ago8 messagesgeneral
Jump to latest
#1Tielman J de Villiers
tjdevil@bondnet.co.za

Hi,

I hope someone can help me.

I want to create a new table using the "automatic" sequence function of
Postgres by creating the first column as type "serial". But I want to start
at say "5000". Can it be done, and how?

Thank you

Tielman J de Villiers
BondNet Pty Ltd

#2Tielman J de Villiers
tjdevil@bondnet.co.za
In reply to: Tielman J de Villiers (#1)
Re: Serial data type not starting at 1

Thanks Tony,

I have tried:
db=> create table test2(x serial start 5000,y varchar);
But it gives:
ERROR: parser: parse error at or near "start"

Tielman J de Villiers
BondNet Pty Ltd

-----Original Message-----
From: tony [mailto:tony@animaproductions.com]
Sent: Thursday, November 15, 2001 4:41 PM
To: Tielman J de Villiers
Cc: 'pgsql-general@postgresql.org'
Subject: Re: [GENERAL] Serial data type not starting at 1

On Thu, 2001-11-15 at 14:50, Tielman J de Villiers wrote:

Hi,

I hope someone can help me.

I want to create a new table using the "automatic" sequence function
of Postgres by creating the first column as type "serial". But I want
to start at say "5000". Can it be done, and how?

Like in the docs...

START 5000

Cheers

Tony Grant

--
RedHat Linux on Sony Vaio C1XD/S http://www.animaproductions.com/linux2.html
Macromedia UltraDev with PostgreSQL
http://www.animaproductions.com/ultra.html

#3tony
tony@animaproductions.com
In reply to: Tielman J de Villiers (#1)
Re: Serial data type not starting at 1

On Thu, 2001-11-15 at 14:50, Tielman J de Villiers wrote:

Hi,

I hope someone can help me.

I want to create a new table using the "automatic" sequence function of
Postgres by creating the first column as type "serial". But I want to start
at say "5000". Can it be done, and how?

Like in the docs...

START 5000

Cheers

Tony Grant

--
RedHat Linux on Sony Vaio C1XD/S
http://www.animaproductions.com/linux2.html
Macromedia UltraDev with PostgreSQL
http://www.animaproductions.com/ultra.html

#4Martijn van Oosterhout
kleptog@svana.org
In reply to: Tielman J de Villiers (#1)
Re: Serial data type not starting at 1

On Thu, Nov 15, 2001 at 03:50:29PM +0200, Tielman J de Villiers wrote:

Hi,

I hope someone can help me.

I want to create a new table using the "automatic" sequence function of
Postgres by creating the first column as type "serial". But I want to start
at say "5000". Can it be done, and how?

I don't think you can do it within the table definition, but you can
certainly use setval() to change the value after the table has been created.
--
Martijn van Oosterhout <kleptog@svana.org>
http://svana.org/kleptog/

Show quoted text

Magnetism, electricity and motion are like a three-for-two special offer:
if you have two of them, the third one comes free.

#5tony
tony@animaproductions.com
In reply to: Tielman J de Villiers (#2)
Re: Serial data type not starting at 1

On Thu, 2001-11-15 at 15:38, Tielman J de Villiers wrote:

Thanks Tony,

I have tried:
db=> create table test2(x serial start 5000,y varchar);
But it gives:
ERROR: parser: parse error at or near "start"

create sequence test_serial start 5000;
create table test2 (
x nextval('test_serial'),
y varchar;
);

Tony
--
RedHat Linux on Sony Vaio C1XD/S
http://www.animaproductions.com/linux2.html
Macromedia UltraDev with PostgreSQL
http://www.animaproductions.com/ultra.html

#6Stephan Szabo
sszabo@megazone23.bigpanda.com
In reply to: Tielman J de Villiers (#1)
Re: Serial data type not starting at 1

On Thu, 15 Nov 2001, Tielman J de Villiers wrote:

Hi,

I hope someone can help me.

I want to create a new table using the "automatic" sequence function of
Postgres by creating the first column as type "serial". But I want to start
at say "5000". Can it be done, and how?

I would think you can use setval() on the sequence created by the serial
before any rows are inserted in order to start at a different value.

#7Tielman J de Villiers
tjdevil@bondnet.co.za
In reply to: Stephan Szabo (#6)
Re: Serial data type not starting at 1

Great and thank you very much:

[ create table test2 (x int default nextval('test_serial'),y varchar); ]

Did the trick

Tielman J de Villiers
BondNet Pty Ltd

-----Original Message-----
From: tony [mailto:tony@animaproductions.com]
Sent: Thursday, November 15, 2001 4:54 PM
To: Tielman J de Villiers
Cc: 'pgsql-general@postgresql.org'
Subject: RE: [GENERAL] Serial data type not starting at 1

On Thu, 2001-11-15 at 15:38, Tielman J de Villiers wrote:

Thanks Tony,

I have tried:
db=> create table test2(x serial start 5000,y varchar);
But it gives:
ERROR: parser: parse error at or near "start"

create sequence test_serial start 5000;
create table test2 (
x nextval('test_serial'),
y varchar;
);

Tony
--
RedHat Linux on Sony Vaio C1XD/S http://www.animaproductions.com/linux2.html
Macromedia UltraDev with PostgreSQL
http://www.animaproductions.com/ultra.html

#8Andrew G. Hammond
drew@xyzzy.dhs.org
In reply to: Tielman J de Villiers (#1)
Re: Serial data type not starting at 1

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Which version of postgres are you running? Some stuff such as
setval(sequence) and START only appears to have been implemented in more
recent versions of postgres. This might be your problem.

On 2001 November 15 08:50 am, Tielman J de Villiers wrote:

Hi,

I hope someone can help me.

I want to create a new table using the "automatic" sequence function of
Postgres by creating the first column as type "serial". But I want to start
at say "5000". Can it be done, and how?

Thank you

Tielman J de Villiers
BondNet Pty Ltd

---------------------------(end of broadcast)---------------------------
TIP 3: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to majordomo@postgresql.org so that your
message can get through to the mailing list cleanly

- --
Andrew G. Hammond mailto:drew@xyzzy.dhs.org http://xyzzy.dhs.org/~drew/
56 2A 54 EF 19 C0 3B 43 72 69 5B E3 69 5B A1 1F 613-389-5481
5CD3 62B0 254B DEB1 86E0 8959 093E F70A B457 84B1
"To blow recursion you must first blow recur" -- me
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.6 (GNU/Linux)
Comment: For info see http://www.gnupg.org

iEYEARECAAYFAjv0GF8ACgkQCT73CrRXhLFsFQCfVRkAgEQxcqZv+BQxdzoMLjj0
OCUAn0sPYTMrdTLxH9yoXQhklf4UzRvj
=qpko
-----END PGP SIGNATURE-----