November 2019
Beginner to intermediate
470 pages
11h 59m
English
Passing code to PostgreSQL as a string is very flexible. However, using single quotes can be an issue. In many programming languages, single quotes show up frequently. To be able to use these quotes, people have to escape them when passing the string to PostgreSQL. For many years, this has been the standard procedure. Fortunately, those old times have passed by, and new means of passing the code to PostgreSQL are available. One of these is dollar quoting, as shown in the following code:
test=# CREATE OR REPLACE FUNCTION mysum(int, int)
RETURNS int AS
$$
SELECT $1 + $2;
$$ LANGUAGE 'sql';
CREATE FUNCTION
Instead of using quotes to start and end strings, you can simply use $$. Currently, there are two languages that ...