2

The Postgres docs state:

While the standard syntax for specifying string constants is usually convenient, it can be difficult to understand when the desired string contains many single quotes or backslashes, since each of those must be doubled.

I understand how single quotes are doubled, since that is how they are escaped according to section 4.1.2.1 on string constants. But if backslashes were doubled, then surely this wouldn't be possible:

janus=> \d todo
                            Table "public.todo"
 Column |  Type   | Collation | Nullable |             Default              
--------+---------+-----------+----------+----------------------------------
 id     | integer |           | not null | nextval('todo_id_seq'::regclass)
 descr  | text    |           |          | 
 done   | boolean |           |          | 

janus=> truncate table todo;
TRUNCATE TABLE
janus=> insert into todo (descr,done) values ('\''', false);
INSERT 0 1
janus=> select length(descr), descr from todo;
 length | descr 
--------+-------
      2 | \'
(1 row)

As you can see, the backslash before the two single quotes (that are interpreted as one single quote), has no effect, and it is inserted literally. So how is the "standard" syntax referenced in the quote interacting with backslashes? There does not seem to be any special treatment of them, they are like any other character.

0

1 Answer 1

4

The documentation you quote is a leftover from before version 9.1, when standard_conforming_strings was off by default. Ever since 9.1, this has been obsolete, and I have proposed a patch to remove it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.