You are reading the article How Nullif Function Works In Postgresql? updated in December 2023 on the website Minhminhbmm.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 January 2024 How Nullif Function Works In Postgresql?
Definition of PostgreSQL NULLIFPostgreSQL nullif is a common conditional expression used to handle null values or expressions in PostgreSQL. nullif is also used with the coalesce function to handle the null values. PostgreSQL nullif function returns a null value if provided expressions are equal. If two expressions provided are equal, then it provides a null value; as a result, otherwise, it will return the first expression as a result.
Start Your Free Data Science Course
Syntax:
Below is the syntax of the nullif function as follows.
Select (Argument1 (First value which is used to handle null values), Argument2 (Second value which is used to handle null values)) SELECT Column1, …, ColumnN COALESCE ( NULLIF (Column_name, ''), ) FROM table_name;Parameter:
Select: In PostgreSQL, you can use the NULLIF function with the SELECT statement to fetch data from a table while handling null values or expressions. We can use multiple columns or a single column at one time to fetch data from the table.
Coalesce: Coalesce states that function name in PostgreSQL, which returns as a first non-null value. Coalesce function is essential and useful in PostgreSQL.
We have used coalesce function with nullif function in PostgreSQL.
Argument 1 to Argument 2: Argument is nothing but an integer or character value that we have passing with nullif function. If we have passing two-argument and both contain a different value, then the nullif function will return the first value in a result. If we have to pass both the same values, then it will return a null value as a result.
Column 1 to Column N: This is the table’s column name. If we want to fetch data from a table using nullif function in PostgreSQL, we pass multiple columns simultaneously. Also, we have given the column name with the nullif function in PostgreSQL.
From: In PostgreSQL, you can retrieve data from the keyword FROM with the table name in a SELECT query.
Table name: Table name used with nullif function to fetch data from a table.
Nullif: It is used to handle null values in PostgreSQL; nullif is also used with the coalesce function to handle the null values. nullif function returns a null value if provided expressions are equal; if provided two expressions are equal, then it provides a null value; otherwise, it will return the first expression as a result.
How does NULLIF Function work in PostgreSQL?Below is the working of nullif function in PostgreSQL.
We can use the coalesce function with nullif function in PostgreSQL. Coalesce states that the function name in PostgreSQL which returns as first non-null value as a result. Coalesce function is essential and useful in PostgreSQL.
In PostgreSQL, you can use the common conditional expression NULLIF to handle null values or expressions.
If we have passing two nullif function arguments and the first contains a null value, then the nullif function will return the first value in a result. If we pass both the same value, it will return a null value in a result.
We have used the nullif function in PostgreSQL to prevent the division error by zero.
In PostgreSQL, you can use the nullif function to prevent errors that may occur when comparing two values.
ExamplesBelow is an example of nullif function.
We have using a discount table to describe an example of the nullif function as follows.
Below is the data description of the discount table, which we have used to describe an example of nullif function.
Example #1 testing=# select * from discount;Output:
Example #2In the below example, we have passing values like 50 and 50. The nullif function will return null values because both the arguments which we have passing are the same.
testing=# select nullif (50, 50);In the above example, we pass the same argument with the nullif function so that it will return the null value as a result.
Example #3In the below example, we have passing values as 50 and 100. Nullif function will return the first value, i.e., 50 because both the arguments which we have passing are different.
testing=# select nullif (50, 100);Output:
In the above example, we have a different passing argument with the nullif function so that it will return the first value as a result.
Example #4 testing=# select nullif ('A', 'P');Output:
In the above example, we have a passing different argument with the nullif function so that it will return the first value as a result.
Example #5In the below example, we have to retrieve data from a discount table using the nullif function.
testing=# SELECT cust_id, product_name, COALESCE ( NULLIF (Product_price, '')) AS Product_price FROM discount;Output:
Recommended ArticlesWe hope that this EDUCBA information on “PostgreSQL NULLIF” was beneficial to you. You can view EDUCBA’s recommended articles for more information.
You're reading How Nullif Function Works In Postgresql?
How Find_In_Set() Function Works In Mysql?
Introduction to MySQL FIND_IN_SET()
MySQL FIND_IN_SET() function is a built-in MySQL string function responsible for discovering the position of a given specific string provided in a list of strings separated by a comma. The FIND_IN_SET() function accepts two arguments that allow matching the first value with the second one containing a list of values as substrings separated by a comma character.
Start Your Free Data Science Course
Hadoop, Data Science, Statistics & others
Generally, the FIND_IN_SET() function applies to any field in the database table with a sequence of values differentiated by a comma. The user wants to compare those values with a specific single value. It thus returns the index of the matched string within the list.
SyntaxFollowing is the syntax structure that illustrates the use of the FIND_IN_SET() function in the MySQL server:
FIND_IN_SET(string1, stringlist);
The initial parameter named string1 defines the string which you need to find.
The next parameter, “stringlist,” represents the list of strings that must be examined, and commas separate these strings.
According to the value of the function arguments, the MySQL FIND_IN_SET() will return the value as an integer or a NULL:
If either function’s parameters, i.e., string1 or stringlist, have a NULL value, the function results in a NULL value.
The function will return zero if the stringlist is empty or if the string1 parameter is not found in the stringlist.
The function returns a positive integer value if the string1 parameter is available in the stringlist.
But note that if the string1 consists of a comma(,), the FIND_IN_SET() function performs poorly on execution. If the string1 parameter is a constant string and the stringlist parameter represents a SET column type, the MySQL server will optimize using bit arithmetic.
How does the FIND_IN_SET() function works in MySQL?MySQL consists of many databases, and each database comprises different tables. Tables in MySQL store data in various data types supported by MySQL, and the most commonly used types are integers and strings.
When a MySQL user wants to find out if a specific string exits in any of certain sequences of strings divided by a comma(,) symbol aimed for any query execution, then the built-in MySQL string function FIND_IN_SET() can be applied.
This function provides the required value depending on the search results. For example, suppose we are illustrating the following query to show how the function works in MySQL:
We will search a substring h within a list of strings using the statement below,
SELECT FIND_IN_SET("h", "g,h,k,l");We use the SELECT statement with the FIND_IN_SET() function to evaluate and display the return value. The result from the above query is true as the first parameter, ‘h’ is present in the list as the second parameter. So, Upon execution, the function will produce a positive integer, specifically 2. This is because the first value of the FIND_IN_SET() function is found in the second index of the list of values provided in the function’s second parameter, which is ‘g,h,k,l’.
Similarly, if we take the below query, then the function returns 0 as the output value as the value is not in the list:
SELECT FIND_IN_SET("b", "g,h,k,l");Also, when we define the query as follows then, the output is NULL as the second parameter is NULL:
SELECT FIND_IN_SET("h", NULL);Thus, we can define the position of a string within a particular list of substrings provided by the database tables.
Conversely, the MySQL IN operator takes any number of arguments to show if a value matches any value in a set.
Examples of MySQL FIND_IN_SET()Let us demonstrate some examples using the MySQL FIND_IN_SET() as follows:
Example #1Example to fetch data from a table by MySQL FIND_IN_SET() function:
Suppose we have a table named collection created in our database using the query below:
CREATE TABLE IF NOT EXISTS Collection (ColID INT AUTO_INCREMENT PRIMARY KEY, ColName VARCHAR(255) NOT NULL, Subjects VARCHAR(255) NOT NULL);Also, let us enter a few record rows into the Collection table created:
INSERT INTO Collection (ColName, Subjects) VALUES('o-1','Computers, Maths, Science'),('o-2','Networks, Maths, MySQL'),('o-3',' Computers, English, Data Science'),('o-4','Electric, Maths, Science'),('o-5','Computers, MySQL, English'),('o-6','Science, Web Design'),('o-7','Maths, Science'),('o-8','MySQL, Web Design'),('o-9','Computers');Displaying the contents of the table as follows:
SELECT * FROM Collection;Now, we will find the collection that will accept the Maths subject using the MySQL function FIND_IN_SET() shown below:
SELECT ColName, Subjects FROM Collection WHERE FIND_IN_SET('Computers', Subjects);Output:
Looking for a simple example and its output as follows:
SELECT FIND_IN_SET('h', 'g,h,k,l');Output:
The FIND_IN_SET() function provides the position of the first argument ‘h’ as found in the sequence of values as the second argument of the function.
Example #2Example showing Negativity of MySQL FIND_IN_SET() function:
Considering the previous table, the result value of the function will be empty when MySQL returns false. This occurs when the substring specified in the first argument is not found in the list of values provided as the second argument. Thus, we will apply the MySQL NOT operator to negate the MySQL function FIND_IN_SET(). Finally, we will illustrate the query example with FIND_IN_SET() function using the NOT operator also to search the collection that does not match the PHP subject in the table values:
SELECT ColName, Subjects FROM Collection WHERE FIND_IN_SET('PHP', Subjects);As you can see, no output is produced as a collection because, in the list of values from column Subjects, the FIND_IN_SET() function has not found any matched substring as given in the first argument.
Example #3Difference between IN operator and FIND_IN_SET():
The IN operator defines whether a substring matches any substring set or list and can accept any number of arguments parted by a comma as follows:
SELECT ColName, Subjects FROM Collection WHERE ColName IN ('o-1', 'o-2', 'o-5', 'o-6');Output:
Similarly, using the FIND_IN_SET() will result in the identical output as IN query but takes only two parameters to show a match of value with a list of values divided by a comma:
SELECT ColName, Subjects FROM Collection WHERE FIND_IN_SET(ColName, 'o-1,o-2,o-5,o-6');Output:
ConclusionMySQL FIND_IN_SET() function allows a server to check if a substring as the first argument is present in the list of values composed of substrings in the second argument parted by a comma.
This function, when the value is searched, returns the results based on those values as a positive integer as position(if the value exists in the list), zero(if value not found) or NULL(if any argument is NULL), which can be helpful for MySQL operations at the admin level.
Recommended ArticlesWe hope that this EDUCBA information on “MySQL FIND_IN_SET()” was beneficial to you. You can view EDUCBA’s recommended articles for more information.
How Addslashes() Function Works In Php?
Introduction to PHP addslashes() function
addslashes() function is an inbuild and pre-defined function in PHP which is used for returning a string containing backlashes and is prefixed before all predefined characters present within the string. PHP addslashes() function has a special characteristic that it does not consider any parameters or arguments to be passed from the function. The predefined characters behave differently in this function. addslashes function somewhat differently in comparison to the addcslashes() function because this function accepts specified characters that need to be added before the slashes but is not important for addslashes() function as it doesn’t allow any parameter to pass and appends the slash before the specified character.
Start Your Free Software Development Course
Web development, programming languages, Software testing & others
Syntax
addslashes($string)
addslashes(): The addslashes() function allows only one parameter or argument to be passed from within the function followed by the $ symbol of string.
$string : This is the argument that will be passed to the addslashes function as an input to the function. it specifies a special structure of the attribute designating the string.
How addslashes() function works in PHP?addslashes is a special inbuild function in the PHP defined string references and string packages which generates a quote for the quote string with slashes. It has a return type which returns the string with a special format in a way that the characters within the string will be prefixed following a string of characters:
Single quote: It is represented by a symbol (‘)
Double quote: It is represented by a symbol (” “)
Backslash: It is represented by a symbol ( )
Null: It is represented by the (NUL byte)
Use cases will vary with the string of characters in a way that the characters that will be prefixed before the string with these characters will be escaped set of characters.
This function has been added and came into its usage after PHP version 5.4.0 and above, otherwise, the default value was being considered as magic_quotes_gpc on all types of GET, POST, and cookies being used on the string as mentioned for addslashes() function.
Sometimes this function behaves abnormally once incorporated with the database queries. Therefore, it depends on the type of requirement and versions to check and cope up with the addslashes function once it is in use with PHP. Since this makes it ambiguous to make it work with databases there are times or scenario that may arise for making it sync with Database injection and its related queries at that time it is very much needed to make database-specific escaped functions or prepared statements for its use.
Moreover, many substrings which act or are a part of the addslashes function which includes following function as its companion:
stripcslashes(): It is a function as part of addslashes which is used to generate some un-quoted string but are quoted with some addcslashes.
stripslashes(): It is also a companion of addslashes function which unquote any of the generated quoted string.
addcslashes(): It is another part of addslashes function which works totally complimentary with the addslashes function in a way that it quotes string with inbuild function including a C style pattern for it.
htmlspecialchars(): This function works in a way that a special character gets converted into HTML entities.
Quotemeta(): This function works for characters within characters which are called meta characters type.
get_magic_quotes_gpc(): This function also behaves in a similar fashion with a very less difference of present settings in configuration for setting of magic_quotes_gpc.
Examples of PHP addslashes() FunctionBelow are the different examples :
Example #1This program represents the addslashes function for the representation of the string with an output of the generated string with escaped sequences of characters.
Code:
<?php $str = addslashes(‘hope you are doing good with educba!’); echo($str);
Output:
Example #2This program represents the addslashes function for the representation of the string with an output of the generated string with escaped sequences of characters but supporting the ambiguous behavior of the database injection.
Code:
<?php $str = “Which car is Volkswaon?”; echo addslashes($str) . “ Safe for database injection.”;
Example #3This program represents the addcslashes() function for the representation of the string with an output of the generated string with escaped sequences of characters by adding a backslash in front of the letter W which behaves completely opposite of addslashes() function.
Code:
<?php $str = addcslashes(“Welcome Educba!”,”W”); echo($str);
Output:
Example #4This program represents the addcslashes() function for the representation of the string with an output of the generated string with escaped sequences of characters by adding a backslash in front of the letter educba for adding backslashes which behave completely opposite of addslashes() function.
Code:
<?php $str = “Thanks for revisiting the educba portal!”;
Output:
Example #5Code:
<?php $str = “Thanks for revisiting to our portal of educba!”; echo addcslashes($str,’a..g’);
Output:
Example #6This program represents the HTML special characters with the elements to translate the element’s value into one value using string.
Code:
<?php $str = “There are some good person.”; echo htmlspecialchars($str);
Output:
ConclusionThe addslashes function is used to represent and traverse the string by prefixing the backslash string in front of the entire special character string and is used to quote the necessary and important string to be used simultaneously.
Recommended ArticlesThis is a guide to PHP addslashes(). Here we discuss how addslashes() function works in PHP along with multiple examples and its code implementation. You may also have a look at the following articles to learn more –
How Reduce Function Works In Kotlin
Introduction to Kotlin reduce
Web development, programming languages, Software testing & others
SyntaxThe kotlin language has many default methods. Keywords and operators create the application deployment, and it’s faster compared to java type of applications. It’s a lightweight component that prevents the applications from increasing memory sizes.
fun main() { val vars -----some codes which depends on the requirement---- }The above codes are the basic syntax for the kotlin reduce() function used on the main method. We can import the packages based on the classes and methods which will use in the code. The reduce() function reduces the sizes and prints the values on the output console.
How does reduce Function Work in Kotlin?The kotlin language is cross-platform and a Java standard library, but the type is inference. The reduce() is one of the built-in functions that accumulates the values. It may be of any type, like an integer or number, strings starting with the index element, and it applies the code operation from left to the right set of values will be assigned for each set of elements. The values declared by the specific variable types will be array types; the value starts from the index 0.
Using the reduceIndexed() function also returns the array index; if the array is empty, it throws the exception and returns the null value if the array value is empty. The function parameter is a must for the function invoked and each subsequent data element on the group. The data is to be key-value pair formats like a map it associates with the key of each type of group with the formatted results of accumulating the group elements on the stack memory because the method performs the operation that is related to the memory areas for storing the complex values into the single set format values.
Examples of Kotlin reduceGiven below are the examples:
Example #1Code:
import kotlin.collections.* fun main() { val x = listOf(12,34,56,78,90,627, 54,56,65324,65,62145) println("Have a Nice Day users its the first example regarding the reduce() "+y) println("Thank you users for spenting the time please try again "+z) val ab = listOf("First", "Welcome", "To", "My","Domain") val ef = listOf("second", "Please", "Try", "Again","Have", "A", "Nice", "Day", "Users","123","456","789") }Output:
In the above example, we used some collection with the reduce() method to reduce the lines from left to right. Currently, the reduce() method converts the values like integer numbers into the single set of values stored on the variable.
Example #2Code:
import kotlin.collections.* try { val p = intArrayOf(11, 22, 33, 44, 55, 66, 77, 88, 99) println(p.sum()) var x = 0 p.forEach { x += it } println(x) val vars = 11/ 0 println(vars) } catch (ex: ArithmeticException) { println(ex) } finally { println("If above two blocks are not executing means the finally block will execute") } println("This is a Second Example") var w: String = "Welcome To My Domain its a Second Example for to use the reduce() method in Kotlin java library" println("Have a Nice Day users : $w") var u: String? = "Thank you for choosing our application Please try again" println("Its a Second variable $u") u = null println("If the variable is going to be null : $u") }Output:
Example #3Code:
package one val example1: Int = 33 val example2: Int = 53 val sum = example1 + example2 println("The sum is: $sum") val example3 = listOf("first", "second", "third", "four", "five", "six", "seven", "eight", "nine", "ten") val example4 = example3.groupingBy { it.first() } }) val example5 = example4.values.sortedBy { it.first } println(example5) val example6 = listOf("first", "second", "third", "four", "five", "six", "seven", "eight", "nine", "ten") val example7 = example3.groupingBy { it.first() } println(example7) val nums = listOf(44, 45, 43, 22, 11, 72, 61, 83, 94) mp.put(1, "siva") mp.put(2, "raman") mp.put(3, "welcome") mp.put(4, "users") mp.put(5, "have") mp.put(6, "a") mp.put(7, "nice") mp.put(8, "day") val akeys = ArrayList(mp.keys) val avalues = ArrayList(mp.values) println("Your input keys are : $akeys") println("Your input values are: $avalues") val y = listOf("four", "five", "six", "second", "first", "seven", "eight", "nine", "ten") println(res) }Output:
In the final example, we used the collection concepts like list and map and converted the map values to the list collection. Here we used to reduce() and reduceRight() methods for reducing the code lines from left to right and right to left.
ConclusionIn the kotlin language, we used some default methods, keywords, and variables, which regarding the separate packages, include classes and methods. For that, the reduce() and other similar methods are the default methods for reducing the datas into a single set in the collections, util, and other default packages, which depend on the user requirement.
Recommended ArticlesWe hope that this EDUCBA information on “Kotlin reduce” was beneficial to you. You can view EDUCBA’s recommended articles for more information.
How Does Isnan() Function Works In Javascript?
Introduction to isNaN() JavaScript
In this article, we will learn about isNaN() JavaScript. We will try to split the function isNaN() word by word and analyze the meaning of the function. is and NaN is both 2 separate words. NaN abbreviation is Not a Number. Now if we include any helping verb in front of any word, give a question right. Here also, isNaN means checks given value is a Number or Not. isNaN() checks whether the value passed to it is true or false.
Start Your Free Software Development Course
Web development, programming languages, Software testing & others
How does the isNaN() function work in JavaScript?
isNaN() function always checks whether the value is a Number or Not a Number.
isNaN() returns the Boolean value as output.
Returned Boolean values are true or false.
If the given value is a string, it returns true; if the given value is a number, it returns false.
isNaN(value);value: Pass the required value to check whether it is a number or not.
Example: There is a situation if we want to add or subtract numbers. Let’s suppose the numbers we are getting are from 3rd party clients. Are we directly add or subtract those values? No, because We don’t know what those values are, whether numbers or strings. So, we first check whether it is a number or not by using the isNaN() function. If the number is in string form, we simply par the number. Later we will add or subtract.
Examples to Implement in isNaN() JavaScriptBelow is the example of implementing in isNaN() JavaScript:
Example #1Checking whether passing Strings are numbers or not
Code:
function checkStringsNumberOrNot() { var a=”Amardeep”; var b=”123″; var c=’25/12/2023′; var d=”123Param”; var e=”Hi989″; var f=”*&^%”; var g=123+”Hello”; } checkStringsNumberOrNot();
Output:
Explanation of the above code: Amardeep is not a number, so the function returns true. 123 is a number, so the function returns false. 25/12/2023 is not a number but a date, so the function returns true. 123Param is not a number, so the function returns true. Hi989 is not a number, so the function returns true. 8&^% is not a number, so the function returns true. 123Hello is not a number, so the function returns true. (123+” String”=String so becomes 123Hello).
Example #2Checking whether passing integers are numbers or not
Code:
function checkIntegersNumberOrNot() { var a=”989″; var b=23; var c=-25; var d=-5.21; var e=’+28.67F’; var f=”87.23L”; var g=’0′; } checkIntegersNumberOrNot();
Explanation of the above code: 989 is a number, so the function returns false. 23 is a number, so the function returns false. -25 is a number, so the function returns false. -5.21 is a number, so the function returns false. +28.67F is not a number, so the function returns true. 23L is not a number, so the function returns true. 0 is a number, so the function returns
Note: Whereas in Java, suffixes F and L indicate float and long numbers, respectively, JavaScript doesn’t.
Example #3Checking whether passing predefined JavaScript values are numbers or not
Code:
function checkPredefinedValuesNumberOrNot() { var a=”true”; var b=”false”; var c=”undefined”; var d=”null”; var e=0/0; var f=NaN; var g=”NaN”; } checkPredefinedValuesNumberOrNot();
Output:
Explanation of the above code: true is not a number, so the function returns true. false is not a number, so the function returns true. Undefined is not a number, so the function returns true. null is not a number, so the function returns true. NaN(0/0) is not a number, so the function returns true. NaN without quotes is not a number, so the function returns true. NaN with quotes is not a number, so the function returns true.
Example #4Its checks passed value is NaN, and its type is number. It is an updated version of the isNaN() direct-using function. It also returns true or false based on the value provided to it.
Code:
function checkValuesNumberOrNot() { var a=10; var b=”false”; var c=0/0; var d=-21.7; var e=Number.NaN } checkValuesNumberOrNot();
Output:
Explanation of the above code: 10 is a number, so the function returns false. false is a number, so the function returns false. NaN (0/0) is not a number, so the function returns true. -21.7 is a number, so the function returns false. NaN (Number.NaN) is not a number, so the function returns true.
Note:
Number.isNaN() returns the false and true output as false only because it considers false as 0 and true as 1 here.
Function isNaN continuously checks whether the value inside the function is a number or not, whether in single quotes, double quotes, or no quotes.
ConclusionisNaN() function is used to figure out whether a given value is a number or not. If the given value is a number, then return false otherwise, return true.
Recommended ArticlesThis is a guide to isNaN() JavaScript. Here we discuss an introduction, how isNaN() JavaScript works, and examples to implement. You can also go through our other related articles to learn more –
How Save Function Works In Docker With Examples?
Introduction to Docker Save
The ‘docker save’ is used to save one or more than one image to a tar archive. It includes all parent layers, and all tags or versions. It is by default streamed to STDOUT, however, we can write to a file, instead of STDOUT by specifying a flag. This command is very useful when we have to use Docker images on different machines without using a registry or repository. We can also compress or save the image to a chúng tôi file using gzip.
Start Your Free Software Development Course
Web development, programming languages, Software testing & others
Syntax:
$docker save [OPTIONS] IMAGE [IMAGE…]
–output, -o: It is used to redirect the output to a file
–help, -h: It is used to get help about the command.
How save function works in Docker?As we know, it is used to save Docker images to an archive. When we run this command from the command line, the Docker daemon saves the mentioned Docker image as an archive. We can then share that archive with different teams or to different computers and so on. Now, we need to load that archive file, in order to use that image. When we load that archive file again, it creates a Docker image.
ExamplesLet’s understand the whole process with an example.
Scenario: We are going to save a Docker image and then will load it after deleting the existing image.
Step 1. Let’s check available Docker images locally using the below command:
docker image ls
Explanation: – In the above snapshot, we can see that there are two images available, let’s take the ‘ubuntu’ Docker image with the ‘latest’ tag. If the image is not available locally, pull it from the public registry that is chúng tôi using the below command:
docker pull ubuntu
Note: We can use any Docker images; it should be available locally.
Step 2. Now, we have a Docker image available locally let’s save it to an archive file as shown below:
ls my-ubuntu2.tar
Explanation: In the above snapshot, we can see that the ‘-o’ option has been used to save it to an archive and the name of the archive is ‘my-ubuntu.tar’. We can also use redirection instead of the ‘-o’ option to redirect the output to an archive file as shown below:
ls my-ubuntu2.tar
Step 3. Let’s verify by deleting exiting image and loading it from archive using below command:
docker image ls
Explanation: In the above snapshot, we have deleted the ‘ubuntu’ image that we have verified using the second command and then we have loaded the image using the archive file in which we have saved the image earlier. We have to use the ‘-i’ option to instruct the Docker daemon to load the image from an archive file instead of STDOUT. Finally, we have checked the locally available images to verify and we can see that the image is available again.
Scenario: Save multiple images at once.
Step 1. Let’s save two Docker images Ubuntu and nginx to an archive file as shown below:
docker save -o chúng tôi ubuntu nginx:alpine
Step 2. Let’s verify it as well using the same way we did earlier:
docker image ls
Explanation: As per the above example, we can understand that we can save multiple images in a single archive, so we load it again, it will load all the images that were saved using the ‘docker save’ command.
Scenario: Save Docker images to a chúng tôi file.
Solution: We can do it by using the gzip command. It compresses the tar and makes it smaller in size. We can run the below command to save the images to a chúng tôi file:
ll chúng tôi my-images2.tar.gz
Explanation: In the above snapshot, we can see that the ‘my-images2.tar.gz’ file is much smaller than the ‘my-images.tar’ file.
Advantages
We can archive the Docker images if not in use, for example, old builds are not required after a new build is released, however, we have to keep it for some time before removing it so better we can archive those images.
We can save a lot of disk space if we also compressing the archive using gzip.
ConclusionThe ‘docker save’ is a handy command to save the images only, it does not save changes made to the image by any running container using that image. We have one more command to save the images and that is ‘docker image save’. This command works similarly to the ‘docker save’ command.
Recommended ArticlesThis is a guide to Docker Save. Here we also discuss the introduction and How save function work in docker? along with different examples and its code implementation. You may also have a look at the following articles to learn more –
Update the detailed information about How Nullif Function Works In Postgresql? on the Minhminhbmm.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!