PostgreSQL Source Code  git master
collationcmds.c
Go to the documentation of this file.
1 /*-------------------------------------------------------------------------
2  *
3  * collationcmds.c
4  * collation-related commands support code
5  *
6  * Portions Copyright (c) 1996-2021, PostgreSQL Global Development Group
7  * Portions Copyright (c) 1994, Regents of the University of California
8  *
9  *
10  * IDENTIFICATION
11  * src/backend/commands/collationcmds.c
12  *
13  *-------------------------------------------------------------------------
14  */
15 #include "postgres.h"
16 
17 #include "access/htup_details.h"
18 #include "access/table.h"
19 #include "access/xact.h"
20 #include "catalog/dependency.h"
21 #include "catalog/indexing.h"
22 #include "catalog/namespace.h"
23 #include "catalog/objectaccess.h"
24 #include "catalog/pg_collation.h"
25 #include "commands/alter.h"
26 #include "commands/collationcmds.h"
27 #include "commands/comment.h"
28 #include "commands/dbcommands.h"
29 #include "commands/defrem.h"
30 #include "common/string.h"
31 #include "mb/pg_wchar.h"
32 #include "miscadmin.h"
33 #include "utils/acl.h"
34 #include "utils/builtins.h"
35 #include "utils/lsyscache.h"
36 #include "utils/pg_locale.h"
37 #include "utils/rel.h"
38 #include "utils/syscache.h"
39 
40 
41 typedef struct
42 {
43  char *localename; /* name of locale, as per "locale -a" */
44  char *alias; /* shortened alias for same */
45  int enc; /* encoding */
47 
48 
49 /*
50  * CREATE COLLATION
51  */
53 DefineCollation(ParseState *pstate, List *names, List *parameters, bool if_not_exists)
54 {
55  char *collName;
56  Oid collNamespace;
57  AclResult aclresult;
58  ListCell *pl;
59  DefElem *fromEl = NULL;
60  DefElem *localeEl = NULL;
61  DefElem *lccollateEl = NULL;
62  DefElem *lcctypeEl = NULL;
63  DefElem *providerEl = NULL;
64  DefElem *deterministicEl = NULL;
65  DefElem *versionEl = NULL;
66  char *collcollate = NULL;
67  char *collctype = NULL;
68  char *collproviderstr = NULL;
69  bool collisdeterministic = true;
70  int collencoding = 0;
71  char collprovider = 0;
72  char *collversion = NULL;
73  Oid newoid;
74  ObjectAddress address;
75 
76  collNamespace = QualifiedNameGetCreationNamespace(names, &collName);
77 
78  aclresult = pg_namespace_aclcheck(collNamespace, GetUserId(), ACL_CREATE);
79  if (aclresult != ACLCHECK_OK)
80  aclcheck_error(aclresult, OBJECT_SCHEMA,
81  get_namespace_name(collNamespace));
82 
83  foreach(pl, parameters)
84  {
85  DefElem *defel = lfirst_node(DefElem, pl);
86  DefElem **defelp;
87 
88  if (strcmp(defel->defname, "from") == 0)
89  defelp = &fromEl;
90  else if (strcmp(defel->defname, "locale") == 0)
91  defelp = &localeEl;
92  else if (strcmp(defel->defname, "lc_collate") == 0)
93  defelp = &lccollateEl;
94  else if (strcmp(defel->defname, "lc_ctype") == 0)
95  defelp = &lcctypeEl;
96  else if (strcmp(defel->defname, "provider") == 0)
97  defelp = &providerEl;
98  else if (strcmp(defel->defname, "deterministic") == 0)
99  defelp = &deterministicEl;
100  else if (strcmp(defel->defname, "version") == 0)
101  defelp = &versionEl;
102  else
103  {
104  ereport(ERROR,
105  (errcode(ERRCODE_SYNTAX_ERROR),
106  errmsg("collation attribute \"%s\" not recognized",
107  defel->defname),
108  parser_errposition(pstate, defel->location)));
109  break;
110  }
111  if (*defelp != NULL)
112  errorConflictingDefElem(defel, pstate);
113  *defelp = defel;
114  }
115 
116  if (localeEl && (lccollateEl || lcctypeEl))
117  ereport(ERROR,
118  errcode(ERRCODE_SYNTAX_ERROR),
119  errmsg("conflicting or redundant options"),
120  errdetail("LOCALE cannot be specified together with LC_COLLATE or LC_CTYPE."));
121 
122  if (fromEl && list_length(parameters) != 1)
123  ereport(ERROR,
124  errcode(ERRCODE_SYNTAX_ERROR),
125  errmsg("conflicting or redundant options"),
126  errdetail("FROM cannot be specified together with any other options."));
127 
128  if (fromEl)
129  {
130  Oid collid;
131  HeapTuple tp;
132 
133  collid = get_collation_oid(defGetQualifiedName(fromEl), false);
135  if (!HeapTupleIsValid(tp))
136  elog(ERROR, "cache lookup failed for collation %u", collid);
137 
138  collcollate = pstrdup(NameStr(((Form_pg_collation) GETSTRUCT(tp))->collcollate));
139  collctype = pstrdup(NameStr(((Form_pg_collation) GETSTRUCT(tp))->collctype));
140  collprovider = ((Form_pg_collation) GETSTRUCT(tp))->collprovider;
141  collisdeterministic = ((Form_pg_collation) GETSTRUCT(tp))->collisdeterministic;
142  collencoding = ((Form_pg_collation) GETSTRUCT(tp))->collencoding;
143 
144  ReleaseSysCache(tp);
145 
146  /*
147  * Copying the "default" collation is not allowed because most code
148  * checks for DEFAULT_COLLATION_OID instead of COLLPROVIDER_DEFAULT,
149  * and so having a second collation with COLLPROVIDER_DEFAULT would
150  * not work and potentially confuse or crash some code. This could be
151  * fixed with some legwork.
152  */
153  if (collprovider == COLLPROVIDER_DEFAULT)
154  ereport(ERROR,
155  (errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
156  errmsg("collation \"default\" cannot be copied")));
157  }
158 
159  if (localeEl)
160  {
161  collcollate = defGetString(localeEl);
162  collctype = defGetString(localeEl);
163  }
164 
165  if (lccollateEl)
166  collcollate = defGetString(lccollateEl);
167 
168  if (lcctypeEl)
169  collctype = defGetString(lcctypeEl);
170 
171  if (providerEl)
172  collproviderstr = defGetString(providerEl);
173 
174  if (deterministicEl)
175  collisdeterministic = defGetBoolean(deterministicEl);
176 
177  if (versionEl)
178  collversion = defGetString(versionEl);
179 
180  if (collproviderstr)
181  {
182  if (pg_strcasecmp(collproviderstr, "icu") == 0)
183  collprovider = COLLPROVIDER_ICU;
184  else if (pg_strcasecmp(collproviderstr, "libc") == 0)
185  collprovider = COLLPROVIDER_LIBC;
186  else
187  ereport(ERROR,
188  (errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
189  errmsg("unrecognized collation provider: %s",
190  collproviderstr)));
191  }
192  else if (!fromEl)
193  collprovider = COLLPROVIDER_LIBC;
194 
195  if (!collcollate)
196  ereport(ERROR,
197  (errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
198  errmsg("parameter \"lc_collate\" must be specified")));
199 
200  if (!collctype)
201  ereport(ERROR,
202  (errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
203  errmsg("parameter \"lc_ctype\" must be specified")));
204 
205  /*
206  * Nondeterministic collations are currently only supported with ICU
207  * because that's the only case where it can actually make a difference.
208  * So we can save writing the code for the other providers.
209  */
210  if (!collisdeterministic && collprovider != COLLPROVIDER_ICU)
211  ereport(ERROR,
212  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
213  errmsg("nondeterministic collations not supported with this provider")));
214 
215  if (!fromEl)
216  {
217  if (collprovider == COLLPROVIDER_ICU)
218  collencoding = -1;
219  else
220  {
221  collencoding = GetDatabaseEncoding();
222  check_encoding_locale_matches(collencoding, collcollate, collctype);
223  }
224  }
225 
226  if (!collversion)
227  collversion = get_collation_actual_version(collprovider, collcollate);
228 
229  newoid = CollationCreate(collName,
230  collNamespace,
231  GetUserId(),
232  collprovider,
233  collisdeterministic,
234  collencoding,
235  collcollate,
236  collctype,
237  collversion,
238  if_not_exists,
239  false); /* not quiet */
240 
241  if (!OidIsValid(newoid))
242  return InvalidObjectAddress;
243 
244  /*
245  * Check that the locales can be loaded. NB: pg_newlocale_from_collation
246  * is only supposed to be called on non-C-equivalent locales.
247  */
249  if (!lc_collate_is_c(newoid) || !lc_ctype_is_c(newoid))
250  (void) pg_newlocale_from_collation(newoid);
251 
252  ObjectAddressSet(address, CollationRelationId, newoid);
253 
254  return address;
255 }
256 
257 /*
258  * Subroutine for ALTER COLLATION SET SCHEMA and RENAME
259  *
260  * Is there a collation with the same name of the given collation already in
261  * the given namespace? If so, raise an appropriate error message.
262  */
263 void
264 IsThereCollationInNamespace(const char *collname, Oid nspOid)
265 {
266  /* make sure the name doesn't already exist in new schema */
268  CStringGetDatum(collname),
270  ObjectIdGetDatum(nspOid)))
271  ereport(ERROR,
273  errmsg("collation \"%s\" for encoding \"%s\" already exists in schema \"%s\"",
274  collname, GetDatabaseEncodingName(),
275  get_namespace_name(nspOid))));
276 
277  /* mustn't match an any-encoding entry, either */
279  CStringGetDatum(collname),
280  Int32GetDatum(-1),
281  ObjectIdGetDatum(nspOid)))
282  ereport(ERROR,
284  errmsg("collation \"%s\" already exists in schema \"%s\"",
285  collname, get_namespace_name(nspOid))));
286 }
287 
288 /*
289  * ALTER COLLATION
290  */
293 {
294  Relation rel;
295  Oid collOid;
296  HeapTuple tup;
297  Form_pg_collation collForm;
298  Datum collversion;
299  bool isnull;
300  char *oldversion;
301  char *newversion;
302  ObjectAddress address;
303 
304  rel = table_open(CollationRelationId, RowExclusiveLock);
305  collOid = get_collation_oid(stmt->collname, false);
306 
307  if (!pg_collation_ownercheck(collOid, GetUserId()))
309  NameListToString(stmt->collname));
310 
312  if (!HeapTupleIsValid(tup))
313  elog(ERROR, "cache lookup failed for collation %u", collOid);
314 
315  collForm = (Form_pg_collation) GETSTRUCT(tup);
316  collversion = SysCacheGetAttr(COLLOID, tup, Anum_pg_collation_collversion,
317  &isnull);
318  oldversion = isnull ? NULL : TextDatumGetCString(collversion);
319 
320  newversion = get_collation_actual_version(collForm->collprovider, NameStr(collForm->collcollate));
321 
322  /* cannot change from NULL to non-NULL or vice versa */
323  if ((!oldversion && newversion) || (oldversion && !newversion))
324  elog(ERROR, "invalid collation version change");
325  else if (oldversion && newversion && strcmp(newversion, oldversion) != 0)
326  {
327  bool nulls[Natts_pg_collation];
328  bool replaces[Natts_pg_collation];
329  Datum values[Natts_pg_collation];
330 
331  ereport(NOTICE,
332  (errmsg("changing version from %s to %s",
333  oldversion, newversion)));
334 
335  memset(values, 0, sizeof(values));
336  memset(nulls, false, sizeof(nulls));
337  memset(replaces, false, sizeof(replaces));
338 
339  values[Anum_pg_collation_collversion - 1] = CStringGetTextDatum(newversion);
340  replaces[Anum_pg_collation_collversion - 1] = true;
341 
342  tup = heap_modify_tuple(tup, RelationGetDescr(rel),
343  values, nulls, replaces);
344  }
345  else
346  ereport(NOTICE,
347  (errmsg("version has not changed")));
348 
349  CatalogTupleUpdate(rel, &tup->t_self, tup);
350 
351  InvokeObjectPostAlterHook(CollationRelationId, collOid, 0);
352 
353  ObjectAddressSet(address, CollationRelationId, collOid);
354 
355  heap_freetuple(tup);
356  table_close(rel, NoLock);
357 
358  return address;
359 }
360 
361 
362 Datum
364 {
365  Oid collid = PG_GETARG_OID(0);
366  HeapTuple tp;
367  char *collcollate;
368  char collprovider;
369  char *version;
370 
372  if (!HeapTupleIsValid(tp))
373  ereport(ERROR,
374  (errcode(ERRCODE_UNDEFINED_OBJECT),
375  errmsg("collation with OID %u does not exist", collid)));
376 
377  collcollate = pstrdup(NameStr(((Form_pg_collation) GETSTRUCT(tp))->collcollate));
378  collprovider = ((Form_pg_collation) GETSTRUCT(tp))->collprovider;
379 
380  ReleaseSysCache(tp);
381 
382  version = get_collation_actual_version(collprovider, collcollate);
383 
384  if (version)
386  else
387  PG_RETURN_NULL();
388 }
389 
390 
391 /* will we use "locale -a" in pg_import_system_collations? */
392 #if defined(HAVE_LOCALE_T) && !defined(WIN32)
393 #define READ_LOCALE_A_OUTPUT
394 #endif
395 
396 #ifdef READ_LOCALE_A_OUTPUT
397 /*
398  * "Normalize" a libc locale name, stripping off encoding tags such as
399  * ".utf8" (e.g., "en_US.utf8" -> "en_US", but "br_FR.iso885915@euro"
400  * -> "br_FR@euro"). Return true if a new, different name was
401  * generated.
402  */
403 static bool
404 normalize_libc_locale_name(char *new, const char *old)
405 {
406  char *n = new;
407  const char *o = old;
408  bool changed = false;
409 
410  while (*o)
411  {
412  if (*o == '.')
413  {
414  /* skip over encoding tag such as ".utf8" or ".UTF-8" */
415  o++;
416  while ((*o >= 'A' && *o <= 'Z')
417  || (*o >= 'a' && *o <= 'z')
418  || (*o >= '0' && *o <= '9')
419  || (*o == '-'))
420  o++;
421  changed = true;
422  }
423  else
424  *n++ = *o++;
425  }
426  *n = '\0';
427 
428  return changed;
429 }
430 
431 /*
432  * qsort comparator for CollAliasData items
433  */
434 static int
435 cmpaliases(const void *a, const void *b)
436 {
437  const CollAliasData *ca = (const CollAliasData *) a;
438  const CollAliasData *cb = (const CollAliasData *) b;
439 
440  /* comparing localename is enough because other fields are derived */
441  return strcmp(ca->localename, cb->localename);
442 }
443 #endif /* READ_LOCALE_A_OUTPUT */
444 
445 
446 #ifdef USE_ICU
447 /*
448  * Get the ICU language tag for a locale name.
449  * The result is a palloc'd string.
450  */
451 static char *
452 get_icu_language_tag(const char *localename)
453 {
454  char buf[ULOC_FULLNAME_CAPACITY];
455  UErrorCode status;
456 
457  status = U_ZERO_ERROR;
458  uloc_toLanguageTag(localename, buf, sizeof(buf), true, &status);
459  if (U_FAILURE(status))
460  ereport(ERROR,
461  (errmsg("could not convert locale name \"%s\" to language tag: %s",
462  localename, u_errorName(status))));
463 
464  return pstrdup(buf);
465 }
466 
467 /*
468  * Get a comment (specifically, the display name) for an ICU locale.
469  * The result is a palloc'd string, or NULL if we can't get a comment
470  * or find that it's not all ASCII. (We can *not* accept non-ASCII
471  * comments, because the contents of template0 must be encoding-agnostic.)
472  */
473 static char *
474 get_icu_locale_comment(const char *localename)
475 {
476  UErrorCode status;
477  UChar displayname[128];
478  int32 len_uchar;
479  int32 i;
480  char *result;
481 
482  status = U_ZERO_ERROR;
483  len_uchar = uloc_getDisplayName(localename, "en",
484  displayname, lengthof(displayname),
485  &status);
486  if (U_FAILURE(status))
487  return NULL; /* no good reason to raise an error */
488 
489  /* Check for non-ASCII comment (can't use pg_is_ascii for this) */
490  for (i = 0; i < len_uchar; i++)
491  {
492  if (displayname[i] > 127)
493  return NULL;
494  }
495 
496  /* OK, transcribe */
497  result = palloc(len_uchar + 1);
498  for (i = 0; i < len_uchar; i++)
499  result[i] = displayname[i];
500  result[len_uchar] = '\0';
501 
502  return result;
503 }
504 #endif /* USE_ICU */
505 
506 
507 /*
508  * pg_import_system_collations: add known system collations to pg_collation
509  */
510 Datum
512 {
513  Oid nspid = PG_GETARG_OID(0);
514  int ncreated = 0;
515 
516  if (!superuser())
517  ereport(ERROR,
518  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
519  errmsg("must be superuser to import system collations")));
520 
522  ereport(ERROR,
523  (errcode(ERRCODE_UNDEFINED_SCHEMA),
524  errmsg("schema with OID %u does not exist", nspid)));
525 
526  /* Load collations known to libc, using "locale -a" to enumerate them */
527 #ifdef READ_LOCALE_A_OUTPUT
528  {
529  FILE *locale_a_handle;
530  char localebuf[NAMEDATALEN]; /* we assume ASCII so this is fine */
531  int nvalid = 0;
532  Oid collid;
533  CollAliasData *aliases;
534  int naliases,
535  maxaliases,
536  i;
537 
538  /* expansible array of aliases */
539  maxaliases = 100;
540  aliases = (CollAliasData *) palloc(maxaliases * sizeof(CollAliasData));
541  naliases = 0;
542 
543  locale_a_handle = OpenPipeStream("locale -a", "r");
544  if (locale_a_handle == NULL)
545  ereport(ERROR,
547  errmsg("could not execute command \"%s\": %m",
548  "locale -a")));
549 
550  while (fgets(localebuf, sizeof(localebuf), locale_a_handle))
551  {
552  size_t len;
553  int enc;
554  char alias[NAMEDATALEN];
555 
556  len = strlen(localebuf);
557 
558  if (len == 0 || localebuf[len - 1] != '\n')
559  {
560  elog(DEBUG1, "locale name too long, skipped: \"%s\"", localebuf);
561  continue;
562  }
563  localebuf[len - 1] = '\0';
564 
565  /*
566  * Some systems have locale names that don't consist entirely of
567  * ASCII letters (such as "bokm&aring;l" or "fran&ccedil;ais").
568  * This is pretty silly, since we need the locale itself to
569  * interpret the non-ASCII characters. We can't do much with
570  * those, so we filter them out.
571  */
572  if (!pg_is_ascii(localebuf))
573  {
574  elog(DEBUG1, "locale name has non-ASCII characters, skipped: \"%s\"", localebuf);
575  continue;
576  }
577 
578  enc = pg_get_encoding_from_locale(localebuf, false);
579  if (enc < 0)
580  {
581  /* error message printed by pg_get_encoding_from_locale() */
582  continue;
583  }
584  if (!PG_VALID_BE_ENCODING(enc))
585  continue; /* ignore locales for client-only encodings */
586  if (enc == PG_SQL_ASCII)
587  continue; /* C/POSIX are already in the catalog */
588 
589  /* count valid locales found in operating system */
590  nvalid++;
591 
592  /*
593  * Create a collation named the same as the locale, but quietly
594  * doing nothing if it already exists. This is the behavior we
595  * need even at initdb time, because some versions of "locale -a"
596  * can report the same locale name more than once. And it's
597  * convenient for later import runs, too, since you just about
598  * always want to add on new locales without a lot of chatter
599  * about existing ones.
600  */
601  collid = CollationCreate(localebuf, nspid, GetUserId(),
602  COLLPROVIDER_LIBC, true, enc,
603  localebuf, localebuf,
604  get_collation_actual_version(COLLPROVIDER_LIBC, localebuf),
605  true, true);
606  if (OidIsValid(collid))
607  {
608  ncreated++;
609 
610  /* Must do CCI between inserts to handle duplicates correctly */
612  }
613 
614  /*
615  * Generate aliases such as "en_US" in addition to "en_US.utf8"
616  * for ease of use. Note that collation names are unique per
617  * encoding only, so this doesn't clash with "en_US" for LATIN1,
618  * say.
619  *
620  * However, it might conflict with a name we'll see later in the
621  * "locale -a" output. So save up the aliases and try to add them
622  * after we've read all the output.
623  */
624  if (normalize_libc_locale_name(alias, localebuf))
625  {
626  if (naliases >= maxaliases)
627  {
628  maxaliases *= 2;
629  aliases = (CollAliasData *)
630  repalloc(aliases, maxaliases * sizeof(CollAliasData));
631  }
632  aliases[naliases].localename = pstrdup(localebuf);
633  aliases[naliases].alias = pstrdup(alias);
634  aliases[naliases].enc = enc;
635  naliases++;
636  }
637  }
638 
639  ClosePipeStream(locale_a_handle);
640 
641  /*
642  * Before processing the aliases, sort them by locale name. The point
643  * here is that if "locale -a" gives us multiple locale names with the
644  * same encoding and base name, say "en_US.utf8" and "en_US.utf-8", we
645  * want to pick a deterministic one of them. First in ASCII sort
646  * order is a good enough rule. (Before PG 10, the code corresponding
647  * to this logic in initdb.c had an additional ordering rule, to
648  * prefer the locale name exactly matching the alias, if any. We
649  * don't need to consider that here, because we would have already
650  * created such a pg_collation entry above, and that one will win.)
651  */
652  if (naliases > 1)
653  qsort((void *) aliases, naliases, sizeof(CollAliasData), cmpaliases);
654 
655  /* Now add aliases, ignoring any that match pre-existing entries */
656  for (i = 0; i < naliases; i++)
657  {
658  char *locale = aliases[i].localename;
659  char *alias = aliases[i].alias;
660  int enc = aliases[i].enc;
661 
662  collid = CollationCreate(alias, nspid, GetUserId(),
663  COLLPROVIDER_LIBC, true, enc,
664  locale, locale,
665  get_collation_actual_version(COLLPROVIDER_LIBC, locale),
666  true, true);
667  if (OidIsValid(collid))
668  {
669  ncreated++;
670 
672  }
673  }
674 
675  /* Give a warning if "locale -a" seems to be malfunctioning */
676  if (nvalid == 0)
678  (errmsg("no usable system locales were found")));
679  }
680 #endif /* READ_LOCALE_A_OUTPUT */
681 
682  /*
683  * Load collations known to ICU
684  *
685  * We use uloc_countAvailable()/uloc_getAvailable() rather than
686  * ucol_countAvailable()/ucol_getAvailable(). The former returns a full
687  * set of language+region combinations, whereas the latter only returns
688  * language+region combinations if they are distinct from the language's
689  * base collation. So there might not be a de-DE or en-GB, which would be
690  * confusing.
691  */
692 #ifdef USE_ICU
693  {
694  int i;
695 
696  /*
697  * Start the loop at -1 to sneak in the root locale without too much
698  * code duplication.
699  */
700  for (i = -1; i < uloc_countAvailable(); i++)
701  {
702  const char *name;
703  char *langtag;
704  char *icucomment;
705  const char *collcollate;
706  Oid collid;
707 
708  if (i == -1)
709  name = ""; /* ICU root locale */
710  else
711  name = uloc_getAvailable(i);
712 
713  langtag = get_icu_language_tag(name);
714  collcollate = U_ICU_VERSION_MAJOR_NUM >= 54 ? langtag : name;
715 
716  /*
717  * Be paranoid about not allowing any non-ASCII strings into
718  * pg_collation
719  */
720  if (!pg_is_ascii(langtag) || !pg_is_ascii(collcollate))
721  continue;
722 
723  collid = CollationCreate(psprintf("%s-x-icu", langtag),
724  nspid, GetUserId(),
725  COLLPROVIDER_ICU, true, -1,
726  collcollate, collcollate,
727  get_collation_actual_version(COLLPROVIDER_ICU, collcollate),
728  true, true);
729  if (OidIsValid(collid))
730  {
731  ncreated++;
732 
734 
735  icucomment = get_icu_locale_comment(name);
736  if (icucomment)
737  CreateComments(collid, CollationRelationId, 0,
738  icucomment);
739  }
740  }
741  }
742 #endif /* USE_ICU */
743 
744  PG_RETURN_INT32(ncreated);
745 }
bool pg_collation_ownercheck(Oid coll_oid, Oid roleid)
Definition: aclchk.c:5262
void CreateComments(Oid oid, Oid classoid, int32 subid, const char *comment)
Definition: comment.c:143
#define DEBUG1
Definition: elog.h:25
void table_close(Relation relation, LOCKMODE lockmode)
Definition: table.c:167
#define GETSTRUCT(TUP)
Definition: htup_details.h:654
void check_encoding_locale_matches(int encoding, const char *collate, const char *ctype)
Definition: dbcommands.c:725
#define RelationGetDescr(relation)
Definition: rel.h:503
Oid GetUserId(void)
Definition: miscinit.c:478
char * localename
Definition: collationcmds.c:43
Oid QualifiedNameGetCreationNamespace(List *names, char **objname_p)
Definition: namespace.c:3040
char * pstrdup(const char *in)
Definition: mcxt.c:1299
char * psprintf(const char *fmt,...)
Definition: psprintf.c:46
#define PG_RETURN_INT32(x)
Definition: fmgr.h:354
int errcode(int sqlerrcode)
Definition: elog.c:698
bool superuser(void)
Definition: superuser.c:46
int pg_strcasecmp(const char *s1, const char *s2)
Definition: pgstrcasecmp.c:36
#define lengthof(array)
Definition: c.h:734
void heap_freetuple(HeapTuple htup)
Definition: heaptuple.c:1338
unsigned int Oid
Definition: postgres_ext.h:31
#define OidIsValid(objectId)
Definition: c.h:710
AclResult pg_namespace_aclcheck(Oid nsp_oid, Oid roleid, AclMode mode)
Definition: aclchk.c:4756
bool pg_is_ascii(const char *str)
Definition: string.c:99
signed int int32
Definition: c.h:429
int ClosePipeStream(FILE *file)
Definition: fd.c:2826
#define NAMEDATALEN
void aclcheck_error(AclResult aclerr, ObjectType objtype, const char *objectname)
Definition: aclchk.c:3308
bool defGetBoolean(DefElem *def)
Definition: define.c:111
#define SearchSysCacheExists1(cacheId, key1)
Definition: syscache.h:184
#define ObjectIdGetDatum(X)
Definition: postgres.h:551
#define ERROR
Definition: elog.h:46
#define ACL_CREATE
Definition: parsenodes.h:92
#define SearchSysCacheExists3(cacheId, key1, key2, key3)
Definition: syscache.h:188
bool lc_collate_is_c(Oid collation)
Definition: pg_locale.c:1321
struct pg_encoding enc
Definition: encode.c:516
char * defGetString(DefElem *def)
Definition: define.c:49
ItemPointerData t_self
Definition: htup.h:65
#define lfirst_node(type, lc)
Definition: pg_list.h:172
char * get_namespace_name(Oid nspid)
Definition: lsyscache.c:3316
#define NoLock
Definition: lockdefs.h:34
static char * buf
Definition: pg_test_fsync.c:68
#define PG_GETARG_OID(n)
Definition: fmgr.h:275
int location
Definition: parsenodes.h:749
#define RowExclusiveLock
Definition: lockdefs.h:38
int errdetail(const char *fmt,...)
Definition: elog.c:1042
int errcode_for_file_access(void)
Definition: elog.c:721
#define CStringGetDatum(X)
Definition: postgres.h:622
void IsThereCollationInNamespace(const char *collname, Oid nspOid)
FILE * OpenPipeStream(const char *command, const char *mode)
Definition: fd.c:2520
Datum pg_collation_actual_version(PG_FUNCTION_ARGS)
#define InvokeObjectPostAlterHook(classId, objectId, subId)
Definition: objectaccess.h:175
#define WARNING
Definition: elog.h:40
HeapTuple SearchSysCache1(int cacheId, Datum key1)
Definition: syscache.c:1127
char * NameListToString(List *names)
Definition: namespace.c:3147
pg_locale_t pg_newlocale_from_collation(Oid collid)
Definition: pg_locale.c:1468
#define TextDatumGetCString(d)
Definition: builtins.h:83
AclResult
Definition: acl.h:177
uintptr_t Datum
Definition: postgres.h:411
void CommandCounterIncrement(void)
Definition: xact.c:1021
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:1175
int GetDatabaseEncoding(void)
Definition: mbutils.c:1210
Datum SysCacheGetAttr(int cacheId, HeapTuple tup, AttrNumber attributeNumber, bool *isNull)
Definition: syscache.c:1388
ObjectAddress DefineCollation(ParseState *pstate, List *names, List *parameters, bool if_not_exists)
Definition: collationcmds.c:53
int pg_get_encoding_from_locale(const char *ctype, bool write_message)
Definition: chklocale.c:452
#define ereport(elevel,...)
Definition: elog.h:157
void errorConflictingDefElem(DefElem *defel, ParseState *pstate)
Definition: define.c:355
#define NOTICE
Definition: elog.h:37
#define PG_RETURN_TEXT_P(x)
Definition: fmgr.h:372
text * cstring_to_text(const char *s)
Definition: varlena.c:190
#define PG_VALID_BE_ENCODING(_enc)
Definition: pg_wchar.h:295
#define HeapTupleIsValid(tuple)
Definition: htup.h:78
const char * GetDatabaseEncodingName(void)
Definition: mbutils.c:1216
List * defGetQualifiedName(DefElem *def)
Definition: define.c:223
void CatalogTupleUpdate(Relation heapRel, ItemPointer otid, HeapTuple tup)
Definition: indexing.c:301
static int list_length(const List *l)
Definition: pg_list.h:149
int parser_errposition(ParseState *pstate, int location)
Definition: parse_node.c:111
Oid CollationCreate(const char *collname, Oid collnamespace, Oid collowner, char collprovider, bool collisdeterministic, int32 collencoding, const char *collcollate, const char *collctype, const char *collversion, bool if_not_exists, bool quiet)
Definition: pg_collation.c:46
void * repalloc(void *pointer, Size size)
Definition: mcxt.c:1182
const char * name
Definition: encode.c:515
FormData_pg_collation * Form_pg_collation
Definition: pg_collation.h:56
#define ObjectAddressSet(addr, class_id, object_id)
Definition: objectaddress.h:40
static Datum values[MAXATTR]
Definition: bootstrap.c:166
#define SearchSysCacheCopy1(cacheId, key1)
Definition: syscache.h:175
#define Int32GetDatum(X)
Definition: postgres.h:523
const ObjectAddress InvalidObjectAddress
Datum pg_import_system_collations(PG_FUNCTION_ARGS)
void * palloc(Size size)
Definition: mcxt.c:1062
int errmsg(const char *fmt,...)
Definition: elog.c:909
#define elog(elevel,...)
Definition: elog.h:232
ObjectAddress AlterCollation(AlterCollationStmt *stmt)
int i
#define NameStr(name)
Definition: c.h:681
static char * locale
Definition: initdb.c:126
#define CStringGetTextDatum(s)
Definition: builtins.h:82
#define PG_FUNCTION_ARGS
Definition: fmgr.h:193
char * defname
Definition: parsenodes.h:746
bool lc_ctype_is_c(Oid collation)
Definition: pg_locale.c:1371
#define qsort(a, b, c, d)
Definition: port.h:504
static void static void status(const char *fmt,...) pg_attribute_printf(1
Definition: pg_regress.c:227
Relation table_open(Oid relationId, LOCKMODE lockmode)
Definition: table.c:39
HeapTuple heap_modify_tuple(HeapTuple tuple, TupleDesc tupleDesc, Datum *replValues, bool *replIsnull, bool *doReplace)
Definition: heaptuple.c:1113
#define ERRCODE_DUPLICATE_OBJECT
Definition: streamutil.c:32
Oid get_collation_oid(List *name, bool missing_ok)
Definition: namespace.c:3646
Definition: pg_list.h:50
#define PG_RETURN_NULL()
Definition: fmgr.h:345
char * get_collation_actual_version(char collprovider, const char *collcollate)
Definition: pg_locale.c:1645