I had some spare cycles so I went ahead and patched this.
Patch includes documentation and new regression tests. While I was in
there I also added regression tests for quote_ident(), which appeared
to be absent.
quote_literal doesn't seem to have any regression tests either, but I
decided to leave that for another patch.
With thanks to Neil Conway for his assistance on IRC.
Cheers
BJ
On 9/15/07, Bruce Momjian [EMAIL PROTECTED] wrote:
This has been saved for the 8.4 release:
Brendan Jurd wrote:
Hi hackers,
I note that we currently expose the usefulness of the quote_identifier
function to the user with quote_ident(text).
Is there any reason we shouldn't do the same with
quote_qualified_identifier?
We could just add a quote_qualified_ident(text, text) ... it would
make forming dynamic queries more convenient in databases that use
multiple schemas.
Clearly a DBA could just create this function himself in SQL (and it
wouldn't be difficult), but is that a good reason not to have it in
our standard set of functions?
Would be happy to cook up a patch for this.
Cheers,
BJ
---(end of broadcast)---
TIP 9: In versions below 8.0, the planner will ignore your desire to
choose an index scan if your joining column's datatypes do not
match
--
Bruce Momjian [EMAIL PROTECTED] http://momjian.us
EnterpriseDB http://www.enterprisedb.com
+ If your life is a hard drive, Christ can be your backup. +
Index: doc/src/sgml/func.sgml
===
RCS file: /projects/cvsroot/pgsql/doc/src/sgml/func.sgml,v
retrieving revision 1.397
diff -c -r1.397 func.sgml
*** doc/src/sgml/func.sgml 19 Sep 2007 03:13:57 - 1.397
--- doc/src/sgml/func.sgml 22 Sep 2007 03:07:26 -
***
*** 1276,1281
--- 1276,1284
primaryquote_ident/primary
/indexterm
indexterm
+ primaryquote_qualified_ident/primary
+/indexterm
+indexterm
primaryquote_literal/primary
/indexterm
indexterm
***
*** 1541,1546
--- 1544,1563
/row
row
+
entryliteralfunctionquote_qualified_ident/function(parameterschema/parameter
typetext/type, parameteridentifier/parameter
typetext/type)/literal/entry
+entrytypetext/type/entry
+entry
+ Return the given schema and identifier suitably quoted to be
used as a
+ fully qualified identifier in an acronymSQL/acronym
statement
+ string. Quoting is performed as for
functionquote_ident/function,
+ but parameterschema/parameter and
parameteridentifier/parameter
+ are quoted separately.
+/entry
+entryliteralquote_ident('Some schema','A table')/literal/entry
+entryliteralSome schema.A table/literal/entry
+ /row
+
+ row
entryliteralfunctionquote_literal/function(parameterstring/parameter)/literal/entry
entrytypetext/type/entry
entry
Index: src/backend/utils/adt/quote.c
===
RCS file: /projects/cvsroot/pgsql/src/backend/utils/adt/quote.c,v
retrieving revision 1.22
diff -c -r1.22 quote.c
*** src/backend/utils/adt/quote.c 27 Feb 2007 23:48:08 - 1.22
--- src/backend/utils/adt/quote.c 22 Sep 2007 03:07:26 -
***
*** 46,51
--- 46,77
}
/*
+ * quote_qualified_ident -
+ *returns a properly quoted, schema-qualified identifier
+ */
+ Datum
+ quote_qualified_ident(PG_FUNCTION_ARGS)
+ {
+ text*schema = PG_GETARG_TEXT_P(0);
+ text*ident = PG_GETARG_TEXT_P(1);
+ text*result;
+ const char *quoted;
+ char*schema_s;
+ char*ident_s;
+
+ schema_s = DatumGetCString(DirectFunctionCall1(textout,
+
PointerGetDatum(schema)));
+ ident_s = DatumGetCString(DirectFunctionCall1(textout,
+
PointerGetDatum(ident)));
+
+ quoted = quote_qualified_identifier(schema_s, ident_s);
+
+ result = DatumGetTextP(DirectFunctionCall1(textin,
+
CStringGetDatum(quoted)));
+ PG_RETURN_TEXT_P(result);
+ }
+
+ /*
* quote_literal -
* returns a properly quoted literal
*
Index: src/include/catalog/pg_proc.h
===
RCS file: /projects/cvsroot/pgsql/src/include/catalog/pg_proc.h,v
retrieving revision 1.471
diff -c -r1.471 pg_proc.h
*** src/include/catalog/pg_proc.h 20 Sep 2007 17:56:32