Say if I have a table:
CREATE TABLE T ( TableDTM TIMESTAMP NOT NULL, Code INT NOT NULL );
And I insert some rows:
PostgreSQL supports window functions, have a look at this
[EDIT] Try the following:
SELECT TableDTM, Code FROM ( SELECT TableDTM, Code, LAG(Code, 1, NULL) OVER (ORDER BY TableDTM) AS PrevCode FROM T ) WHERE PrevCode<>Code OR PrevCode IS NULL;