EDUCBA

EDUCBA

MENUMENU
  • Free Tutorials
  • Free Courses
  • Certification Courses
  • 360+ Courses All in One Bundle
  • Login
Home Data Science Data Science Tutorials PostgreSQL Tutorial PostgreSQL Float
Secondary Sidebar
PostgreSQL Tutorial
  • Basic
    • What is PostgreSQL
    • PostgreSQL Features
    • How to Install PostgreSQL
    • PostgreSQL Versions
    • PostgreSQL Architecture
    • PostgreSQL GUI
    • Postgres Command-Line
    • PostgreSQL Variables
    • PostgreSQL Data Types
    • PostgreSQL NOT NULL
    • PostgreSQL Integer
    • PostgreSQL Boolean
    • PostgreSQL BIGINT
    • PostgreSQL NULLIF
    • PostgreSQL Administration
    • PostgreSQL Commands
    • PostgreSQL Operators
    • PostgreSQL IN Operator
    • Postgres like query
    • PostgreSQL encode
    • PostgreSQL Cheat Sheet
    • PostgreSQL List Databases
    • PostgreSQL Rename Database
  • Control Statement
    • PostgreSQL IF Statement
    • PostgreSQL if else
    • PostgreSQL CASE Statement
    • PostgreSQL LOOP
    • PostgreSQL For Loop
    • PostgreSQL While Loop
  • Joins
    • Joins in PostgreSQL
    • PostgreSQL Inner Join
    • PostgreSQL Outer Join
    • LEFT OUTER JOIN in PostgreSQL
    • PostgreSQL FULL OUTER JOIN
    • PostgreSQL LEFT JOIN
    • PostgreSQL Full Join
    • PostgreSQL Cross Join
    • PostgreSQL NATURAL JOIN
    • PostgreSQL UPDATE JOIN
  • Queries
    • PostgreSQL Queries
    • PostgreSQL INSERT INTO
    • PostgreSQL WHERE Clause
    • PostgreSQL WITH Clause
    • PostgreSQL ORDER BY
    • PostgreSQL ORDER BY Random
    • PostgreSQL ORDER BY DESC
    • PostgreSQL GROUP BY
    • PostgreSQL group_concat
    • PostgreSQL HAVING
    • PostgreSQL Recursive Query
  • Advanced
    • PostgreSQL Schema
    • Postgres List Schemas
    • PostgreSQL Drop Schema
    • PostgreSQL VARCHAR
    • Array in PostgreSQL
    • PostgreSQL DDL
    • PostgreSQL List Users
    • Postgres Default User
    • Postgres add user
    • PostgreSQL User Password
    • PostgreSQL log_statement
    • PostgreSQL repository
    • PostgreSQL shared_buffer
    • PostgreSQL String Functions
    • PostgreSQL Compare Strings
    • PostgreSQL Text Search
    • PostgreSQL TEXT
    • PostgreSQL String Array
    • PostgreSQL where in array
    • PostgreSQL Constraints
    • PostgreSQL UNIQUE Constraint
    • PostgreSQL CHECK Constraint
    • PostgreSQL INTERSECT
    • PostgreSQL Like
    • Cursors in PostgreSQL
    • PostgreSQL UNION ALL
    • Indexes in PostgreSQL
    • PostgreSQL Index Types
    • PostgreSQL REINDEX
    • PostgreSQL UNIQUE Index
    • PostgreSQL Clustered Index
    • PostgreSQL DROP INDEX
    • PostgreSQL DISTINCT
    • PostgreSQL FETCH
    • PostgreSQL RAISE EXCEPTION
    • PostgreSQL Auto Increment
    • Sequence in PostgreSQL
    • Wildcards in PostgreSQL
    • PostgreSQL Subquery
    • PostgreSQL Alias
    • PostgreSQL LIMIT
    • PostgreSQL Limit Offset
    • PostgreSQL LAG()
    • PostgreSQL Table
    • Postgres Show Tables
    • PostgreSQL Describe Table
    • PostgreSQL Lock Table
    • PostgreSQL ALTER TABLE
    • Postgres Rename Table
    • PostgreSQL List Tables
    • PostgreSQL TRUNCATE TABLE
    • PostgreSQL Table Partitioning
    • Postgres DROP Table
    • PostgreSQL Functions
    • PostgreSQL Math Functions
    • PostgreSQL Window Functions
    • Aggregate Functions in PostgreSQL
    • PostgreSQL Primary Key
    • Foreign Key in PostgreSQL
    • PostgreSQL Procedures
    • PostgreSQL Stored Procedures
    • PostgreSQL Views
    • PostgreSQL Materialized Views
    • Postgres Create View
    • PostgreSQL Triggers
    • PostgreSQL DROP TRIGGER
    • PostgreSQL Date Functions
    • PostgreSQL TO_DATE()
    • PostgreSQL datediff
    • PostgreSQL Timestamp
    • PostgreSQL CURRENT_TIMESTAMP()
    • PostgreSQL Notify
    • PostgreSQL LENGTH()
    • PostgreSQL blob
    • PostgreSQL Median
    • PostgreSQL kill query
    • PostgreSQL Formatter
    • PostgreSQL RANK()
    • PostgreSQL Select
    • PostgreSQL Average
    • PostgreSQL DATE_PART()
    • PostgreSQL EXECUTE
    • PostgreSQL COALESCE
    • PostgreSQL EXTRACT()
    • PostgreSQL Sort
    • PostgreSQL TO_CHAR
    • PostgreSQL Interval
    • PostgreSQL Number Types
    • PostgreSQL ROW_NUMBER
    • Alter Column in PostgreSQL
    • PostgreSQL Identity Column
    • PostgreSQL SPLIT_PART()
    • PostgreSQL CONCAT()
    • PostgreSQL replace
    • PostgreSQL TRIM()
    • PostgreSQL MAX
    • PostgreSQL DELETE
    • PostgreSQL Float
    • PostgreSQL OID
    • PostgreSQL log
    • PostgreSQL REGEXP_MATCHES()
    • PostgreSQL MD5 
    • PostgreSQL NOW()
    • PostgreSQL RANDOM
    • PostgreSQL round
    • PostgreSQL Trunc()
    • PostgreSQL TIME
    • PostgreSQL IS NULL
    • PostgreSQL CURRENT_TIME
    • PostgreSQL MOD()
    • Postgresql Count
    • PostgreSQL Datetime
    • PostgreSQL MIN()
    • PostgreSQL age()
    • PostgreSQL enum
    • PostgreSQL OR
    • PostgreSQL Wal
    • PostgreSQL NOT IN
    • PostgreSQL SET
    • PostgreSQL Current Date
    • PostgreSQL Compare Date
    • PostgreSQL SERIAL
    • PostgreSQL UUID
    • PostgreSQL Merge
    • PostgreSQL Database
    • PostgreSQL Clone Database
    • PostgreSQL Copy Database
    • PostgreSQL Show Databases
    • PostgreSQL Restore Database
    • PostgreSQL DROP DATABASE
    • PostgreSQL ALTER DATABASE
    • Postgres DROP Database
    • Postgres Dump Database
    • PostgreSQL OFFSET
    • PostgreSQL GRANT
    • PostgreSQL COMMIT
    • PostgreSQL ROLLUP
    • PostgreSQL JSON
    • EXPLAIN ANALYZE in PostgreSQL
    • PostgreSQL Temporary Table
    • PostgreSQL Show Tables
    • PostgreSQL cluster
    • PostgreSQL Replication
    • PostgreSQL Logical Replication
    • PostgreSQL flush privileges
    • PostgreSQL Tablespaces
    • CAST in PostgreSQL
    • PostgreSQL CTE
    • hstore in PostgreSQL
    • PostgreSQL Encryption
    • PostgreSQL DECODE()
    • PostgreSQL Vacuum
    • PostgreSQL EXCLUDE
    • Postgres Change Password
    • Postgres Delete Cascade
    • PostgreSQL EXCEPT
    • PostgreSQL Roles
    • PostgreSQL Link
    • PostgreSQL Partition
    • PostgreSQL column does not exist
    • PostgreSQL Log Queries
    • PostgreSQL escape single quote
    • PostgreSQL Query Optimization
    • PostgreSQL Character Varying
    • PostgreSQL Transaction
    • PostgreSQL Extensions
    • PostgreSQL Import CSV
    • PostgreSQL Client
    • PostgreSQL caching
    • PostgreSQL Incremental Backup
    • PostgreSQL JSON vs JSONNB
    • PostgreSQL JDBC Driver
    • PostgreSQL Interview Questions

PostgreSQL Float

By Sohel SayyadSohel Sayyad

PostgreSQL Float

Introduction to PostgreSQL Float Data Type

PostgreSQL provides different types of data types. The single table consists of a different column with different data types and we need to store floating numbers that contain decimal points in the float column and values are not approx., so at this condition, we use float data type. The float data type belongs under the numeric data type’s category. Float data type supports floating-point number, real number, and numeric with 4 or 8 bytes number. In float data type we use bit size where bit size means the length of the string. For example 3.4, 654.3, and -345.32 these are the floating-point numbers. The system memory is limited, you can’t store numbers with infinite precision, so that reason we use float data type and this is the main purpose of the float data type.

Syntax and Parameters:

Start Your Free Data Science Course

Hadoop, Data Science, Statistics & others

Consider the below syntax to understand how we can use the float data type.

1. float(p)

Column_name flaot

Explanation

Where float is the data type and p this defines minimum acceptable binary digits and it is accepted 4 or 8 bytes numbers. Where column name means specific column name in the created table and float means float data type

2. real (num)

Explanation

Where real data type and num is number and it is single precision.

3. numeric or numeric (p,s):

Explanation

Where Numeric is the data type and where p for digit and s for number after the decimal point and it is double precision.

How does Float Data Type work in PostgreSQL?

Double precision floating point decimal stored in float data type. Float data type corresponds to IEEE 4 byte floating to double floating-point. Generally, float data type stores scientific numbers which can be calculated close to value. The number entered in the float data type can differ slightly because float data type returns the most significant digit. This is a range of float data type 1E-307 to 1E+308.

Examples

Mainly there are three types of floating-point numbers in PostgreSQL as below

1. Float (n):

In this type floating-point number who have precision at least, n, and up to a maximum 8 bytes.

Example

Create table float_point (floatn float4 not null);
insert into float_point (floatn) values (543.23);
select * from float_point;

Explanation

In the above statement, we create a column with the name floatn in float_point table and its data type is float4, it shows the result in real. Illustrate the end result of the above declaration by using the use of the following snapshot

 PostgreSQL Float 1

Same example we write for float 8

create table float_point1  (floatn float8 not null);
insert into  float_point1 (floatn) values (5434533453);
select * from float_point1;

Explanation

In the above statement, we create a column with name floatn and data type is float in float_point1 table, it shows result in double precision. Illustrate the end result of the above declaration by using the use of the following snapshot.

PostgreSQL Float 2

2. real:

This is the second data type of float and it is used as a 4-byte floating-point number the real has a vary of at least 1E-37 to 1E+37 with an accuracy of up to 6 decimal digits.

Example

Create  table  float_point_r  (real_no real not null);
insert  into float_point_r (real_no) values (12345623);
select * from float_point_r;

Illustrate the end result of the above declaration by using the use of the following snapshot.

PostgreSQL Float 3

Another example of real data type

CREATE TABLE emp (emp_id INTEGER PRIMARY KEY, emp_name TEXT, emp_age INTEGER, emp_weight REAL);
INSERT INTO emp (emp_id,emp_name,emp_age,emp_weight) VALUES (1, 'Alex', 26, 145.5), (2, 'John', 30, 150.3),  (3, 'Bob', 34, 156.6);
select * from emp;

Explanation

In the above statement emp is the table name and we create a table with different data types like text integer and real data type for emp_weight.

Illustrate the end result of the above declaration by using the use of the following snapshot

PostgreSQL Float 4

3. Numeric or numeric (p,s):

This is the third data type under the float, numeric means that it uses two notations for number represent is a real number with p and s where p for digit and s for number after the decimal point. The numeric(p,s) represents the exact number and it is double precision. The range of double precision is 1E-307 to 1E+308 with an accuracy of at least fifteen digits.

Example

Create  table  float_point_numeric (numeric_no numeric(2,2) );
insert  into  float_point_numeric (numeric_no) values (0.3);
select   * from float_point_numeric;

Illustrate the end result of the above declaration by using the use of the following snapshot

PostgreSQL Float 5

Now we illustrate three data type in following example

create table float_data_type
(floatn float8 not null, realn real not null, numerict numeric(3, 2));
insert  into  float_data_type (floatn,realn,numerict)values
(23456543355, 34564433, 3.22),
(87654354444, 45564333, 4.11);
select * from float_data_type;

Explanation

In the above statement, we execute all three types of float data type, in this example, we create a table with name as float_data_type and create different columns with different data types like column name floatn with float8 data type, realn with a real data type, and numerict with numeric data type. Illustrate the end result of the above declaration by using the use of the following snapshot.

PostgreSQL Float 6

Example

If you want to store a large number of decimal digits that time you require the correct data type, so PostgreSQL provides such a data type we call double precision it is the numeric data type and it uses 8 bytes 0r up to 15 digits. Another name of double precision is float8.

create table test ( test_id SERIAL PRIMARY KEY, test_name VARCHAR(100), float_col double precision);
insert  into test (test_id, test_name, float_col) VALUES (1, 'unit testing',12345678986), (2, 'fun_testing', 76548767523), (3, 'system_testing',0987923467);
select test_id, float_col from test;

Explanation

In the above statement, we implement double precision data type. Illustrate the end result of the above declaration by using the use of the following snapshot.

test id

Conclusion

We hope from the above article you have understood the PostgreSQL FLOAT data type. From the above article, we learn different types of float data types like float, real and numeric with different examples we also see double-precision examples. Finally, the main objective of this data type is to give correct number representation in tables and avoid complexity of integer number representation.

Recommended Articles

This is a guide to PostgreSQL Float. Here we discuss the definition and How does the Float Data Type work in PostgreSQL? You may also have a look at the following articles to learn more –

  1. PostgreSQL DELETE
  2. PostgreSQL MAX
  3. PostgreSQL EXCLUDE
  4. PostgreSQL WITH Clause
Popular Course in this category
PostgreSQL Course (2 Courses, 1 Project)
  2 Online Courses |  1 Hands-on Project |  7+ Hours |  Verifiable Certificate of Completion
4.5
Price

View Course
Primary Sidebar
Footer
About Us
  • Blog
  • Who is EDUCBA?
  • Sign Up
  • Live Classes
  • Corporate Training
  • Certificate from Top Institutions
  • Contact Us
  • Verifiable Certificate
  • Reviews
  • Terms and Conditions
  • Privacy Policy
  •  
Apps
  • iPhone & iPad
  • Android
Resources
  • Free Courses
  • Database Management
  • Machine Learning
  • All Tutorials
Certification Courses
  • All Courses
  • Data Science Course - All in One Bundle
  • Machine Learning Course
  • Hadoop Certification Training
  • Cloud Computing Training Course
  • R Programming Course
  • AWS Training Course
  • SAS Training Course

ISO 10004:2018 & ISO 9001:2015 Certified

© 2023 - EDUCBA. ALL RIGHTS RESERVED. THE CERTIFICATION NAMES ARE THE TRADEMARKS OF THEIR RESPECTIVE OWNERS.

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you

Let’s Get Started

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA Login

Forgot Password?

By signing up, you agree to our Terms of Use and Privacy Policy.

This website or its third-party tools use cookies, which are necessary to its functioning and required to achieve the purposes illustrated in the cookie policy. By closing this banner, scrolling this page, clicking a link or continuing to browse otherwise, you agree to our Privacy Policy

Loading . . .
Quiz
Question:

Answer:

Quiz Result
Total QuestionsCorrect AnswersWrong AnswersPercentage

Explore 1000+ varieties of Mock tests View more