diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2008-03-23 00:24:20 +0000 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2008-03-23 00:24:20 +0000 |
commit | 7de81124d52422a513725af7f40446613e6bdda8 (patch) | |
tree | 2716cf33b99552a4ca76bc97e010c7654ca15fe7 /src/backend/utils/adt/quote.c | |
parent | 40a3dfb7e354787bc5da6bf0b62b5f11b1a86efb (diff) |
Create a function quote_nullable(), which works the same as quote_literal()
except that it returns the string 'NULL', rather than a SQL null, when called
with a null argument. This is often a much more useful behavior for
constructing dynamic queries. Add more discussion to the documentation
about how to use these functions.
Brendan Jurd
Diffstat (limited to 'src/backend/utils/adt/quote.c')
-rw-r--r-- | src/backend/utils/adt/quote.c | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/src/backend/utils/adt/quote.c b/src/backend/utils/adt/quote.c index ad9335d7b3c..519c6d874b5 100644 --- a/src/backend/utils/adt/quote.c +++ b/src/backend/utils/adt/quote.c @@ -7,7 +7,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/utils/adt/quote.c,v 1.23 2008/01/01 19:45:52 momjian Exp $ + * $PostgreSQL: pgsql/src/backend/utils/adt/quote.c,v 1.24 2008/03/23 00:24:19 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -96,3 +96,19 @@ quote_literal(PG_FUNCTION_ARGS) PG_RETURN_TEXT_P(result); } + +/* + * quote_nullable - + * Returns a properly quoted literal, with null values returned + * as the text string 'NULL'. + */ +Datum +quote_nullable(PG_FUNCTION_ARGS) +{ + if (PG_ARGISNULL(0)) + PG_RETURN_DATUM(DirectFunctionCall1(textin, + CStringGetDatum("NULL"))); + else + PG_RETURN_DATUM(DirectFunctionCall1(quote_literal, + PG_GETARG_DATUM(0))); +} |