Is tying a knot in an electrical wire safe?
In the case that the lamp is light weight enough to not stress the cord, there's a specific knot for that called an Underwriter's Knot that is supposed to put minimum stress on the conductors and provide enough bulge to keep it from pulling out. Since most PVC insulation will cold flow under pressure, the edges it butts up against must be well rounded.