Обсуждение: Inserting preset values into a serial column
PostgreSQL 8.4.4.1 Can someone pls confirm that, provided I am doing it right, I can insert a row into a table where the primary key is serialNOT NULL and a (unique) value is provided in the offered data? I cannot see an answer to this specific point in thedocs. TIA Michael Rowan mike.rowan@internode.on.net 11 Kingscote Street ALBERTON South Australia 5014 tel 618 8240 3993
Michael Rowan <mike.rowan@internode.on.net> wrote: > PostgreSQL 8.4.4.1 > Can someone pls confirm that, provided I am doing it right, I can insert a row into a table where the primary key is serialNOT NULL and a (unique) value is provided in the offered data? I cannot see an answer to this specific point in thedocs. Sure, just try it. You only need to make sure that after your insertion the corresponding sequence will not collide with your data, e. g., you will have to setval() the se- quence to MAX(value) (+ 1?). Tim
mike.rowan@internode.on.net (Michael Rowan) writes: > PostgreSQL 8.4.4.1 > > Can someone pls confirm that, provided I am doing it right, I can > insert a row into a table where the primary key is serial NOT NULL and > a (unique) value is provided in the offered data? I cannot see an > answer to this specific point in the docs. Sure, it shouldn't present a problem. You'd presumably also want to change the value of the sequence that underlies this in order to point it to a value beyond the range of the "offered data." (Use the function "setval()" to do this.) -- Rules of the Evil Overlord #208. "Members of my Legion of Terror will attend seminars on Sensitivity Training. It's good public relations for them to be kind and courteous to the general population when not actively engaged in sowing chaos and destruction."