## Decimal Types
-Pydantic has special support for `Decimal` types using the <a href="https://pydantic-docs.helpmanual.io/usage/types/#arguments-to-condecimal" class="external-link" target="_blank">`condecimal()` special function</a>.
+Pydantic has special support for <a href="https://docs.pydantic.dev/latest/api/standard_library_types/#decimaldecimal" class="external-link" target="_blank">`Decimal` types</a>.
-/// tip
-
-Pydantic 1.9, that will be released soon, has improved support for `Decimal` types, without needing to use the `condecimal()` function.
-
-But meanwhile, you can already use this feature with `condecimal()` in **SQLModel** it as it's explained here.
-
-///
-
-When you use `condecimal()` you can specify the number of digits and decimal places to support. They will be validated by Pydantic (for example when using FastAPI) and the same information will also be used for the database columns.
+When you use `Decimal` you can specify the number of digits and decimal places to support in the `Field()` function. They will be validated by Pydantic (for example when using FastAPI) and the same information will also be used for the database columns.
/// info
-For the database, **SQLModel** will use <a href="https://docs.sqlalchemy.org/en/14/core/type_basics.html#sqlalchemy.types.DECIMAL" class="external-link" target="_blank">SQLAlchemy's `DECIMAL` type</a>.
+For the database, **SQLModel** will use <a href="https://docs.sqlalchemy.org/en/20/core/type_basics.html#sqlalchemy.types.DECIMAL" class="external-link" target="_blank">SQLAlchemy's `DECIMAL` type</a>.
///
+from decimal import Decimal
from typing import Optional
-from pydantic import condecimal
from sqlmodel import Field, Session, SQLModel, create_engine, select
name: str = Field(index=True)
secret_name: str
age: Optional[int] = Field(default=None, index=True)
- money: condecimal(max_digits=5, decimal_places=3) = Field(default=0)
+ money: Decimal = Field(default=0, max_digits=5, decimal_places=3)
sqlite_file_name = "database.db"
-from pydantic import condecimal
+from decimal import Decimal
+
from sqlmodel import Field, Session, SQLModel, create_engine, select
name: str = Field(index=True)
secret_name: str
age: int | None = Field(default=None, index=True)
- money: condecimal(max_digits=5, decimal_places=3) = Field(default=0)
+ money: Decimal = Field(default=0, max_digits=5, decimal_places=3)
sqlite_file_name = "database.db"