Trending March 2024 # How Rollup Works In Postgresql # Suggested April 2024 # Top 10 Popular

You are reading the article How Rollup Works In Postgresql updated in March 2024 on the website Hatcungthantuong.com. We hope that the information we have shared is helpful to you. If you find the content interesting and meaningful, please share it with your friends and continue to follow and support us for the latest updates. Suggested April 2024 How Rollup Works In Postgresql

Introduction to PostgreSQL ROLLUP

The PostgreSQL ROLLUP is an extension of the GROUP BY clause. Generally, the PostgreSQL GROUP BY ROLLUP is used for data analytics operations. For performing data analytics related operations, so many tools or software are available in the market. PostgreSQL is not made for Data Analytics purpose; with the help of the operations like ROLLUP, we can support data analytics operations on real-time data.

Start Your Free Data Science Course

Hadoop, Data Science, Statistics & others

Syntax:

SELECT c1, c2, c3, aggregate_function(c4) FROM table GROUP BY ROLLUP (c1, c2, c3);

(c1, c2, c3)

(c1,c2)

(c1)

()

We can also perform a partial roll up to reduce the count of sub-totals created.

SELECT c1, c2, c3, aggregate(c4) FROM table_name GROUP BY c1, ROLLUP (c2, c3); How ROLLUP works in PostgreSQL?

We can use a single statement to generate multiple grouping sets with the help of the PostgreSQL ROLLUP option.

The PostgreSQL ROLLUP option adds extra rows in the result set, allowing us to get total and super-aggregate rows.

In order to analyze the hierarchical data like creating grand-total or sub-total, we use the PostgreSQL ROLLUP option.

Examples of ROLLUP in PostgreSQL

Let’s create a table named Furniture.

Code:

CREATE table furniture ( furniture_id SERIAL PRIMARY KEY, furniture_name VARCHAR (256) NOT null, furniture_type VARCHAR (256) NOT null, furniture_price int NULL );

Now, insert some data in the furniture table to execute SQL statements.

INSERT INTO furniture (furniture_name,furniture_type,furniture_price) VALUES ('Chair','Wood',2500), ('Chair','Plastic',2000), ('Table','Wood',5000), ('Table','Plastic',4000), ('Sofa','Wood',10000), ('Sofa','Plastic',8000), ('Bed','Wood',15000), ('Bed','Plastic',13000);

Illustrate the result of the above statement with the help of the following snapshot and the SELECT statement.

SELECT * FROM furniture; Example #1 – ROLLUP with one column

The following SQL statement uses the GROUP BY clause and the SUM() function to find the total furniture price from furniture_name.

Code:

SELECT furniture_name, SUM(furniture_price) FROM furniture GROUP BY furniture_name;

Output:

Illustrate the result of the above statement with the help of the following snapshot.

To fetch the total furniture price of all Furniture, we can use the PostgreSQL ROLLUP to the GROUP BY clause as follows:

SELECT furniture_name, SUM(furniture_price) FROM furniture GROUP BY ROLLUP (furniture_name);

Output:

Illustrate the result of the above statement with the help of the following snapshot.

You can see the NULL value in the furniture_name column, which shows the grand total super-aggregate result.

In this above example, the PostgreSQL ROLLUP option allows the statement to add an extra row showing the total furniture price.

As we have seen, the output shows a NULL value in a newly produced row, which we can make more readable using the COALESCE() function.

Code:

SELECT COALESCE(furniture_name, 'Total furniture price') AS furniture_name, SUM(furniture_price) FROM furniture GROUP BY ROLLUP (furniture_name);

Output:

Illustrate the result of the above statement with the help of the following snapshot.

Example #2 – ROLLUP with multiple columns

The following SQL statement generates the furniture result by furniture_name and furniture_type:

Code:

SELECT furniture_name, furniture_type, SUM(furniture_price) FROM furniture GROUP BY furniture_name, furniture_type;

Output:

Illustrate the result of the above statement with the help of the following snapshot.

Now add the ROLLUP to the GROUP BY clause as follows:

SELECT furniture_name, furniture_type, SUM(furniture_price) FROM furniture GROUP BY ROLLUP (furniture_name , furniture_type);

Output:

Illustrate the result of the above statement with the help of the following snapshot.

Explanation:

The set of furniture_type rows for a specified furniture_name, an additional summary row, generates the total furniture price. The values in the furniture_type column are set to NULL in the newly added row.

Following all rows, an additional summary row generates the total furniture price of all furniture names and furniture types. The values in the furniture_name and furniture_type columns are set to NULL in the newly added rows.

Example #3 – ROLLUP with a partial rollup

We can use it to do a partial rollup which reduces the count of sub-totals generated, as shown in the following example:

Code:

SELECT furniture_name, furniture_type, SUM(furniture_price) FROM furniture GROUP BY furniture_name, ROLLUP (furniture_type);

Output:

Illustrate the result of the above statement with the help of the following snapshot.

The above example generates an aggregate summary for the furniture_type column, not the furniture_name column.

Conclusion

From the above article, you have seen how to use it. Also, we have added some examples of PostgreSQL ROLLUP to understand it in depth.

Recommended Articles

We hope that this EDUCBA information on “PostgreSQL ROLLUP” was beneficial to you. You can view EDUCBA’s recommended articles for more information.

You're reading How Rollup Works In Postgresql

How Rank() Function Works In Postgresql ?

Introduction to PostgreSQL RANK()

The following article provides an outline of PostgreSQL RANK(). We can assign a rank to each row of the partition of a result set by using the RANK() function. The rank of the first row of a partition is 1. The rank is incremented in a fashion where the next row’s rank equals the number of rows tied to the rank. Since the values of the rank computation are determined internally by the OVER clause, no explicit parameters are required.

Start Your Free Data Science Course

Hadoop, Data Science, Statistics & others

Syntax:

RANK() OVER ( [PARTITION BY partition_exp, .... ] )

Explanation:

PARTITION BY clause: The rows of the partitions of the result set to which the PostgreSQL RANK() function is applied.

ORDER BY clause: Defines the order of rows in each partition to which the PostgreSQL RANK() function is applied.

How RANK() Function works in PostgreSQL?

To calculate the rank of the next row, the PostgreSQL RANK function adds the number of rows to the position assigned to the previous rank.

Because of this, the rank might not be sequential.

All of the partition rows with the same values get the same rank.

Examples of PostgreSQL RANK()

Now let’s create a new table of name ‘Grades’, which will have a column named’Grade’ using CREATE TABLE statement as follows:

Code:

CREATE TABLE Grades ( Grade VARCHAR(1) );

Now, insert some data into the ‘Grades’ table using the INSERT statement as follows:

Code:

INSERT INTO Grades(Grade) VALUES ('A'),('A'),('A'), ('B'),('B'), ('C'), ('D');

Illustrate the content of the Grades table with the help of the following snapshot and SQL statement.

Code:

SELECT Grade FROM Grades;

Output:

Now, with the help of the RANK() Function, we can assign a rank to the row of the Grade column in the result set of the Grades table as follows:

Code:

SELECT Grade, RANK () OVER ( ORDER BY Grade ) grade_rank FROM Grades;

Output:

From the above snapshot, we can see that the first three rows have the rank assigned as rank 1, which is the same for all rows whose value is ‘A’.

The rank of the fourth and fifth rows is assigned to rank 4 because of the PostgreSQL.

RANK() function calculated it as the previous rank summed with a total number of rows tied to that rank. Similarly, it assigns rank 6 and ranks 7 to the sixth and seventh rows, respectively.

Now let’s create tables of name ‘transaction’ and ‘invoices’ in order to understand the RANK function with the PARTITION BY clause.

Code:

CREATE TABLE transaction ( transaction_id serial PRIMARY KEY, transaction_data VARCHAR (256) NOT NULL ); CREATE TABLE invoices ( invoice_id serial PRIMARY KEY, transaction_id INT NOT NULL, invoice_data VARCHAR (256) NOT NULL, invoice_amount INT NOT NULL, FOREIGN KEY (transaction_id) REFERENCES transaction (transaction_id) );

Now insert some data in the transaction and invoices table by using the INSERT statement as follows:

Code:

INSERT INTO transaction (transaction_data) VALUES ('Purchase of Mobile'), ('Purchase of PC'), ('Purchase of Headphone'), ('Purchase of Mouse'), ('Purchase of Cable'); INSERT INTO invoices (invoice_data, transaction_id,invoice_amount) VALUES ('Purchase of Mobile', 1,30500), ('Purchase of Mobile', 1,30500), ('Purchase of Mobile', 1,20500), ('Purchase of PC', 2,15000), ('Purchase of PC', 2,12000);

Illustrate the result of the above statement with the help of the following snapshots and select statements:

Code:

select * from transaction;

Output:

Code:

select * from invoices;

Output:

Example #1

without PARTITION

Code:

SELECT invoice_id, invoice_data, invoice_amount, RANK () OVER ( ORDER BY invoice_amount DESC ) invoice_amount_rank FROM invoices;

Output:

In the above example, the entire table is considered a single PARTITION as we have not defined the Partition BY clause.

Example #2

with PARTITION BY

Code:

SELECT invoice_id, invoice_data, invoice_amount, transaction_data, RANK () OVER ( PARTITION BY i.transaction_id ORDER BY invoice_amount DESC ) invoice_amount_rank FROM invoices i INNER JOIN transaction t ON i.transaction_id = t.transaction_id;

Output:

In the above example, we have defined the PARTITION BY clause. In PostgreSQL, you can use the PARTITION BY clause to group invoices into partitions based on the transaction_id column. Also, we have an ORDER BY clause defined, which sorts invoices from high to low in each partition by their invoice_amount.

Here, you can use the RANK function in PostgreSQL to assign a rank to each transaction data, which will reset when the transaction data changes. This allows for clear visualization of the assigned ranks for each invoice.

Conclusion

From the above article, we hope you understand how to use the PostgreSQL RANK function and how the PostgreSQL RANK() function works to assign the rank and fetch the data. Also, we have added some examples of the PostgreSQL RANK() Function to understand it in detail.

Recommended Articles

We hope that this EDUCBA information on “PostgreSQL RANK()” was beneficial to you. You can view EDUCBA’s recommended articles for more information.

How To Create A Temporary Table In Postgresql

A temporary table in PostgreSQL is a table that exists only for the duration of a single database session. After the session ends, the temporary table is automatically dropped. In this tutorial, you will learn how to create a temporary table in PostgreSQL.

Prerequisites

Before proceeding with this tutorial, you should have:

Access to a PostgreSQL server.

Basic knowledge of SQL.

Step 1: Connect to the PostgreSQL Server

Connect to the PostgreSQL server using your preferred client. You can use the psql command-line tool or a graphical client such as pgAdmin or DBeaver.

Step 2: Create a Temporary Table

To create a temporary table in PostgreSQL, you can use the CREATE TEMPORARY TABLE statement followed by the table definition. For example, the following statement creates a temporary table named temp_users with two columns: id and name.

CREATE TEMPORARY TABLE temp_users ( id SERIAL PRIMARY KEY, name VARCHAR(100) NOT NULL );

The SERIAL data type is used for auto-incrementing columns in PostgreSQL. The PRIMARY KEY constraint ensures that the id column is unique and not null. The NOT NULL constraint ensures that the name column is not null.

Step 3: Insert Data into the Temporary Table

Once the temporary table is created, you can insert data into it using the INSERT INTO statement. For example, the following statement inserts two rows into the temp_users table:

INSERT INTO temp_users (name) VALUES ('John Doe'), ('Jane Smith');

You can verify that the data was inserted successfully by running a SELECT statement:

SELECT * FROM temp_users;

The output should be:

—-+————

Step 4: Use the Temporary Table

You can use the temporary table just like any other table in PostgreSQL. For example, you can join it with other tables, filter rows based on certain criteria, or aggregate data. Here’s an example of a SELECT statement that returns the count of distinct names in the temp_users table:

SELECT COUNT(DISTINCT name) FROM temp_users;

The output should be:

count ------- 2 Step 5: Drop the Temporary Table

When you’re done using the temporary table, you can drop it using the DROP TABLE statement. For example, the following statement drops the temp_users table:

DROP TABLE temp_users;

The temporary table will be automatically dropped when the database session ends, but it’s a good practice to clean up after yourself.

Troubleshooting

If you try to create a temporary table with the same name as an existing permanent table, you will get an error message: ERROR: relation "my_table" already exists To avoid this error, choose a unique name for your temporary table.

If you try to use a temporary table outside of the database session that created it, you will get an error message: ERROR: relation "temp_users" does not exist This is because temporary tables are automatically dropped at the end of the session. If you need to use the same temporary table in multiple sessions, you can create it again in each session.

Conclusion

In this tutorial, you learned how to create a temporary table in PostgreSQL, insert data into it, use it in queries, and drop it when you’re done. Temporary tables can be useful for storing data that’s only needed temporarily and don’t clutter up your database with unnecessary tables.

How Bcrypt Works In Flask

Introduction to Flask bcrypt

Flask bcrypt is defined as a flask extension that enables users with utilities related to bcrypt chúng tôi bcrypt is a hashing function for password that is based on the Blowfish cipher and incorporates salt for protecting the application against any rainbow table attacks. We know, too many new terminologies. Let us decipher that! Salt is an additional input of random data that helps safeguard passwords when stored whereas rainbow table is a precomputed table that enables caching of cryptographic hash functions quite often used for cracking password hashes. The bcrypt is an adaptive function which can be deliberately made slower so that application is resistant to brute force attacks.

Start Your Free Software Development Course

Web development, programming languages, Software testing & others

Syntax of Flask bcrypt

1. Installing Flask bcrypt module in python.

pip install flask-bcrypt

2. Instantiate bcrypt object in python.

from flask import Flask from flask.ext.bcrypt import Bcrypt appBcrypt = Flask(__name__) bcrypt = Bcrypt(appBcrypt)

3. Hash a password using defined method through the bcrypt object created.

Python 2:

Python 3:

4. Check a hashed password through the bcrypt object created.

How bcrypt Works in Flask?

In order to understand about hashing and in particular about bcrypt, it is important for us to understand a few terminologies which might be either new are so confusingly used that there is a need to clear the air of confusion. The first interchangeable terms that are used are Authentication and Authorization. In the process of authentication, we make sure on who the user is as they claim them to be, whereas in authorization, it is made sure that user is allowed to access a route or resource. Hence, the password about which we will talk about in hashing using Bcrypt, needs to undergo authentication and once authenticated, the user will be authorized to proceed with the next tasks.

These passwords are very critical to oneself, as one’s either financial or personal data might be at risk of compromise in case the passwords falls into wrong hands and can even lead to a terrible security breach. Hence, the stored password should never be in plain text. Now, in case we need to store password, we need to hash a password and then store it into the database. This process of hashing is alternatively termed as one-way encryption which has a motto of never decrypting the password. Now, if the password is never decrypted, how does it authenticate. For this we hash the password sent by user and then match the hash value instead of performing decrypt on the stored hashed password. One of the technique or modules which enables flask to perform such hashing operation is present in flask bcrypt about which we will now know on how this module works, now that we have the clear understanding of the circumstances bcrypt works in.

At first, we would need to install the flask-bcrypt module in the environment that is used for development of the flask application. We would need to use pip command while installing the module. As a next step, we would need to start building our flask application where we would need to first import the installed module. Once the import is complete, we would need to instantiate the object of bcrypt. With this we can now use the object created throughout the code. At this point we have an object of bcrypt created that will have all the API calls necessary for the utilities of hashing in a flask application.

There are various hash methods present. With any one of the hashing methods, we would try to generate a password hash by available hashlib ones and keep the hashed password same. With this hashed password, when a user tries to input another password, we would use the API of check_password_hash. This API will take in 2 values, one being the hash value and the other being the input of the user. Now the API will try to hash the value of the input by user and then look if the hash value of the user input matches to the hash value of the stored password and in this way it will authenticate the user.

Incase one tries to look at the hashed password, what they will see is a byte literal which might not make any sense, but instead contains information of the hashed value and also about the information on how the password was hashed. We also talked about a utility of bcrypt where in we can increase the time it takes to hash the password. By doing this we can delay the quick successive brute force attacks and thus saving from any malicious attacks. With this we now know the working of bcrypt in flask and what environment are they used in.

Examples of Flask bcrypt

Given below are the examples of Flask bcrypt:

Example #1

Installing flask bcrypt module in python.

Syntax:

pip install flask-bcrypt

Output:

Example #2

Hash a password using defined method through the bcrypt object created.

Syntax:

from flask import Flask, request from datetime import timedelta from flask_bcrypt import Bcrypt appBcrypt = Flask(__name__) bcryptObj = Bcrypt(appBcrypt) @appBcrypt.route("/login", methods = ['POST','GET']) def login(): if request.method == 'POST': studentName = request.form['studentName'] password = request.form['password'] hashPassword = bcryptObj.generate_password_hash(password) The hashed password is being followed is: {}'''.format(studentName, password, hashPassword) if __name__ == "__main__": appBcrypt.run(debug=True)

Output:

Example #3

Check a hashed password through the bcrypt object created.

Syntax:

from flask import Flask, request from datetime import timedelta from flask_bcrypt import Bcrypt appBcrypt = Flask(__name__) bcryptObj = Bcrypt(appBcrypt) @appBcrypt.route("/login", methods = ['POST','GET']) def login(): if request.method == 'POST': studentName = request.form['studentName'] password = request.form['password'] hashPassword = bcryptObj.generate_password_hash(password) if bcryptObj.check_password_hash(hashPassword, 'eduCBA'): The password matches with the first group'''.format(studentName) elif bcryptObj.check_password_hash(hashPassword, 'eduCBAPremium'): The password matches with the Premium group'''.format(studentName) else: return ''' None of the group ''' if __name__ == "__main__": appBcrypt.run(debug=True)

Password matches the first group:

Password matches the premium group:

Password matches the none of the groups:

Conclusion

In this article we have got to know about the full details of what bcrypt is and an hands-on training on how hashing looks like and how hashed values are checked even without decrypting it back. Now it lies in hands of reader to utilize the knowledge in their flask application password hashing.

Recommended Articles

We hope that this EDUCBA information on “Flask bcrypt” was beneficial to you. You can view EDUCBA’s recommended articles for more information.

How Exists Works In Mongodb?

Definition of MongoDB exists

MongoDB provides different types of functionality to the user, the MongoDB exists as one of the functionalities provided by MongoDB. Basically, MongoDB provides a different comparison operator to the user, $exists is one of the comparison operators, when we set the $exists operator in the field of collection that means the $exists operator is true. After that $exists operator compares all the documents from the collection including the null field. That means as per our requirement we can set the $exists operator in the collection and get the desired result. When the set $exists operator is false then it returns the documents that do not match with the set value.

Start Your Free Data Science Course

Hadoop, Data Science, Statistics & others

Syntax:

Explanation

After that, we set the comparison operator that is $exists is true as shown.

How exists works in MongoDB?

Now let’s see how the $exists operator works in MongoDB as follows.

First, try to understand what the operator is. MongoDB provides different kinds of operators such as comparison, logical, element array and bitwise, etc. But we commonly used comparison operators among the different operators. Again we have different types of comparison operators such as eq, gt, lt, and gte, etc, and this operator we can use as per our requirement.

The working of the “not equal” operator is simple; we just need to mention the specified field name with the specified value that we want. The specified field name and specified value depend on the user. At the time of execution, it compares all specified values with all documents from the collection and if the value of the document is not equal to the specified value then it displays specified records.

Basically, the $exists operator is used to compare the field values that we need which means as per user requirement we can display the document from the collection. If we set $exists is true then it displays the matched field value that we already set and if we set $exist is false then it shows all fields that do not contain the field value that we already set from the collection. In the event that we make an association between collection and assortment, we see likenesses between lines – reports and sections – fields. The greatest contrast is that each archive from the same assortment can contain altogether different arrangements of fields. So the field can contain invalid, yet it might likewise not be there. Now and then, we need to separate between those. The method of doing checks additionally relies upon the utilization and what would you like to accomplish.

Examples

Now let’s see different examples of the $exists comparison operator in the MongoDB for better understanding as follows.

First, we need to create the new collection but before that, we need to create the new database by using the following statement as follows.

First, we created a sample database by using the following statement as follows.

use sample

Explanation

In the above statement, we use the command to create the new database, here we successfully created a sample database and we use it. The end result or we can say the output of the above statement we illustrated by using the following screenshot as follows.

After successful creation of the database, we need to create the collection by using the following statement as follows.

Explanation

In the above statement, we use create collection command to create the new collection; here we created a new collection name as a student_sample as shown. The end result or we can say the output of the above statement we illustrated by using the following screenshot as follows.

Now we have a new collection, so now we need to insert the different document into the newly created collection that is student_sample with a null field so we can get the result. For insertion of the document, we can use the following statement as follows.

db.student_sample.insert({ name: “Sachin”, dept: “IT”, marks: 98, dbsm:null})

Explanation

By using the above statement we insert a document into the student_sample collection, in which we insert names of students, department of the student, and dbsm marks with the null field as shown. Now we can see all documents from the collection by using the following statement as follows.

db.student_sample.find()

Explanation

Now we have a collection with documents now implementing the $exists as follows.

db.student_sample.find({dbsm:{$exists: true}})

Explanation

In the above example, we use a comparison operator that is $exists as shown, here we set the field value that dbsm with true. The dbsm contains a null value. The end result or we can say the output of the above statement we illustrated by using the following screenshot as follows.

So similarly we can implement $exists with false as per user requirement as follow here we just need to write the false instead of true.

db.student_sample.find({dbsm:{$exists: false}})

Conclusion

We hope from this article you learn more about MongoDB exists. From the above article, we have learned the basic syntax of $exists and we also see different examples of exists. From this article, we learned how and when we use MongoDB exists.

Recommended Articles

This is a guide to MongoDB exists. Here we discuss the definition, syntax, How exists works in MongoDB? examples with code implementation. You may also have a look at the following articles to learn more –

How Set Works In Haskell

Introduction to Haskell set

In Haskell as the name suggest set is used to store the elements, set are immutable in nature and comes under the data structure category, which provide us a way to store elements inside it, which should be in orders and unique as well. The set in Haskell provide us effective and efficient way of deletion, insertion and other operations. As we said they are immutable in nature that means if we try to modify the existing set it will always return us the new set containing the new modified elements.

Start Your Free Software Development Course

Web development, programming languages, Software testing & others

Syntax of Haskell set

The set is used to store the elements, and also we have to use some package to use it inside our program.

import qualified chúng tôi as Set:

name_of_set = Set.empty name_of_set = Set.singleton 'your single value' name_of_set = Set.fromList 'your list'

As you can see in the above line of syntax, we have three different approaches by the use of it we can create a set in Haskell, one issuing empty, another one using singleton and third is form the existing list we have

Let’s take an practice syntax:

demoset = Set.empty

As you can see in the above code of syntax we are trying to create an empty set by the use of ’empty’ method of set.

How set Works in Haskell?

The set is used to store the elements, set store the unique element, also in order in which they inserted into the set. We have one simplest way to create the set in Haskell by the use of existing list we have, also we can create it by using the empty and singleton method available in Haskell set.

Let’s take a closer look at the import packages which is required to import in the program:

Packs to use for set:

1. import qualified chúng tôi as Set

This mentions package should be import in the program otherwise we will get error while creating the set in Haskell, because all the method of creating set present inside the package only. In order to access them it should be in the place.

2. Create set by using the existing list object

We can create set by the use of existing list variable. For this we can use the ‘fromList’ from the set package available. But to use this we have to have set package imported into the program.

Let’s have a look at the syntax for the ‘fromList’ to start using it.

name_of_set = Set.fromList 'your list'

As you can see in the above line of code, it is very easy to use a handle

Let’s take a sample piece of code:

demoset = Set.fromList [10, 20, 30]

This will create a set which contain the elements from the list, and it will return us the new set by the existing list object in Haskell.

3. Create an empty set

We can also create an empty set by the use of ’empty’ method available inside the set package, for this also set package is to be present in the program at the top.

Let’s take a look at the syntax for the ’empty’ to start using it while programming:

name_of_set = Set.empty

As you can see in the above line of code, it is very easy to use a handle.

Let’s take a sample piece of code:

Code:

demoset = Set.empty

This will create a set which is empty.

4. Create set using the single value

In Haskell we can also create a singleton set which will contain the single value inside it, for this we have ‘singleton’ method available in the set library of Haskell.

Let’s take an look at the syntax for the ‘singleton’ to start using it while programming:

name_of_set = Set.singleton 'your single value'

let’s take an sample piece of code understand:

demoset = Set.singleton 'A'

In the following ways we can create set in Haskell, but the set package is important to include it, is also an in built function of Haskell, so we do not require to install any dependency for this to use in our program.

Example of Haskell set

Given below is the example mentioned:

In this example we are trying to create the set in Haskell using the set library and fromList function of the set package.

Code:

import qualified chúng tôi as Set set1 = Set.fromList ['a'..'z'] set2 = Set.fromList [10, 20, 30, 40, 50, 60] set3 = Set.fromList ["Hello", "world", "bye", "enjoy", "moment"] set4 = Set.fromList [1, 2, 3, 4, 5, 6, 7] set5 = Set.fromList [400, 200, 100, 500, 900, 800] set6 = Set.fromList ["value 1", "value 2", "value 3", "value 3", "value 4"] set7 = Set.fromList [1.1, 2.2, 3.3, 4.4, 5.5, 6.6] main = do print("Demo to show set in Haskell !!") print("Printing the result !!") print("first set is :::", set1) print("second set is :::", set2) print("third is :::", set3) print("fourth set is :::", set4) print("fifth set is :::", set5) print("sixth set is :::", set6) print("seventh set is :::", set7)

Output:

Conclusion

By the use of set we can store our elements inside the set, it also main the orders of the insertion of the elements. One important thing about set that we only contained the unique elements, so in this way we can avoid duplicate data as well while preforming business logic for the application.

Recommended Articles

We hope that this EDUCBA information on “Haskell set” was beneficial to you. You can view EDUCBA’s recommended articles for more information.

Update the detailed information about How Rollup Works In Postgresql on the Hatcungthantuong.com website. We hope the article's content will meet your needs, and we will regularly update the information to provide you with the fastest and most accurate information. Have a great day!