

Between the $tag$, you can place any string with single quotes (‘) and backslashes (\). The following shows the syntax of the dollar-quoted string constants: Syntax: $tag$$tag$ PostgreSQL version 8.0 introduced the dollar quoting feature to make string constants more readable. Doubling every single quote and backslash makes the string constant more difficult to read and maintain.

The problem arises when the string constant contains many single quotes and backslashes. If a string constant contains a backslash, you need to escape it by using another backslash. If you use an old version of PostgreSQL, one can prepend the string constant with E to declare the postfix escape string syntax and use the backslash \ to escape the single quote like this: select E'I\'m also a string constant' For example: select 'I''m also a string constant' When a string constant contains a single quote (‘ ), you need to escape it by doubling up the single quote. In PostgreSQL, you use single quotes for a string constant like this: select 'String constant' ISRO CS Syllabus for Scientist/Engineer Exam.ISRO CS Original Papers and Official Keys.GATE CS Original Papers and Official Keys.
Postgresql substring how to#
Here we discuss how to use PostgreSQL POSITION() function along with the examples. This is a guide to PostgreSQL POSITION(). Also, we have added several examples of the POSITION() function to understand it in detail. We hope from the above article you have understood how to use this function and how the POSITION() function works.

SELECT POSITION('awesome' IN 'PostgreSQL is awesome') ģ. Consider the string ‘PostgreSQL is awesome’ from which we will find out the position of the ‘awesome’ by using the PostgreSQL POSITION function. SELECT category_id, category_name, POSITION('n' IN "category_name") FROM category Ģ. Consider the following statement which finds the position of the substring ‘n’ in the column ‘category_name’. Illustrate the result of the above statement by using the following snapshot and SQL statement.ġ. INSERT INTO category(category_name)values Now, we will insert some data in the ‘category’ table by using the INSERT TABLE statement: We will create tables named ‘category’ in order to understand the examples of this function in detail.Ĭonsider the following CREATE TABLE statement in order to create the category table.
