summaryrefslogtreecommitdiff
path: root/django/db/backends/postgresql
diff options
context:
space:
mode:
authorMariusz Felisiak <felisiak.mariusz@gmail.com>2025-11-17 13:43:47 +0100
committerGitHub <noreply@github.com>2025-11-17 13:43:47 +0100
commit1ce6e78dd4beed702f15fa0be798dd17a15d4ba8 (patch)
tree0078da5312fb69897bb6327040d51c3450d2fa3b /django/db/backends/postgresql
parent5c60763561c67924eff1069e1516b60a59d068d5 (diff)
Fixed #24920 -- Added support for DecimalField with no precision.
Thanks Lily for the review.
Diffstat (limited to 'django/db/backends/postgresql')
-rw-r--r--django/db/backends/postgresql/base.py8
-rw-r--r--django/db/backends/postgresql/features.py1
-rw-r--r--django/db/backends/postgresql/introspection.py6
3 files changed, 12 insertions, 3 deletions
diff --git a/django/db/backends/postgresql/base.py b/django/db/backends/postgresql/base.py
index e2728afea5..42b37ab3c2 100644
--- a/django/db/backends/postgresql/base.py
+++ b/django/db/backends/postgresql/base.py
@@ -89,6 +89,12 @@ def _get_varchar_column(data):
return "varchar(%(max_length)s)" % data
+def _get_decimal_column(data):
+ if data["max_digits"] is None and data["decimal_places"] is None:
+ return "numeric"
+ return "numeric(%(max_digits)s, %(decimal_places)s)" % data
+
+
class DatabaseWrapper(BaseDatabaseWrapper):
vendor = "postgresql"
display_name = "PostgreSQL"
@@ -105,7 +111,7 @@ class DatabaseWrapper(BaseDatabaseWrapper):
"CharField": _get_varchar_column,
"DateField": "date",
"DateTimeField": "timestamp with time zone",
- "DecimalField": "numeric(%(max_digits)s, %(decimal_places)s)",
+ "DecimalField": _get_decimal_column,
"DurationField": "interval",
"FileField": "varchar(%(max_length)s)",
"FilePathField": "varchar(%(max_length)s)",
diff --git a/django/db/backends/postgresql/features.py b/django/db/backends/postgresql/features.py
index 5bbf4b86cb..5e4ed320be 100644
--- a/django/db/backends/postgresql/features.py
+++ b/django/db/backends/postgresql/features.py
@@ -68,6 +68,7 @@ class DatabaseFeatures(BaseDatabaseFeatures):
supports_covering_indexes = True
supports_stored_generated_columns = True
supports_nulls_distinct_unique_constraints = True
+ supports_no_precision_decimalfield = True
can_rename_index = True
test_collations = {
"deterministic": "C",
diff --git a/django/db/backends/postgresql/introspection.py b/django/db/backends/postgresql/introspection.py
index 791d729ea4..69dd776aa3 100644
--- a/django/db/backends/postgresql/introspection.py
+++ b/django/db/backends/postgresql/introspection.py
@@ -137,8 +137,10 @@ class DatabaseIntrospection(BaseDatabaseIntrospection):
# display_size is always None on psycopg2.
line.internal_size if line.display_size is None else line.display_size,
line.internal_size,
- line.precision,
- line.scale,
+ # precision and scale are always 2^16 - 1 on psycopg2 for
+ # DecimalFields with no precision.
+ None if line.precision == 2**16 - 1 else line.precision,
+ None if line.scale == 2**16 - 1 else line.scale,
*field_map[line.name],
)
for line in cursor.description