On 3/11/2016 12:40 AM, Craig Ringer wrote:
I was using Oracle 11g XE, GENERATED ALWAYS was not available. This is the code I used for Oracle:
CREATE TABLE jdbc (j_name VARCHAR2(64) NOT NULL, j_id NUMBER(10) NOT NULL);
CREATE SEQUENCE jdbc_seq;
CREATE OR REPLACE TRIGGER jdbc_seq_trigger
BEFORE INSERT ON jdbc
FOR EACH ROW
WHEN (new.j_id IS NULL)
BEGIN
SELECT jdbc_seq.NEXTVAL
INTO :new.j_id
FROM dual;
END;
/ For DB2 the type is indeed GENERATED ALWAYS AS IDENTITY:
j_id INT GENERATED ALWAYS AS IDENTITY Originally the name was ID but when both DB2 and MS/jTDS returned a column named "ID" I realized that it might come from the column name, so I modified the column name. DB2 was indeed returning the column name, while MS/jTDS returns a column named "ID" regardless of the actual column name.
I agree, but I can test it if you give me the SQL commands. I do want to remove all of that horrible software from my workstation as soon as possible, but it can wait if more testing is required.
If you give me the code that you want to test I will test it.
I agree with Craig.
I'm not sure how multi-column keys work. In both MySQL and SQL Server for example, you can not have more than one SEQUENCE column, so perhaps that's their "solution".
Igal