Graeme Davidson pleaded guilty to the charge at the High Court in Glasgow yesterday.
The 37-year-old stabbed police constable Derek Laing at a property in Lundin Crescent in Tayport, Fife, on 29 June.
He had been visiting his cousin the previous night and started drinking around 8:30pm before a neighbour phoned police a few hours later.
The court heard Mr Laing and colleagues arrived to find Davidson alone and asleep in the bedroom and when he awoke, appearing intoxicated, he questioned why they were there.
Mr Laing, of St Andrews police office and with 13 years’ service, tried to help Davidson find his clothes before leaving him sitting dressed on the bed with the court hearing the officer had “no cause for concern”.
He stood in the property’s hallway by the kitchen door and soon after Davidson, who had not been placed in handcuffs or searched, left the bedroom in a hurry.
The officer thought Davidson was rushing to the front door but quickly realised the accused was coming towards him “at speed” with his right hand raised and holding “a long, slender item”.
Advocate Margaret Barron, prosecuting, said Mr Laing’s initial thought was hoping it was a pen before thinking he was “in a fight for my life” as the knife “made an impact to his chest”.
Reports from other officers describe Davidson as “lunging” and “jumping” at their colleague, who had no time to react or reach for his protection.
A picture of the weapon measuring three-and-a-half inches was shown to Lord Matthews who was also told it left a “one centimetre puncture wound” that was “superficial ... but could have been more significant”.
Mr Laing was treated by his colleagues before being taken to Ninewells Hospital in Dundee and was discharged at around 3:45am with two stitches.
The court also heard as well as being “greatly concerned for his life”, the police officer has been “struggling to cope with the effects on his wife and young family”.