By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,178 Members | 971 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,178 IT Pros & Developers. It's quick & easy.

Sequence name with SERIAL type

P: n/a
I'm curious if the default scheme for sequence name (which is created
with SERIAL data type) can be changed -- currently all sequences are
named like this: <table_name>_<field_name>_seq -- can it be changed for
e.g. <table_name>__<field_name>__seq ???

Thanks.

ML


---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
(send "unregister YourEmailAddressHere" to ma*******@postgresql.org)

Nov 12 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
On Wed, Dec 17, 2003 at 08:59:03AM +0100, Marek Lewczuk wrote:
I'm curious if the default scheme for sequence name (which is created
with SERIAL data type) can be changed -- currently all sequences are
named like this: <table_name>_<field_name>_seq -- can it be changed for
e.g. <table_name>__<field_name>__seq ???


You'd have to hack the source code. See the transformColumnDefinition()
and makeObjectName() functions in src/backend/parser/analyze.c.

--
Michael Fuhr
http://www.fuhr.org/~mfuhr/

---------------------------(end of broadcast)---------------------------
TIP 5: Have you checked our extensive FAQ?

http://www.postgresql.org/docs/faqs/FAQ.html

Nov 12 '05 #2

P: n/a
Marek Lewczuk <ne***@lewczuk.com> writes:
I'm curious if the default scheme for sequence name (which is created
with SERIAL data type) can be changed -- currently all sequences are
named like this: <table_name>_<field_name>_seq -- can it be changed for
e.g. <table_name>__<field_name>__seq ???


Sure ... just hack one or two places in the sources ...

That probably wasn't the answer you wanted, but I'm quite unsure what
you did want. Are you suggesting the above would be a better default
naming scheme? Are you saying you want user-configurability of implicit
sequence names? In either case, what's your argument why we should
invest effort and possibly create backwards-compatibility issues?

regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 8: explain analyze is your friend

Nov 12 '05 #3

P: n/a
On Wednesday 17 December 2003 07:59, Marek Lewczuk wrote:
I'm curious if the default scheme for sequence name (which is created
with SERIAL data type) can be changed -- currently all sequences are
named like this: <table_name>_<field_name>_seq -- can it be changed for
e.g. <table_name>__<field_name>__seq ???


Your two options seem to be:
1. Build your own sequence and don't use SERIAL
2. Change the source (should be a simple change).

--
Richard Huxton
Archonet Ltd

---------------------------(end of broadcast)---------------------------
TIP 4: Don't 'kill -9' the postmaster

Nov 12 '05 #4

P: n/a

On 17/12/2003 07:59 Marek Lewczuk wrote:
I'm curious if the default scheme for sequence name (which is created
with SERIAL data type) can be changed -- currently all sequences are
named like this: <table_name>_<field_name>_seq -- can it be changed for
e.g. <table_name>__<field_name>__seq ???

You could try something like

myfield integer default nextval('mysequence')

where you have previously created the sequence mysequence.

HTH

--
Paul Thomas
+------------------------------+---------------------------------------------+
| Thomas Micro Systems Limited | Software Solutions for the Smaller
Business |
| Computer Consultants |
http://www.thomas-micro-systems-ltd.co.uk |
+------------------------------+---------------------------------------------+

---------------------------(end of broadcast)---------------------------
TIP 5: Have you checked our extensive FAQ?

http://www.postgresql.org/docs/faqs/FAQ.html

Nov 12 '05 #5

P: n/a
Tom Lane wrote:
Marek Lewczuk <ne***@lewczuk.com> writes:
I'm curious if the default scheme for sequence name (which is created
with SERIAL data type) can be changed -- currently all sequences are
named like this: <table_name>_<field_name>_seq -- can it be changed for
e.g. <table_name>__<field_name>__seq ???

Sure ... just hack one or two places in the sources ...

That probably wasn't the answer you wanted, but I'm quite unsure what you did want.

I just asked is it can be done (somehow...).
Are you suggesting the above would be a better default
naming scheme? Are you saying you want user-configurability of implicit
sequence names? In either case, what's your argument why we should
invest effort and possibly create backwards-compatibility issues?


I'm not saying that proposed naming scheme is better - I think that it
is more readable, and I'm using it in my project.
Look at below examples:

Primary key:
1. <table_name>__pkey
(e.g. my_clients__pkey)

Foreign key:
1. <table_name>__<field>__fkey
(e.g. my_clients__client_id__fkey)
2. <table_name>__<field>_<field>__fkey
(e.g. my_clients__client_id_company_id__fkey)

Index:
1. <table_name>__<field>__index
(e.g. my_clients__country__index)
2. <table_name>__<field>_<field>_<field>__index
(e.g. my_clients__country_city_street__index)

Sequence:
1. <table_name>__<field>__seq
(e.g. my_clients__client_id__seq)
As you can see all naming schemes are very similar, and becouse of this
I just wanted to know if there is something like "user-configurability
implicit of sequence names". I didn't want to propose NEW naming scheme
- but maybe my naming schemes are worth looking at.

ML



---------------------------(end of broadcast)---------------------------
TIP 8: explain analyze is your friend

Nov 12 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.