![]() We see the null value in the excerpt column. Posts Code language: SQL (Structured Query Language) ( sql ) We can simply use the following query to get all rows in the posts table. In case the excerpt is not provided, we use the first 40 characters of the post body. Third, our goal is to display the posts overview page that shows title and excerpt of each posts. ( 'test post 3', null, 'test post body 3') Code language: SQL (Structured Query Language) ( sql ) ( 'test post 2', '', 'test post body 2'), ( 'test post 1', 'test post excerpt 1', 'test post body 1'), Second, we insert some sample data into the posts table. ) Code language: SQL (Structured Query Language) ( sql ) Let’s take a look at an example of using the NULLIF function.įirst, we create a table named posts as follows: CREATE TABLE posts (Ĭreated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, See the following examples: SELECT NULLIF ( 1, 1) - return NULL SELECT NULLIF ( 1, 0) - return 1 SELECT NULLIF ( 'A', 'B') - return A Code language: SQL (Structured Query Language) ( sql ) PostgreSQL NULLIF function example The NULLIF function returns a null value if argument_1 equals to argument_2, otherwise it returns argument_1. The following illustrates the syntax of the NULLIF function: NULLIF(argument_1,argument_2) Code language: SQL (Structured Query Language) ( sql ) ![]() The NULLIF function is one of the most common conditional expressions provided by PostgreSQL. We will show you some examples of using the NULLIF function. Summary: this tutorial shows you how to use PostgreSQL NULLIF function to handle null values.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |