Ideally this should be handled by the pg query generator, but it might not be possible to know the data type in qg. Will look at it later