473,386 Members | 1,715 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Is it safe to use DEFAULT currval()

I've got a table, and I'm trying to track changes to it, but can't do it via a
primary key including a revision-number (historical reasons).

CREATE TABLE foo (
id SERIAL,
blah text,
tracking int4 DEFAULT currval('foo_id_seq')
PRIMARY KEY (id)
);

I'm actually setting the DEFAULT on tracking using ALTER TABLE after the
event.

Now - it works, but is that a design feature or just luck?

It's convenient that tracking = id of the first entry, but not vital, so I can
always use a separate sequence if needs be.

--
Richard Huxton
Archonet Ltd

---------------------------(end of broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to ma*******@postgresql.org

Nov 12 '05 #1
2 2519
Richard Huxton <de*@archonet.com> writes:
CREATE TABLE foo (
id SERIAL,
blah text,
tracking int4 DEFAULT currval('foo_id_seq')
PRIMARY KEY (id)
); Now - it works, but is that a design feature or just luck?


You're essentially assuming that the column expressions for an INSERT
will be evaluated left-to-right. That's true at the moment, and I don't
see any foreseeable reason why we'd change it, but it surely is an
implementation dependency that could bite you someday.

regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 9: the planner will ignore your desire to choose an index scan if your
joining column's datatypes do not match

Nov 12 '05 #2
On Saturday 27 September 2003 18:40, Tom Lane wrote:
Richard Huxton <de*@archonet.com> writes:
CREATE TABLE foo (
id SERIAL,
blah text,
tracking int4 DEFAULT currval('foo_id_seq')
PRIMARY KEY (id)
);

Now - it works, but is that a design feature or just luck?


You're essentially assuming that the column expressions for an INSERT
will be evaluated left-to-right. That's true at the moment, and I don't
see any foreseeable reason why we'd change it, but it surely is an
implementation dependency that could bite you someday.


I feared as much. Ah well, use nextval(), a different sequence or write a
trigger I suppose.

--
Richard Huxton
Archonet Ltd

---------------------------(end of broadcast)---------------------------
TIP 7: don't forget to increase your free space map settings

Nov 12 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Jody Gelowitz | last post by:
I am trying to find the definition of "Safe Printing" and cannot find out exactly what this entitles. The reason is that I am trying to print contents from a single textbox to no avail using the...
2
by: Oleg Lebedev | last post by:
I am wondering if it's possible to retrieve the current value of a serial type field without using the name of the corresponding sequence? I know that currval function takes the sequence name as a...
4
by: Peter Tragardh | last post by:
Is it possible to automate Source Safe the way Office is automated by writing your own code? What I would like to do is to create some code to enhance Source Safe, to customize it. There is an...
3
by: Sam | last post by:
Does anyone know if the .NET Framework defines a set of classes that allow you to access Visual Source Safe within your C# programs I know there is some type of COM interface...
3
by: | last post by:
This question references to KB articles: http://support.microsoft.com/default.aspx?scid=kb;EN-US;315158 http://support.microsoft.com/default.aspx?scid=kb;EN-US;317012 I'm running Advanced Server...
2
by: Darren Clark | last post by:
HOw do i get source safe working with .net? I have source safe the server setup on our server... however on my machine when i go File > Source Control > All options are always greyed out. ...
9
by: Brandon Craig Rhodes | last post by:
I have a large table (named "changes") which is perfectly willing to support index lookups when its primary key (named "change") is compared to a constant integer: # explain select * from...
20
by: Xavoux | last post by:
Hello all... I can't remind which function to use for safe inputs... gets, fgets, scanf leads to buffer overflow... i compiled that code with gcc version 2.95.2, on windows 2000 char tmp0 =...
72
by: jacob navia | last post by:
We have discussed often the proposition from Microsoft for a safer C library. A rationale document is published here by one of the members of the design team at microsoft:...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
0
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.