Thread: Sequence name with SERIAL type
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
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/
Marek Lewczuk <newsy@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
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
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 | +------------------------------+---------------------------------------------+
Tom Lane wrote: > Marek Lewczuk <newsy@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