It may technically work but it's not a good idea. The 19 barrel's outer dimensions are smaller, so the tang at the rear of the barrel will gouge the sides of the breech face and you'll get inconsistent lockup. The round portion of the barrel that sticks out of the muzzle hole of the slide is also smaller, so much more stress will be put on the barrel lugs, locking block, frame pins, and the frame itself. Eventually one of those parts is bound to crack.
I'd get an aftermarket .40-9mm conversion barrel for the G23, it has the same outer dimensions as a G23 .40 barrel but it's chambered for 9mm. You'd also need to use 9mm magazines with that barrel.