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?
Set Column Default using pgAdmin In the popup, go to 'Columns' tab and click on the edit icon againt a column to change the default value, as shown below. Now, go to the 'Constraints' tab and set or change the default value. Click on the Save button to save the changes.
The default starting value is minvalue for ascending sequences and maxvalue for descending ones.
Click the Definition tab to continue. Use the fields in the Definition tab to define the sequence: Use the Increment field to specify which value is added to the current sequence value to create a new value. Provide a value in the Start field to specify the beginning value of the sequence.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With