Where are you putting this code? I'm triying to replicate your issue on my postgresql server but works normally for me, the only thing I can think off is that you are putting this code outside a reactive expression.
Could you make a minimal REPRoducible EXample (reprex) about your issue?
Here is a very useful guide about how to make a reprex for a shiny app