Skip to content

Commit 3f89964

Browse files
committed
Add quote_literal(anyelement) to preserve (and, in fact, extend) a
useful consequence of the former liberal implicit casting to text; namely that you can feed non-string values to quote_literal() and get unsurprising results. Per discussion.
1 parent 66d7bbf commit 3f89964

File tree

3 files changed

+19
-6
lines changed

3 files changed

+19
-6
lines changed

doc/src/sgml/func.sgml

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<!-- $PostgreSQL: pgsql/doc/src/sgml/func.sgml,v 1.411 2007/11/08 13:13:28 petere Exp $ -->
1+
<!-- $PostgreSQL: pgsql/doc/src/sgml/func.sgml,v 1.412 2007/11/27 18:29:11 tgl Exp $ -->
22

33
<chapter id="functions">
44
<title>Functions and Operators</title>
@@ -1514,7 +1514,7 @@
15141514
</row>
15151515

15161516
<row>
1517-
<entry><literal><function>quote_ident</function>(<parameter>string</parameter>)</literal></entry>
1517+
<entry><literal><function>quote_ident</function>(<parameter>string</parameter> <type>text</type>)</literal></entry>
15181518
<entry><type>text</type></entry>
15191519
<entry>
15201520
Return the given string suitably quoted to be used as an identifier
@@ -1528,7 +1528,7 @@
15281528
</row>
15291529

15301530
<row>
1531-
<entry><literal><function>quote_literal</function>(<parameter>string</parameter>)</literal></entry>
1531+
<entry><literal><function>quote_literal</function>(<parameter>string</parameter> <type>text</type>)</literal></entry>
15321532
<entry><type>text</type></entry>
15331533
<entry>
15341534
Return the given string suitably quoted to be used as a string literal
@@ -1539,6 +1539,17 @@
15391539
<entry><literal>'O''Reilly'</literal></entry>
15401540
</row>
15411541

1542+
<row>
1543+
<entry><literal><function>quote_literal</function>(<parameter>value</parameter> <type>anyelement</type>)</literal></entry>
1544+
<entry><type>text</type></entry>
1545+
<entry>
1546+
Coerce the given value to text and then quote it as a literal.
1547+
Embedded single-quotes and backslashes are properly doubled.
1548+
</entry>
1549+
<entry><literal>quote_literal(42.5)</literal></entry>
1550+
<entry><literal>'42.5'</literal></entry>
1551+
</row>
1552+
15421553
<row>
15431554
<entry><literal><function>regexp_matches</function>(<parameter>string</parameter> <type>text</type>, <parameter>pattern</parameter> <type>text</type> [, <parameter>flags</parameter> <type>text</type>])</literal></entry>
15441555
<entry><type>setof text[]</type></entry>

src/include/catalog/catversion.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
* Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group
3838
* Portions Copyright (c) 1994, Regents of the University of California
3939
*
40-
* $PostgreSQL: pgsql/src/include/catalog/catversion.h,v 1.438 2007/11/27 12:21:05 petere Exp $
40+
* $PostgreSQL: pgsql/src/include/catalog/catversion.h,v 1.439 2007/11/27 18:29:11 tgl Exp $
4141
*
4242
*-------------------------------------------------------------------------
4343
*/
@@ -53,6 +53,6 @@
5353
*/
5454

5555
/* yyyymmddN */
56-
#define CATALOG_VERSION_NO 200711271
56+
#define CATALOG_VERSION_NO 200711272
5757

5858
#endif

src/include/catalog/pg_proc.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
10-
* $PostgreSQL: pgsql/src/include/catalog/pg_proc.h,v 1.479 2007/11/27 12:21:05 petere Exp $
10+
* $PostgreSQL: pgsql/src/include/catalog/pg_proc.h,v 1.480 2007/11/27 18:29:11 tgl Exp $
1111
*
1212
* NOTES
1313
* The script catalog/genbki.sh reads this file and generates .bki
@@ -2631,6 +2631,8 @@ DATA(insert OID = 1282 ( quote_ident PGNSP PGUID 12 1 0 f f t f i 1 25 "25"
26312631
DESCR("quote an identifier for usage in a querystring");
26322632
DATA(insert OID = 1283 ( quote_literal PGNSP PGUID 12 1 0 f f t f i 1 25 "25" _null_ _null_ _null_ quote_literal - _null_ _null_ ));
26332633
DESCR("quote a literal for usage in a querystring");
2634+
DATA(insert OID = 1285 ( quote_literal PGNSP PGUID 14 1 0 f f t f v 1 25 "2283" _null_ _null_ _null_ "select pg_catalog.quote_literal($1::pg_catalog.text)" - _null_ _null_ ));
2635+
DESCR("quote a data value for usage in a querystring");
26342636

26352637
DATA(insert OID = 1798 ( oidin PGNSP PGUID 12 1 0 f f t f i 1 26 "2275" _null_ _null_ _null_ oidin - _null_ _null_ ));
26362638
DESCR("I/O");

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy