Auto Increment PostgreSQL [message #4250] |
Tue, 10 June 2014 08:22 |
kong
Messages: 90 Registered: December 2011
|
Member |
|
|
In Radicore 1.84 with PostgreSQL 9.3, I tested auto increment PK feature using this:
CREATE SEQUENCE test_test_id_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
ALTER TABLE test_test_id_seq OWNER TO postgres;
CREATE TABLE test (
test_id integer DEFAULT nextval('test_test_id_seq'::regclass) NOT NULL,
test_desc character varying(255) NOT NULL
);
ALTER TABLE test OWNER TO postgres;
ALTER TABLE ONLY test
ADD CONSTRAINT test_pkey PRIMARY KEY (test_id);
REVOKE ALL ON SEQUENCE test_test_id_seq FROM PUBLIC;
REVOKE ALL ON SEQUENCE test_test_id_seq FROM postgres;
GRANT ALL ON SEQUENCE test_test_id_seq TO postgres;
GRANT ALL ON SEQUENCE test_test_id_seq TO PUBLIC;
REVOKE ALL ON TABLE test FROM PUBLIC;
REVOKE ALL ON TABLE test FROM postgres;
GRANT ALL ON TABLE test TO postgres;
GRANT SELECT,INSERT,DELETE,UPDATE ON TABLE test TO PUBLIC;
I then imported this new table, imported the columns, after which I examined the test_id column via column->update and noted 2 problems:
1) the default value was set to test_test_id_seq
2) the auto increment property was set to 'no' and the screen does not allow any changes to this property.
The first problem is easy to work around, just delete the content in the default field every time columns are imported or re-imported.
The second problem is more troublesome, as a work around requires you to open the dict.inc file and manually add 'auto_increment' => 'y' on the key field, otherwise system will show 'test_id cannot be blank' error when you try to create a record.
|
|
|