![]() Let’s query the table’s data via the below-provided command: SELECT * FROM emp_data įrom the output, you can observe that the fractional part has been trimmed to two decimal places because the scale was set to “2”.Įxample 2: Create a Column With NUMERIC Data Type (Without Scale) To insert the data into the “emp_data” table, you need to run the “INSERT INTO” statement as follows: INSERT INTO emp_data (emp_name, emp_salary) The above snippet verifies that a table named emp_data with three columns has been created successfully. In this example, we created a column with NUMERIC data type having precision “6” and scale “2”: In this example, we will create a table named “emp_data” with three columns: “ emp_id”, “ emp_name”, and “ emp_salary”: CREATE TABLE emp_data ( Omitting the scale part will store the numeric values without the fractional part.Įxample 1: Create a Column With NUMERIC Data Type (With Scale) The scale parameter is optional and can be omitted. For instance, a numeric value “13411.267” has a precision “ 8” and a scale “ 3”. ![]() Here, the precision represents the total number of digits, while the scale parameter represents the number of fractional digits. ![]() Here is the syntax to use the NUMERIC data type in Postgres: NUMERIC(precision, scale) The NUMERIC data type is a high-precision decimal data type in Postgres that is suitable for storing numbers requiring many decimal places. This blog will explain the usage of the NUMERIC data type in Postgres via Practical examples. It can be defined with specific precision and scale, allowing us to specify the number of decimal places to be stored. The NUMERIC data type is a more precise data type that is used to store decimal values. These data types include INTEGER, NUMERIC, BIGINT, etc., each of which is designed to store different types of numerical values. ![]() These data types allow us to store and manipulate numbers in various formats, from simple integers to complex decimal values. Numeric data types are an essential part of any database system, and PostgreSQL is no exception. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |