diff --git a/sqlglot/generators/postgres.py b/sqlglot/generators/postgres.py index 37fd98e2b3..ca1988aa0f 100644 --- a/sqlglot/generators/postgres.py +++ b/sqlglot/generators/postgres.py @@ -222,7 +222,7 @@ def _round_sql(self: PostgresGenerator, expression: exp.Round) -> str: # ROUND(double precision, integer) is not permitted in Postgres # so it's necessary to cast to decimal before rounding. - if expression.this.is_type(exp.DType.DOUBLE): + if expression.this.is_type(*exp.DataType.FLOAT_TYPES): decimal_type = exp.DType.DECIMAL.into_expr(expressions=expression.expressions) this = self.sql(exp.Cast(this=this, to=decimal_type)) diff --git a/tests/dialects/test_postgres.py b/tests/dialects/test_postgres.py index f30906bee7..0513fa543c 100644 --- a/tests/dialects/test_postgres.py +++ b/tests/dialects/test_postgres.py @@ -1798,6 +1798,11 @@ def test_round(self): "bigquery": "ROUND(x::DOUBLE, 4)", }, ) + # ROUND(real, integer) is not permitted in Postgres either, so REAL must be cast too. + self.validate_all( + "ROUND(CAST(CAST(x AS REAL) AS DECIMAL), 4)", + read={"postgres": "ROUND(x::REAL, 4)"}, + ) self.validate_all( "ROUND(CAST(x AS DECIMAL(18, 3)), 4)", read={"duckdb": "ROUND(x::DECIMAL, 4)"} )