![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
select version() "PostgreSQL 9.0.1 on x86_64-unknown-linux-gnu, compiled by GCC gcc (GCC) 4.1.2 20080704 (Red Hat 4.1.2-46), 64-bit" Hi, should a bigserial sequence know that I have made a separate 'insert' on a table ? my experience says that it does not...and this seems wrong to me. |
#3
| |||
| |||
|
|
On Sun, 27 Feb 2011 07:39:55 -0800, Dog is love wrote: should a bigserial sequence know that I have made a separate 'insert' on a table ? my experience says that it does not...and this seems wrong to me. Don't use "serial" data types, use sequence in combination with a trigger. That way, you will know what happens, when. |
#4
| |||
| |||
|
|
On 2/27/2011 2:14 PM, Mladen Gogala wrote: Don't use "serial" data types, use sequence in combination with a trigger. That way, you will know what happens, when. Ha! That seems like a GREAT idea! You'd only have to deal with INSERT triggers, right? Aside from having to write the trigger function (trivial?), are there any other downsides to this approach? |
#5
| |||
| |||
|
|
Ha! That seems like a GREAT idea! You'd only have to deal with INSERT triggers, right? |
#6
| |||
| |||
|
|
(And using a DEFAULT in the column definition gives essentially the same behaviour as SERIAL would in the first place; if you think of it that way, SERIAL shouldn't give any surprises. The only real difference is that if you use SERIAL the sequence will be dropped automatically when you drop the table.) |
#7
| |||
| |||
|
|
On Mon, 28 Feb 2011 18:05:10 +0000, Matthew Woodcraft wrote: (And using a DEFAULT in the column definition gives essentially the same behaviour as SERIAL would in the first place; if you think of it that way, SERIAL shouldn't give any surprises. The only real difference is that if you use SERIAL the sequence will be dropped automatically when you drop the table.) So, what happens in case you try with an explicit insert? |
#8
| |||
| |||
|
|
In article<pan.2011.02.28.21.19.22 (AT) email (DOT) here.invalid>, Mladen Gogala<no (AT) email (DOT) here.invalid> wrote: On Mon, 28 Feb 2011 18:05:10 +0000, Matthew Woodcraft wrote: (And using a DEFAULT in the column definition gives essentially the same behaviour as SERIAL would in the first place; if you think of it that way, SERIAL shouldn't give any surprises. The only real difference is that if you use SERIAL the sequence will be dropped automatically when you drop the table.) So, what happens in case you try with an explicit insert? It overrides the default (like for any other default), and it doesn't affect the sequence. |
#9
| |||
| |||
|
|
It overrides the default (like for any other default), and it doesn't affect the sequence. |
#10
| |||
| |||
|
|
On Mon, 28 Feb 2011 22:13:29 +0000, Matthew Woodcraft wrote: It overrides the default (like for any other default), and it doesn't affect the sequence. So, when the sequence reaches the given number, you will have a primary key violation? That sounds like a plan. |
![]() |
| Thread Tools | |
| Display Modes | |
| |