The syntax of PostgreSQL LIKE operator is as follows: value LIKE pattern Code language: SQL (Structured Query Language) ( sql ) Underscore sign ( _) matches any single character.Percent sign ( %) matches any sequence of zero or more characters.PostgreSQL provides you with two wildcards: You construct a pattern by combining literal values with wildcard characters and use the LIKE or NOT LIKE operator to find the matches. This technique is called pattern matching. The query returns rows whose values in the first_name column begin with Jen and may be followed by any sequence of characters. Notice that the WHERE clause contains a special expression: the first_name, the LIKE operator and a string that contains a percent sign (%). However, this process can be time-consuming if the customer table has a large number of rows.įortunately, you can use the PostgreSQL LIKE operator to match the first name of the customer with a string using the following query: SELECTįirst_name LIKE 'Jen%' Code language: SQL (Structured Query Language) ( sql ) How do you find the exact customer from the database? You may find the customer in the customer table by looking at the first name column to see if there is any value that begins with Jen. However, you can recall that her name begins with something like Jen. Suppose that you want to find a customer, but you don’t remember her name exactly. Summary: in this tutorial, you will learn how to use the PostgreSQL LIKE and ILIKE operators to query data using pattern matchings.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |