473,796 Members | 2,537 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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>_<f ield_name>_seq -- can it be changed for
e.g. <table_name>__< field_name>__se q ???

Thanks.

ML


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

Nov 12 '05 #1
5 3040
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>_<f ield_name>_seq -- can it be changed for
e.g. <table_name>__< field_name>__se q ???


You'd have to hack the source code. See the transformColumn Definition()
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
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>_<f ield_name>_seq -- can it be changed for
e.g. <table_name>__< field_name>__se q ???


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
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>_<f ield_name>_seq -- can it be changed for
e.g. <table_name>__< field_name>__se q ???


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

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>_<f ield_name>_seq -- can it be changed for
e.g. <table_name>__< field_name>__se q ???

You could try something like

myfield integer default nextval('mysequ ence')

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
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>_<f ield_name>_seq -- can it be changed for
e.g. <table_name>__< field_name>__se q ???

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>__p key
(e.g. my_clients__pke y)

Foreign key:
1. <table_name>__< field>__fkey
(e.g. my_clients__cli ent_id__fkey)
2. <table_name>__< field>_<field>_ _fkey
(e.g. my_clients__cli ent_id_company_ id__fkey)

Index:
1. <table_name>__< field>__index
(e.g. my_clients__cou ntry__index)
2. <table_name>__< field>_<field>_ <field>__inde x
(e.g. my_clients__cou ntry_city_stree t__index)

Sequence:
1. <table_name>__< field>__seq
(e.g. my_clients__cli ent_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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1277
by: Anders Ljusberg | last post by:
Hi! I have a problem.. I'm trying to get the XML from a dataset to conform to an XSD, but it keeps rearranging some elements. Try this schema: &lt;xs:schema id="test" targetNamespace="http://tempuri.org/test.xsd"
10
2635
by: Anthony Best | last post by:
I'm working on an idea that uses sequences. I'm going to create a table like this: id serial, sequence int, keyword varchar(32), text text for every keyword there will be a uniq sequence for it eg:
3
2130
by: David Garamond | last post by:
Am I correct to assume that SERIAL does not guarantee that a sequence won't skip (e.g. one successful INSERT gets 32 and the next might be 34)? Sometimes a business requirement is that a serial sequence never skips, e.g. when generating invoice/ticket/formal letter numbers. Would an INSERT INTO t (id, ...) VALUES (SELECT MAX(col)+1 FROM t, ...) suffice, or must I install a trigger too to do additional checking? -- dave
1
1636
by: Miles Keaton | last post by:
Here's an interesting problem! When a sequence clashes with data already in that table: CREATE TABLE clients ( id serial NOT NULL PRIMARY KEY UNIQUE, name varchar(64)); -- import OLD clients, with their original ID#... INSERT INTO clients VALUES (3, 'Dave');
4
4505
by: Sim Zacks | last post by:
I am in the process of converting an existing database to PostGreSQL and wrote a generic script to update all of the sequences as they default at 1. I thought it would be useful to other people who are converting their databases. If anyone can write this script in using plpythonu, I would love to see how it is done. create or replace function UpdateSequences() returns varchar(50) as $$
4
538
by: Eric E | last post by:
Hi, I have a question about sequences. I need a field to have values with no holes in the sequence. However, the values do not need to be in order. My users will draw a number or numbers from the sequence and write to the field. Sometimes, however, these sequence numbers will be discarded (after a transaction is complete), and thus available for use. During the transaction, however, any drawn numbers need to be unavailable. I would...
15
9658
by: Robby Russell | last post by:
I am trying to track down a method of determining what a sequence name is for a SERIAL is in postgresql. For example, CREATE TABLE foo (id SERIAL PRIMARY KEY NOT NULL, bar TEXT); \d foo Table "public.foo" Column | Type | Modifiers
2
2785
by: shumaker | last post by:
I designed a schema in VS C# 2005 Express and am wondering why it chooses to place a sequence tag around the elements of a table. And additionally, if I move the elements around within the table, the sequences in the *.xsd are not rearranged, but are left as is(in the order in which the elements were created in the table). Being a noob to xml, I'm just wondering: 1. Why is the sequence tag automatically added? 2. Why is it not updated...
3
1948
by: Daniel Wilson | last post by:
I am trying to read data from MS SQL Server and turn it into an XML message to send to a remote server, as follows. sfSchemaFileDiag.FilterIndex = 2 If sfSchemaFileDiag.ShowDialog = DialogResult.OK Then DataSet1.WriteXml(sfSchemaFileDiag.FileName) End If
0
9683
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10457
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10176
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10013
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9054
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7550
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5443
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5576
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2927
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.