Howto set sequence as default value via pgAdmin?
I have a posgreSQL database and I am using pgAdmin III to work with it.I created a sequence called primaryKeySequence.
Now I want to use this sequence as the default value for a primary key field in a table. I tried to insert
nextval('primaryKeySequence');
into the default value textfield in pgAdmin. When I click the 'OK'-button an error message comes up and says, that the sequence does not exist.
What is the right way to do it?
Got it. Have a look here: http://pgadmin.org/docs/1.4/pg/functions-sequence.html The sequence name has to be quoted like this nextval('"primaryKeySequence"')
because it is not lowercase
PostgreSQL is going to lowercase the identifier unless you "". So try:
nextval('primarykeysequence')
Also, you are doing it wrong. Use Serial/BigSerial instead.
链接地址: http://www.djcxy.com/p/44792.html