Skip to content

Commit 7df86d4

Browse files
committed
quotes
1 parent 59e491f commit 7df86d4

File tree

1 file changed

+62
-1
lines changed

1 file changed

+62
-1
lines changed
Lines changed: 62 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,63 @@
11
CREATE USER MAPPING FOR local_user SERVER "foreign_server" OPTIONS (user 'remote_user', password 'secret123');
2-
CREATE USER MAPPING FOR local_user SERVER foreign_server OPTIONS (user 'remote_user', password 'secret123');
2+
CREATE USER MAPPING FOR local_user SERVER foreign_server OPTIONS (user 'remote_user', password 'secret123');
3+
4+
-- This file contains examples of SQL string literals requiring E-prefixed strings
5+
6+
-- Basic string with newline
7+
SELECT E'Line 1\nLine 2';
8+
9+
-- Tab character and single quote
10+
SELECT E'Column\tValue with quote: \'' AS formatted_string';
11+
12+
-- Escaped backslash and carriage return
13+
SELECT E'Path is C:\\Program Files\\PostgreSQL\r\nDone.';
14+
15+
-- Unicode escapes
16+
SELECT E'Unicode heart: \u2764' AS unicode_heart;
17+
SELECT E'Extended Unicode: \U0001F680' AS rocket_emoji;
18+
19+
-- Octal escape
20+
SELECT E'Bell sound: \007' AS octal_escape;
21+
22+
-- Hex-looking string that is NOT bytea
23+
-- This needs E because it has \x but also other escapes
24+
SELECT E'This is not a bytea literal: \\xDEAD and a newline \n';
25+
26+
-- Proper bytea hex string (should NOT need E prefix)
27+
SELECT '\\xDEADBEEF'::bytea;
28+
29+
-- A_Const-style literal in INSERT
30+
INSERT INTO messages (content) VALUES (
31+
E'Line one.\nLine two with tab:\tEnd.'
32+
);
33+
34+
-- Another INSERT with a tricky string in a comment
35+
-- Comment: escaped quote and newline: \n and \'
36+
INSERT INTO logs (message) VALUES (
37+
E'Escaped comment info: \nAuthor said: \'yes\''
38+
);
39+
40+
-- String that would cause parsing issues without E
41+
SELECT E'Invalid path: C:\\Users\\Me\\Documents';
42+
43+
-- Control character (form feed)
44+
SELECT E'Page break here:\fNext page';
45+
46+
-- JSON-like string that *requires* E because of escaped quotes
47+
INSERT INTO configs (data) VALUES (
48+
E'{\"theme\": \"dark\", \"alert\": \"bell\\nchime\"}'
49+
);
50+
51+
-- Nested comment trick: using E-string inside a comment-containing SQL
52+
-- This shows a string literal *inside* a SQL statement that also includes a SQL comment
53+
INSERT INTO docs (note) VALUES (
54+
E'This value includes a SQL-style comment -- tricky!\nBut it''s safe here.'
55+
);
56+
57+
-- Example where normal string is okay (no E needed)
58+
SELECT E'Just a plain string, nothing to escape.';
59+
SELECT 'Just a plain string, nothing to escape.';
60+
61+
-- Just to make sure we're parsing string types correctly
62+
-- sval.String.str with embedded backslashes and quotes
63+
SELECT E'This string has \"quotes\" and \\slashes\\' AS tricky_string;

0 commit comments

Comments
 (0)