Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix(postgres): generate float if the type has precision #4516

Merged
merged 1 commit into from
Dec 12, 2024

Conversation

georgesittas
Copy link
Collaborator

@georgesittas georgesittas commented Dec 12, 2024

Postgres doesn't support specifying a precision for the REAL and DOUBLE PRECISION types:

georgesittas=# select 1::real(4);
ERROR:  syntax error at or near "("
LINE 1: select 1::real(4);
                      ^
georgesittas=# select 1::double precision(4);
ERROR:  syntax error at or near "("
LINE 1: select 1::double precision(4);
                                  ^
georgesittas=# select 1::real;
 float4
--------
      1
(1 row)

georgesittas=# select 1::double precision;
 float8
--------
      1
(1 row)

OTOH, according to its docs, it does support a FLOAT(p) type, so we use that instead to (1) roundtrip and (2) facilitate transpilation from other dialects to Postgres:

PostgreSQL also supports the SQL-standard notations float and float(p) for specifying inexact numeric types. Here, p specifies the minimum acceptable precision in binary digits. PostgreSQL accepts float(1) to float(24) as selecting the real type, while float(25) to float(53) select double precision. Values of p outside the allowed range draw an error. float with no precision specified is taken to mean double precision.

Fixes #4508

@georgesittas georgesittas merged commit e15cd0b into main Dec 12, 2024
7 checks passed
@georgesittas georgesittas deleted the jo/fix_float_generation branch December 12, 2024 17:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Invalid syntax for Redshift: AS REAL(8)
3 participants