Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
Postgres FD Implementation
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Abuhujair Javed
Postgres FD Implementation
Commits
c3c39026
Commit
c3c39026
authored
May 31, 2006
by
Bruce Momjian
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Support '' for literal ' in psql single-quote strings, documentation update.
parent
eaca1175
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
9 additions
and
6 deletions
+9
-6
doc/src/sgml/ref/psql-ref.sgml
doc/src/sgml/ref/psql-ref.sgml
+5
-5
src/bin/psql/psqlscan.l
src/bin/psql/psqlscan.l
+4
-1
No files found.
doc/src/sgml/ref/psql-ref.sgml
View file @
c3c39026
<!--
$PostgreSQL: pgsql/doc/src/sgml/ref/psql-ref.sgml,v 1.16
2 2006/05/26 19:51:29 tgl
Exp $
$PostgreSQL: pgsql/doc/src/sgml/ref/psql-ref.sgml,v 1.16
3 2006/05/31 11:35:17 momjian
Exp $
PostgreSQL documentation
-->
...
...
@@ -2262,7 +2262,7 @@ testdb=> <userinput>SELECT * FROM :foo;</userinput>
copy the contents of a file into a table column. First load the file into a
variable and then proceed as above.
<programlisting>
testdb=> <userinput>\set content '
\'' `cat my_file.txt` '\
''</userinput>
testdb=> <userinput>\set content '
''' `cat my_file.txt` ''
''</userinput>
testdb=> <userinput>INSERT INTO my_table VALUES (:content);</userinput>
</programlisting>
One possible problem with this approach is that <filename>my_file.txt</filename>
...
...
@@ -2270,14 +2270,14 @@ testdb=> <userinput>INSERT INTO my_table VALUES (:content);</userinput>
they don't cause a syntax error when the second line is processed. This
could be done with the program <command>sed</command>:
<programlisting>
testdb=> <userinput>\set content '
\'' `sed -e "s/'/\\\\\\'/g" < my_file.txt` '\
''</userinput>
testdb=> <userinput>\set content '
''' `sed -e "s/'/\\\\''/g" < my_file.txt` ''
''</userinput>
</programlisting>
Observe the correct number of backslashes (6)! It works
this way: After <application>psql</application> has parsed this
line, it passes <literal>sed -e "s/'/\\
\
'/g" < my_file.txt</literal>
line, it passes <literal>sed -e "s/'/\\
'
'/g" < my_file.txt</literal>
to the shell. The shell will do its own thing inside the double
quotes and execute <command>sed</command> with the arguments
<literal>-e</literal> and <literal>s/'/
\\
'/g</literal>. When
<literal>-e</literal> and <literal>s/'/
'
'/g</literal>. When
<command>sed</command> parses this it will replace the two
backslashes with a single one and then do the substitution. Perhaps
at one point you thought it was great that all Unix commands use the
...
...
src/bin/psql/psqlscan.l
View file @
c3c39026
...
...
@@ -33,7 +33,7 @@
* Portions Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
* $PostgreSQL: pgsql/src/bin/psql/psqlscan.l,v 1.1
8 2006/05/11 19:15:35 tgl
Exp $
* $PostgreSQL: pgsql/src/bin/psql/psqlscan.l,v 1.1
9 2006/05/31 11:35:17 momjian
Exp $
*
*-------------------------------------------------------------------------
*/
...
...
@@ -861,6 +861,9 @@ other .
{quote} { return LEXRES_OK; }
/* We don't need a state here because we are already in a string */
{xqdouble} { emit("'", 1); }
"\\n" { appendPQExpBufferChar(output_buf, '\n'); }
"\\t" { appendPQExpBufferChar(output_buf, '\t'); }
"\\b" { appendPQExpBufferChar(output_buf, '\b'); }
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment