summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlvaro Herrera2008-11-10 16:25:41 +0000
committerAlvaro Herrera2008-11-10 16:25:41 +0000
commitcc86aaa0a8c6ed39a5b0cc1da1245d6f126f9a4d (patch)
tree3ebf966aff0acbecdf9325c8755940469a4b3c89
parent3956d053f7d92009a7186ac144762a5b2e7b8f6c (diff)
Add a --locale switch to createdb, to ease the creation of databases with
different locales. This is just syntactical sweetener over --lc-collate and --lc-ctype. Per discussion. While at it, properly document --lc-ctype and --lc-collate in SGML docs, which apparently were forgotten (or purposefully ommited?) when they were created.
-rw-r--r--doc/src/sgml/ref/createdb.sgml31
-rw-r--r--src/bin/scripts/createdb.c26
2 files changed, 55 insertions, 2 deletions
diff --git a/doc/src/sgml/ref/createdb.sgml b/doc/src/sgml/ref/createdb.sgml
index 97c38ed4b8..0fc66560a8 100644
--- a/doc/src/sgml/ref/createdb.sgml
+++ b/doc/src/sgml/ref/createdb.sgml
@@ -107,6 +107,35 @@ PostgreSQL documentation
</varlistentry>
<varlistentry>
+ <term><option>-l <replaceable class="parameter">locale</replaceable></></term>
+ <term><option>--locale <replaceable class="parameter">locale</replaceable></></term>
+ <listitem>
+ <para>
+ Specifies the locale to be used in this database. This is equivalent
+ to specifying both <option>--lc-collate</option> and <option>--lc-ctype</option>.
+ </para>
+ </listitem>
+ </varlistentry>
+
+ <varlistentry>
+ <term><option>--lc-collate <replaceable class="parameter">locale</replaceable></></term>
+ <listitem>
+ <para>
+ Specifies the LC_COLLATE setting to be used in this database.
+ </para>
+ </listitem>
+ </varlistentry>
+
+ <varlistentry>
+ <term><option>--lc-ctype <replaceable class="parameter">locale</replaceable></></term>
+ <listitem>
+ <para>
+ Specifies the LC_CTYPE setting to be used in this database.
+ </para>
+ </listitem>
+ </varlistentry>
+
+ <varlistentry>
<term><option>-E <replaceable class="parameter">encoding</replaceable></></term>
<term><option>--encoding <replaceable class="parameter">encoding</replaceable></></term>
<listitem>
@@ -142,7 +171,7 @@ PostgreSQL documentation
</para>
<para>
- The options <option>-D</option>, <option>-E</option>,
+ The options <option>-D</option>, <option>-E</option>, <option>-l</option>,
<option>-O</option>, and
<option>-T</option> correspond to options of the underlying
SQL command <xref linkend="SQL-CREATEDATABASE"
diff --git a/src/bin/scripts/createdb.c b/src/bin/scripts/createdb.c
index 543a83fdeb..369f87a611 100644
--- a/src/bin/scripts/createdb.c
+++ b/src/bin/scripts/createdb.c
@@ -34,6 +34,7 @@ main(int argc, char *argv[])
{"encoding", required_argument, NULL, 'E'},
{"lc-collate", required_argument, NULL, 1},
{"lc-ctype", required_argument, NULL, 2},
+ {"locale", required_argument, NULL, 'l'},
{NULL, 0, NULL, 0}
};
@@ -54,6 +55,7 @@ main(int argc, char *argv[])
char *encoding = NULL;
char *lc_collate = NULL;
char *lc_ctype = NULL;
+ char *locale = NULL;
PQExpBufferData sql;
@@ -65,7 +67,7 @@ main(int argc, char *argv[])
handle_help_version_opts(argc, argv, "createdb", help);
- while ((c = getopt_long(argc, argv, "h:p:U:WeqO:D:T:E:", long_options, &optindex)) != -1)
+ while ((c = getopt_long(argc, argv, "h:p:U:WeqO:D:T:E:l:", long_options, &optindex)) != -1)
{
switch (c)
{
@@ -105,6 +107,9 @@ main(int argc, char *argv[])
case 2:
lc_ctype = optarg;
break;
+ case 'l':
+ locale = optarg;
+ break;
default:
fprintf(stderr, _("Try \"%s --help\" for more information.\n"), progname);
exit(1);
@@ -129,6 +134,24 @@ main(int argc, char *argv[])
exit(1);
}
+ if (locale)
+ {
+ if (lc_ctype)
+ {
+ fprintf(stderr, _("%s: only one of --locale and --lc-ctype can be specified\n"),
+ progname);
+ exit(1);
+ }
+ if (lc_collate)
+ {
+ fprintf(stderr, _("%s: only one of --locale and --lc-collate can be specified\n"),
+ progname);
+ exit(1);
+ }
+ lc_ctype = locale;
+ lc_collate = locale;
+ }
+
if (encoding)
{
if (pg_char_to_encoding(encoding) < 0)
@@ -224,6 +247,7 @@ help(const char *progname)
printf(_("\nOptions:\n"));
printf(_(" -D, --tablespace=TABLESPACE default tablespace for the database\n"));
printf(_(" -E, --encoding=ENCODING encoding for the database\n"));
+ printf(_(" -l, --locale=LOCALE locale settings for the database\n"));
printf(_(" --lc-collate=LOCALE LC_COLLATE setting for the database\n"));
printf(_(" --lc-ctype=LOCALE LC_CTYPE setting for the database\n"));
printf(_(" -O, --owner=OWNER database user to own the new database\n"));