PostgreSQL Source Code git master
Loading...
Searching...
No Matches
varchar.c
Go to the documentation of this file.
1/*-------------------------------------------------------------------------
2 *
3 * varchar.c
4 * Functions for the built-in types char(n) and varchar(n).
5 *
6 * Portions Copyright (c) 1996-2026, PostgreSQL Global Development Group
7 * Portions Copyright (c) 1994, Regents of the University of California
8 *
9 *
10 * IDENTIFICATION
11 * src/backend/utils/adt/varchar.c
12 *
13 *-------------------------------------------------------------------------
14 */
15#include "postgres.h"
16
17#include "access/detoast.h"
18#include "access/htup_details.h"
20#include "catalog/pg_type.h"
21#include "common/hashfn.h"
22#include "libpq/pqformat.h"
23#include "mb/pg_wchar.h"
24#include "nodes/nodeFuncs.h"
25#include "nodes/supportnodes.h"
26#include "utils/array.h"
27#include "utils/builtins.h"
28#include "utils/pg_locale.h"
29#include "utils/varlena.h"
30
31/* common code for bpchartypmodin and varchartypmodin */
32static int32
33anychar_typmodin(ArrayType *ta, const char *typename)
34{
35 int32 typmod;
36 int32 *tl;
37 int n;
38
40
41 /*
42 * we're not too tense about good error message here because grammar
43 * shouldn't allow wrong number of modifiers for CHAR
44 */
45 if (n != 1)
48 errmsg("invalid type modifier")));
49
50 if (*tl < 1)
53 errmsg("length for type %s must be at least 1", typename)));
54 if (*tl > MaxAttrSize)
57 errmsg("length for type %s cannot exceed %d",
58 typename, MaxAttrSize)));
59
60 /*
61 * For largely historical reasons, the typmod is VARHDRSZ plus the number
62 * of characters; there is enough client-side code that knows about that
63 * that we'd better not change it.
64 */
65 typmod = VARHDRSZ + *tl;
66
67 return typmod;
68}
69
70/* common code for bpchartypmodout and varchartypmodout */
71static char *
73{
74 char *res = (char *) palloc(64);
75
76 if (typmod > VARHDRSZ)
77 snprintf(res, 64, "(%d)", (int) (typmod - VARHDRSZ));
78 else
79 *res = '\0';
80
81 return res;
82}
83
84
85/*
86 * CHAR() and VARCHAR() types are part of the SQL standard. CHAR()
87 * is for blank-padded string whose length is specified in CREATE TABLE.
88 * VARCHAR is for storing string whose length is at most the length specified
89 * at CREATE TABLE time.
90 *
91 * It's hard to implement these types because we cannot figure out
92 * the length of the type from the type itself. I changed (hopefully all) the
93 * fmgr calls that invoke input functions of a data type to supply the
94 * length also. (eg. in INSERTs, we have the tupleDescriptor which contains
95 * the length of the attributes and hence the exact length of the char() or
96 * varchar(). We pass this to bpcharin() or varcharin().) In the case where
97 * we cannot determine the length, we pass in -1 instead and the input
98 * converter does not enforce any length check.
99 *
100 * We actually implement this as a varlena so that we don't have to pass in
101 * the length for the comparison functions. (The difference between these
102 * types and "text" is that we truncate and possibly blank-pad the string
103 * at insertion time.)
104 *
105 * - ay 6/95
106 */
107
108
109/*****************************************************************************
110 * bpchar - char() *
111 *****************************************************************************/
112
113/*
114 * bpchar_input -- common guts of bpcharin and bpcharrecv
115 *
116 * s is the input text of length len (may not be null-terminated)
117 * atttypmod is the typmod value to apply
118 *
119 * Note that atttypmod is measured in characters, which
120 * is not necessarily the same as the number of bytes.
121 *
122 * If the input string is too long, raise an error, unless the extra
123 * characters are spaces, in which case they're truncated. (per SQL)
124 *
125 * If escontext points to an ErrorSaveContext node, that is filled instead
126 * of throwing an error; the caller must check SOFT_ERROR_OCCURRED()
127 * to detect errors.
128 */
129static BpChar *
130bpchar_input(const char *s, size_t len, int32 atttypmod, Node *escontext)
131{
132 BpChar *result;
133 char *r;
134 size_t maxlen;
135
136 /* If typmod is -1 (or invalid), use the actual string length */
137 if (atttypmod < (int32) VARHDRSZ)
138 maxlen = len;
139 else
140 {
141 size_t charlen; /* number of CHARACTERS in the input */
142
143 maxlen = atttypmod - VARHDRSZ;
144 charlen = pg_mbstrlen_with_len(s, len);
145 if (charlen > maxlen)
146 {
147 /* Verify that extra characters are spaces, and clip them off */
148 size_t mbmaxlen = pg_mbcharcliplen(s, len, maxlen);
149 size_t j;
150
151 /*
152 * at this point, len is the actual BYTE length of the input
153 * string, maxlen is the max number of CHARACTERS allowed for this
154 * bpchar type, mbmaxlen is the length in BYTES of those chars.
155 */
156 for (j = mbmaxlen; j < len; j++)
157 {
158 if (s[j] != ' ')
159 ereturn(escontext, NULL,
161 errmsg("value too long for type character(%zu)",
162 maxlen)));
163 }
164
165 /*
166 * Now we set maxlen to the necessary byte length, not the number
167 * of CHARACTERS!
168 */
169 maxlen = len = mbmaxlen;
170 }
171 else
172 {
173 /*
174 * Now we set maxlen to the necessary byte length, not the number
175 * of CHARACTERS!
176 */
177 maxlen = len + (maxlen - charlen);
178 }
179 }
180
181 result = (BpChar *) palloc(maxlen + VARHDRSZ);
182 SET_VARSIZE(result, maxlen + VARHDRSZ);
183 r = VARDATA(result);
184 memcpy(r, s, len);
185
186 /* blank pad the string if necessary */
187 if (maxlen > len)
188 memset(r + len, ' ', maxlen - len);
189
190 return result;
191}
192
193/*
194 * Convert a C string to CHARACTER internal representation. atttypmod
195 * is the declared length of the type plus VARHDRSZ.
196 */
197Datum
199{
200 char *s = PG_GETARG_CSTRING(0);
201#ifdef NOT_USED
202 Oid typelem = PG_GETARG_OID(1);
203#endif
204 int32 atttypmod = PG_GETARG_INT32(2);
205 BpChar *result;
206
207 result = bpchar_input(s, strlen(s), atttypmod, fcinfo->context);
209}
210
211
212/*
213 * Convert a CHARACTER value to a C string.
214 *
215 * Uses the text conversion functions, which is only appropriate if BpChar
216 * and text are equivalent types.
217 */
218Datum
225
226/*
227 * bpcharrecv - converts external binary format to bpchar
228 */
229Datum
231{
233#ifdef NOT_USED
234 Oid typelem = PG_GETARG_OID(1);
235#endif
236 int32 atttypmod = PG_GETARG_INT32(2);
237 BpChar *result;
238 char *str;
239 int nbytes;
240
241 str = pq_getmsgtext(buf, buf->len - buf->cursor, &nbytes);
242 result = bpchar_input(str, nbytes, atttypmod, NULL);
243 pfree(str);
245}
246
247/*
248 * bpcharsend - converts bpchar to binary format
249 */
250Datum
252{
253 /* Exactly the same as textsend, so share code */
254 return textsend(fcinfo);
255}
256
257
258/*
259 * Converts a CHARACTER type to the specified size.
260 *
261 * maxlen is the typmod, ie, declared length plus VARHDRSZ bytes.
262 * isExplicit is true if this is for an explicit cast to char(N).
263 *
264 * Truncation rules: for an explicit cast, silently truncate to the given
265 * length; for an implicit cast, raise error unless extra characters are
266 * all spaces. (This is sort-of per SQL: the spec would actually have us
267 * raise a "completion condition" for the explicit cast case, but Postgres
268 * hasn't got such a concept.)
269 */
270Datum
272{
274 int32 maxlen = PG_GETARG_INT32(1);
275 bool isExplicit = PG_GETARG_BOOL(2);
276 BpChar *result;
277 int32 len;
278 char *r;
279 char *s;
280 int i;
281 int charlen; /* number of characters in the input string +
282 * VARHDRSZ */
283
284 /* No work if typmod is invalid */
285 if (maxlen < (int32) VARHDRSZ)
287
288 maxlen -= VARHDRSZ;
289
291 s = VARDATA_ANY(source);
292
293 charlen = pg_mbstrlen_with_len(s, len);
294
295 /* No work if supplied data matches typmod already */
296 if (charlen == maxlen)
298
299 if (charlen > maxlen)
300 {
301 /* Verify that extra characters are spaces, and clip them off */
302 size_t maxmblen;
303
304 maxmblen = pg_mbcharcliplen(s, len, maxlen);
305
306 if (!isExplicit)
307 {
308 for (i = maxmblen; i < len; i++)
309 if (s[i] != ' ')
310 ereturn(fcinfo->context, (Datum) 0,
312 errmsg("value too long for type character(%d)",
313 maxlen)));
314 }
315
316 len = maxmblen;
317
318 /*
319 * At this point, maxlen is the necessary byte length, not the number
320 * of CHARACTERS!
321 */
322 maxlen = len;
323 }
324 else
325 {
326 /*
327 * At this point, maxlen is the necessary byte length, not the number
328 * of CHARACTERS!
329 */
330 maxlen = len + (maxlen - charlen);
331 }
332
333 Assert(maxlen >= len);
334
335 result = palloc(maxlen + VARHDRSZ);
336 SET_VARSIZE(result, maxlen + VARHDRSZ);
337 r = VARDATA(result);
338
339 memcpy(r, s, len);
340
341 /* blank pad the string if necessary */
342 if (maxlen > len)
343 memset(r + len, ' ', maxlen - len);
344
346}
347
348
349/*
350 * char_bpchar()
351 * Convert char to bpchar(1).
352 */
353Datum
355{
356 char c = PG_GETARG_CHAR(0);
357 BpChar *result;
358
359 result = (BpChar *) palloc(VARHDRSZ + 1);
360
362 *(VARDATA(result)) = c;
363
365}
366
367
368/*
369 * bpchar_name()
370 * Converts a bpchar() type to a NameData type.
371 */
372Datum
374{
376 char *s_data;
377 Name result;
378 int len;
379
381 s_data = VARDATA_ANY(s);
382
383 /* Truncate oversize input */
384 if (len >= NAMEDATALEN)
386
387 /* Remove trailing blanks */
388 while (len > 0)
389 {
390 if (s_data[len - 1] != ' ')
391 break;
392 len--;
393 }
394
395 /* We use palloc0 here to ensure result is zero-padded */
398
400}
401
402/*
403 * name_bpchar()
404 * Converts a NameData type to a bpchar type.
405 *
406 * Uses the text conversion functions, which is only appropriate if BpChar
407 * and text are equivalent types.
408 */
409Datum
418
419Datum
426
427Datum
434
435
436/*****************************************************************************
437 * varchar - varchar(n)
438 *
439 * Note: varchar piggybacks on type text for most operations, and so has no
440 * C-coded functions except for I/O and typmod checking.
441 *****************************************************************************/
442
443/*
444 * varchar_input -- common guts of varcharin and varcharrecv
445 *
446 * s is the input text of length len (may not be null-terminated)
447 * atttypmod is the typmod value to apply
448 *
449 * Note that atttypmod is measured in characters, which
450 * is not necessarily the same as the number of bytes.
451 *
452 * If the input string is too long, raise an error, unless the extra
453 * characters are spaces, in which case they're truncated. (per SQL)
454 *
455 * If escontext points to an ErrorSaveContext node, that is filled instead
456 * of throwing an error; the caller must check SOFT_ERROR_OCCURRED()
457 * to detect errors.
458 */
459static VarChar *
460varchar_input(const char *s, size_t len, int32 atttypmod, Node *escontext)
461{
463 size_t maxlen;
464
465 maxlen = atttypmod - VARHDRSZ;
466
467 if (atttypmod >= (int32) VARHDRSZ && len > maxlen)
468 {
469 /* Verify that extra characters are spaces, and clip them off */
470 size_t mbmaxlen = pg_mbcharcliplen(s, len, maxlen);
471 size_t j;
472
473 for (j = mbmaxlen; j < len; j++)
474 {
475 if (s[j] != ' ')
476 ereturn(escontext, NULL,
478 errmsg("value too long for type character varying(%zu)",
479 maxlen)));
480 }
481
482 len = mbmaxlen;
483 }
484
485 /*
486 * We can use cstring_to_text_with_len because VarChar and text are
487 * binary-compatible types.
488 */
490 return result;
491}
492
493/*
494 * Convert a C string to VARCHAR internal representation. atttypmod
495 * is the declared length of the type plus VARHDRSZ.
496 */
497Datum
499{
500 char *s = PG_GETARG_CSTRING(0);
501#ifdef NOT_USED
502 Oid typelem = PG_GETARG_OID(1);
503#endif
504 int32 atttypmod = PG_GETARG_INT32(2);
506
507 result = varchar_input(s, strlen(s), atttypmod, fcinfo->context);
509}
510
511
512/*
513 * Convert a VARCHAR value to a C string.
514 *
515 * Uses the text to C string conversion function, which is only appropriate
516 * if VarChar and text are equivalent types.
517 */
518Datum
525
526/*
527 * varcharrecv - converts external binary format to varchar
528 */
529Datum
531{
533#ifdef NOT_USED
534 Oid typelem = PG_GETARG_OID(1);
535#endif
536 int32 atttypmod = PG_GETARG_INT32(2);
538 char *str;
539 int nbytes;
540
541 str = pq_getmsgtext(buf, buf->len - buf->cursor, &nbytes);
542 result = varchar_input(str, nbytes, atttypmod, NULL);
543 pfree(str);
545}
546
547/*
548 * varcharsend - converts varchar to binary format
549 */
550Datum
552{
553 /* Exactly the same as textsend, so share code */
554 return textsend(fcinfo);
555}
556
557
558/*
559 * varchar_support()
560 *
561 * Planner support function for the varchar() length coercion function.
562 *
563 * Currently, the only interesting thing we can do is flatten calls that set
564 * the new maximum length >= the previous maximum length. We can ignore the
565 * isExplicit argument, since that only affects truncation cases.
566 */
567Datum
569{
571 Node *ret = NULL;
572
574 {
576 FuncExpr *expr = req->fcall;
577 Node *typmod;
578
579 Assert(list_length(expr->args) >= 2);
580
581 typmod = (Node *) lsecond(expr->args);
582
583 if (IsA(typmod, Const) && !((Const *) typmod)->constisnull)
584 {
585 Node *source = (Node *) linitial(expr->args);
590
591 if (new_typmod < 0 || (old_typmod >= 0 && old_max <= new_max))
593 }
594 }
595
597}
598
599/*
600 * Converts a VARCHAR type to the specified size.
601 *
602 * maxlen is the typmod, ie, declared length plus VARHDRSZ bytes.
603 * isExplicit is true if this is for an explicit cast to varchar(N).
604 *
605 * Truncation rules: for an explicit cast, silently truncate to the given
606 * length; for an implicit cast, raise error unless extra characters are
607 * all spaces. (This is sort-of per SQL: the spec would actually have us
608 * raise a "completion condition" for the explicit cast case, but Postgres
609 * hasn't got such a concept.)
610 */
611Datum
613{
615 int32 typmod = PG_GETARG_INT32(1);
616 bool isExplicit = PG_GETARG_BOOL(2);
617 int32 len,
618 maxlen;
619 size_t maxmblen;
620 int i;
621 char *s_data;
622
625 maxlen = typmod - VARHDRSZ;
626
627 /* No work if typmod is invalid or supplied data fits it already */
628 if (maxlen < 0 || len <= maxlen)
630
631 /* only reach here if string is too long... */
632
633 /* truncate multibyte string preserving multibyte boundary */
634 maxmblen = pg_mbcharcliplen(s_data, len, maxlen);
635
636 if (!isExplicit)
637 {
638 for (i = maxmblen; i < len; i++)
639 if (s_data[i] != ' ')
640 ereturn(fcinfo->context, (Datum) 0,
642 errmsg("value too long for type character varying(%d)",
643 maxlen)));
644 }
645
647 maxmblen));
648}
649
650Datum
657
658Datum
665
666
667/*****************************************************************************
668 * Exported functions
669 *****************************************************************************/
670
671/* "True" length (not counting trailing blanks) of a BpChar */
672static inline int
677
678int
679bpchartruelen(char *s, int len)
680{
681 int i;
682
683 /*
684 * Note that we rely on the assumption that ' ' is a singleton unit on
685 * every supported multibyte server encoding.
686 */
687 for (i = len - 1; i >= 0; i--)
688 {
689 if (s[i] != ' ')
690 break;
691 }
692 return i + 1;
693}
694
695Datum
697{
699 int len;
700
701 /* get number of bytes, ignoring trailing spaces */
702 len = bcTruelen(arg);
703
704 /* in multibyte encoding, convert to number of characters */
707
709}
710
711Datum
713{
715
716 /* We need not detoast the input at all */
718}
719
720
721/*****************************************************************************
722 * Comparison Functions used for bpchar
723 *
724 * Note: btree indexes need these routines not to leak memory; therefore,
725 * be careful to free working copies of toasted datums. Most places don't
726 * need to be so careful.
727 *****************************************************************************/
728
729static void
731{
732 if (!OidIsValid(collid))
733 {
734 /*
735 * This typically means that the parser could not resolve a conflict
736 * of implicit collations, so report it that way.
737 */
740 errmsg("could not determine which collation to use for string comparison"),
741 errhint("Use the COLLATE clause to set the collation explicitly.")));
742 }
743}
744
745Datum
747{
750 int len1,
751 len2;
752 bool result;
755
757
758 len1 = bcTruelen(arg1);
759 len2 = bcTruelen(arg2);
760
762
763 if (mylocale->deterministic)
764 {
765 /*
766 * Since we only care about equality or not-equality, we can avoid all
767 * the expense of strcoll() here, and just do bitwise comparison.
768 */
769 if (len1 != len2)
770 result = false;
771 else
772 result = (memcmp(VARDATA_ANY(arg1), VARDATA_ANY(arg2), len1) == 0);
773 }
774 else
775 {
777 collid) == 0);
778 }
779
782
784}
785
786Datum
788{
791 int len1,
792 len2;
793 bool result;
796
798
799 len1 = bcTruelen(arg1);
800 len2 = bcTruelen(arg2);
801
803
804 if (mylocale->deterministic)
805 {
806 /*
807 * Since we only care about equality or not-equality, we can avoid all
808 * the expense of strcoll() here, and just do bitwise comparison.
809 */
810 if (len1 != len2)
811 result = true;
812 else
813 result = (memcmp(VARDATA_ANY(arg1), VARDATA_ANY(arg2), len1) != 0);
814 }
815 else
816 {
818 collid) != 0);
819 }
820
823
825}
826
827Datum
829{
832 int len1,
833 len2;
834 int cmp;
835
836 len1 = bcTruelen(arg1);
837 len2 = bcTruelen(arg2);
838
841
844
845 PG_RETURN_BOOL(cmp < 0);
846}
847
848Datum
850{
853 int len1,
854 len2;
855 int cmp;
856
857 len1 = bcTruelen(arg1);
858 len2 = bcTruelen(arg2);
859
862
865
866 PG_RETURN_BOOL(cmp <= 0);
867}
868
869Datum
871{
874 int len1,
875 len2;
876 int cmp;
877
878 len1 = bcTruelen(arg1);
879 len2 = bcTruelen(arg2);
880
883
886
887 PG_RETURN_BOOL(cmp > 0);
888}
889
890Datum
892{
895 int len1,
896 len2;
897 int cmp;
898
899 len1 = bcTruelen(arg1);
900 len2 = bcTruelen(arg2);
901
904
907
908 PG_RETURN_BOOL(cmp >= 0);
909}
910
911Datum
913{
916 int len1,
917 len2;
918 int cmp;
919
920 len1 = bcTruelen(arg1);
921 len2 = bcTruelen(arg2);
922
925
928
930}
931
932Datum
934{
936 Oid collid = ssup->ssup_collation;
937 MemoryContext oldcontext;
938
939 oldcontext = MemoryContextSwitchTo(ssup->ssup_cxt);
940
941 /* Use generic string SortSupport */
943
944 MemoryContextSwitchTo(oldcontext);
945
947}
948
949Datum
951{
954 int len1,
955 len2;
956 int cmp;
957
958 len1 = bcTruelen(arg1);
959 len2 = bcTruelen(arg2);
960
963
964 PG_RETURN_BPCHAR_P((cmp >= 0) ? arg1 : arg2);
965}
966
967Datum
969{
972 int len1,
973 len2;
974 int cmp;
975
976 len1 = bcTruelen(arg1);
977 len2 = bcTruelen(arg2);
978
981
982 PG_RETURN_BPCHAR_P((cmp <= 0) ? arg1 : arg2);
983}
984
985
986/*
987 * bpchar needs a specialized hash function because we want to ignore
988 * trailing blanks in comparisons.
989 */
990Datum
992{
993 BpChar *key = PG_GETARG_BPCHAR_PP(0);
995 char *keydata;
996 int keylen;
999
1000 if (!collid)
1001 ereport(ERROR,
1003 errmsg("could not determine which collation to use for string hashing"),
1004 errhint("Use the COLLATE clause to set the collation explicitly.")));
1005
1006 keydata = VARDATA_ANY(key);
1007 keylen = bcTruelen(key);
1008
1010
1011 if (mylocale->deterministic)
1012 {
1013 result = hash_any((unsigned char *) keydata, keylen);
1014 }
1015 else
1016 {
1017 Size bsize,
1018 rsize;
1019 char *buf;
1020
1021 bsize = pg_strnxfrm(NULL, 0, keydata, keylen, mylocale);
1022 buf = palloc(bsize + 1);
1023
1024 rsize = pg_strnxfrm(buf, bsize + 1, keydata, keylen, mylocale);
1025
1026 /* the second call may return a smaller value than the first */
1027 if (rsize > bsize)
1028 elog(ERROR, "pg_strnxfrm() returned unexpected result");
1029
1030 /*
1031 * In principle, there's no reason to include the terminating NUL
1032 * character in the hash, but it was done before and the behavior must
1033 * be preserved.
1034 */
1035 result = hash_any((uint8_t *) buf, bsize + 1);
1036
1037 pfree(buf);
1038 }
1039
1040 /* Avoid leaking memory for toasted inputs */
1041 PG_FREE_IF_COPY(key, 0);
1042
1043 return result;
1044}
1045
1046Datum
1048{
1049 BpChar *key = PG_GETARG_BPCHAR_PP(0);
1051 char *keydata;
1052 int keylen;
1054 Datum result;
1055
1056 if (!collid)
1057 ereport(ERROR,
1059 errmsg("could not determine which collation to use for string hashing"),
1060 errhint("Use the COLLATE clause to set the collation explicitly.")));
1061
1062 keydata = VARDATA_ANY(key);
1063 keylen = bcTruelen(key);
1064
1066
1067 if (mylocale->deterministic)
1068 {
1069 result = hash_any_extended((unsigned char *) keydata, keylen,
1070 PG_GETARG_INT64(1));
1071 }
1072 else
1073 {
1074 Size bsize,
1075 rsize;
1076 char *buf;
1077
1078 bsize = pg_strnxfrm(NULL, 0, keydata, keylen, mylocale);
1079 buf = palloc(bsize + 1);
1080
1081 rsize = pg_strnxfrm(buf, bsize + 1, keydata, keylen, mylocale);
1082
1083 /* the second call may return a smaller value than the first */
1084 if (rsize > bsize)
1085 elog(ERROR, "pg_strnxfrm() returned unexpected result");
1086
1087 /*
1088 * In principle, there's no reason to include the terminating NUL
1089 * character in the hash, but it was done before and the behavior must
1090 * be preserved.
1091 */
1093 PG_GETARG_INT64(1));
1094
1095 pfree(buf);
1096 }
1097
1098 PG_FREE_IF_COPY(key, 0);
1099
1100 return result;
1101}
1102
1103/*
1104 * The following operators support character-by-character comparison
1105 * of bpchar datums, to allow building indexes suitable for LIKE clauses.
1106 * Note that the regular bpchareq/bpcharne comparison operators, and
1107 * regular support functions 1 and 2 with "C" collation are assumed to be
1108 * compatible with these!
1109 */
1110
1111static int
1113{
1114 int result;
1115 int len1,
1116 len2;
1117
1118 len1 = bcTruelen(arg1);
1119 len2 = bcTruelen(arg2);
1120
1121 result = memcmp(VARDATA_ANY(arg1), VARDATA_ANY(arg2), Min(len1, len2));
1122 if (result != 0)
1123 return result;
1124 else if (len1 < len2)
1125 return -1;
1126 else if (len1 > len2)
1127 return 1;
1128 else
1129 return 0;
1130}
1131
1132
1133Datum
1147
1148
1149Datum
1163
1164
1165Datum
1179
1180
1181Datum
1195
1196
1197Datum
1211
1212
1213Datum
1215{
1217 MemoryContext oldcontext;
1218
1219 oldcontext = MemoryContextSwitchTo(ssup->ssup_cxt);
1220
1221 /* Use generic string SortSupport, forcing "C" collation */
1223
1224 MemoryContextSwitchTo(oldcontext);
1225
1227}
#define PG_GETARG_ARRAYTYPE_P(n)
Definition array.h:263
int32 * ArrayGetIntegerTypmods(ArrayType *arr, int *n)
Definition arrayutils.c:233
#define TextDatumGetCString(d)
Definition builtins.h:99
#define NameStr(name)
Definition c.h:835
NameData * Name
Definition c.h:833
#define Min(x, y)
Definition c.h:1091
#define VARHDRSZ
Definition c.h:781
#define Assert(condition)
Definition c.h:943
int32_t int32
Definition c.h:620
#define OidIsValid(objectId)
Definition c.h:858
size_t Size
Definition c.h:689
uint32 result
memcpy(sums, checksumBaseOffsets, sizeof(checksumBaseOffsets))
Oid collid
Size toast_raw_datum_size(Datum value)
Definition detoast.c:545
Datum arg
Definition elog.c:1323
int errcode(int sqlerrcode)
Definition elog.c:875
#define ereturn(context, dummy_value,...)
Definition elog.h:280
int errhint(const char *fmt,...) pg_attribute_printf(1
#define ERROR
Definition elog.h:40
#define elog(elevel,...)
Definition elog.h:228
#define ereport(elevel,...)
Definition elog.h:152
struct SortSupportData * SortSupport
Definition execnodes.h:61
#define PG_RETURN_VOID()
Definition fmgr.h:350
#define PG_FREE_IF_COPY(ptr, n)
Definition fmgr.h:260
#define PG_GETARG_OID(n)
Definition fmgr.h:275
#define PG_GETARG_CHAR(n)
Definition fmgr.h:273
#define PG_GETARG_POINTER(n)
Definition fmgr.h:277
#define PG_RETURN_CSTRING(x)
Definition fmgr.h:364
#define PG_GETARG_DATUM(n)
Definition fmgr.h:268
#define PG_GETARG_CSTRING(n)
Definition fmgr.h:278
#define PG_GETARG_INT64(n)
Definition fmgr.h:284
#define PG_GETARG_NAME(n)
Definition fmgr.h:279
#define PG_GETARG_BPCHAR_PP(n)
Definition fmgr.h:311
#define PG_GETARG_VARCHAR_PP(n)
Definition fmgr.h:312
#define PG_RETURN_BPCHAR_P(x)
Definition fmgr.h:375
#define PG_RETURN_INT32(x)
Definition fmgr.h:355
#define PG_RETURN_NAME(x)
Definition fmgr.h:365
#define PG_GETARG_INT32(n)
Definition fmgr.h:269
#define PG_GETARG_BOOL(n)
Definition fmgr.h:274
#define PG_RETURN_POINTER(x)
Definition fmgr.h:363
#define PG_GET_COLLATION()
Definition fmgr.h:198
#define PG_RETURN_VARCHAR_P(x)
Definition fmgr.h:376
#define PG_FUNCTION_ARGS
Definition fmgr.h:193
#define PG_RETURN_BOOL(x)
Definition fmgr.h:360
static Datum hash_any_extended(const unsigned char *k, int keylen, uint64 seed)
Definition hashfn.h:37
static Datum hash_any(const unsigned char *k, int keylen)
Definition hashfn.h:31
const char * str
#define MaxAttrSize
int j
Definition isn.c:78
int i
Definition isn.c:77
int pg_mbstrlen_with_len(const char *mbstr, int limit)
Definition mbutils.c:1186
int pg_mbcharcliplen(const char *mbstr, int len, int limit)
Definition mbutils.c:1254
int pg_mbcliplen(const char *mbstr, int len, int limit)
Definition mbutils.c:1212
int pg_database_encoding_max_length(void)
Definition mbutils.c:1673
void pfree(void *pointer)
Definition mcxt.c:1619
void * palloc0(Size size)
Definition mcxt.c:1420
void * palloc(Size size)
Definition mcxt.c:1390
int32 exprTypmod(const Node *expr)
Definition nodeFuncs.c:304
Node * relabel_to_typmod(Node *expr, int32 typmod)
Definition nodeFuncs.c:694
#define IsA(nodeptr, _type_)
Definition nodes.h:164
static char * errmsg
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition palloc.h:138
#define NAMEDATALEN
const void size_t len
static int list_length(const List *l)
Definition pg_list.h:152
#define linitial(l)
Definition pg_list.h:178
#define lsecond(l)
Definition pg_list.h:183
size_t pg_strnxfrm(char *dest, size_t destsize, const char *src, size_t srclen, pg_locale_t locale)
Definition pg_locale.c:1454
pg_locale_t pg_newlocale_from_collation(Oid collid)
Definition pg_locale.c:1189
static rewind_source * source
Definition pg_rewind.c:89
static char buf[DEFAULT_XLOG_SEG_SIZE]
#define snprintf
Definition port.h:261
uint64_t Datum
Definition postgres.h:70
static int32 DatumGetInt32(Datum X)
Definition postgres.h:202
unsigned int Oid
char * pq_getmsgtext(StringInfo msg, int rawbytes, int *nbytes)
Definition pqformat.c:545
char * c
static int fb(int x)
static int cmp(const chr *x, const chr *y, size_t len)
struct StringInfoData * StringInfo
Definition string.h:15
List * args
Definition primnodes.h:801
Definition nodes.h:135
MemoryContext ssup_cxt
Definition sortsupport.h:66
Definition c.h:830
Definition c.h:776
static Size VARSIZE_ANY_EXHDR(const void *PTR)
Definition varatt.h:472
static char * VARDATA(const void *PTR)
Definition varatt.h:305
static char * VARDATA_ANY(const void *PTR)
Definition varatt.h:486
static void SET_VARSIZE(void *PTR, Size len)
Definition varatt.h:432
Datum bpcharrecv(PG_FUNCTION_ARGS)
Definition varchar.c:230
Datum bpcharne(PG_FUNCTION_ARGS)
Definition varchar.c:787
Datum varchar_support(PG_FUNCTION_ARGS)
Definition varchar.c:568
static int bcTruelen(BpChar *arg)
Definition varchar.c:673
Datum bpchar_larger(PG_FUNCTION_ARGS)
Definition varchar.c:950
Datum bpchar_pattern_lt(PG_FUNCTION_ARGS)
Definition varchar.c:1134
static BpChar * bpchar_input(const char *s, size_t len, int32 atttypmod, Node *escontext)
Definition varchar.c:130
Datum varcharrecv(PG_FUNCTION_ARGS)
Definition varchar.c:530
Datum varcharout(PG_FUNCTION_ARGS)
Definition varchar.c:519
int bpchartruelen(char *s, int len)
Definition varchar.c:679
Datum bpchar_pattern_le(PG_FUNCTION_ARGS)
Definition varchar.c:1150
Datum bpcharsend(PG_FUNCTION_ARGS)
Definition varchar.c:251
Datum varcharsend(PG_FUNCTION_ARGS)
Definition varchar.c:551
Datum bpcharlen(PG_FUNCTION_ARGS)
Definition varchar.c:696
Datum bpchar(PG_FUNCTION_ARGS)
Definition varchar.c:271
Datum name_bpchar(PG_FUNCTION_ARGS)
Definition varchar.c:410
Datum bpchar_sortsupport(PG_FUNCTION_ARGS)
Definition varchar.c:933
Datum bpchargt(PG_FUNCTION_ARGS)
Definition varchar.c:870
Datum btbpchar_pattern_sortsupport(PG_FUNCTION_ARGS)
Definition varchar.c:1214
static char * anychar_typmodout(int32 typmod)
Definition varchar.c:72
Datum bpcharge(PG_FUNCTION_ARGS)
Definition varchar.c:891
static int internal_bpchar_pattern_compare(BpChar *arg1, BpChar *arg2)
Definition varchar.c:1112
Datum bpchar_pattern_ge(PG_FUNCTION_ARGS)
Definition varchar.c:1166
static void check_collation_set(Oid collid)
Definition varchar.c:730
Datum bpchartypmodout(PG_FUNCTION_ARGS)
Definition varchar.c:428
Datum varcharin(PG_FUNCTION_ARGS)
Definition varchar.c:498
Datum bpchartypmodin(PG_FUNCTION_ARGS)
Definition varchar.c:420
static VarChar * varchar_input(const char *s, size_t len, int32 atttypmod, Node *escontext)
Definition varchar.c:460
Datum varchar(PG_FUNCTION_ARGS)
Definition varchar.c:612
Datum bpcharlt(PG_FUNCTION_ARGS)
Definition varchar.c:828
Datum hashbpcharextended(PG_FUNCTION_ARGS)
Definition varchar.c:1047
Datum bpchar_smaller(PG_FUNCTION_ARGS)
Definition varchar.c:968
Datum bpcharout(PG_FUNCTION_ARGS)
Definition varchar.c:219
static int32 anychar_typmodin(ArrayType *ta, const char *typename)
Definition varchar.c:33
Datum bpcharcmp(PG_FUNCTION_ARGS)
Definition varchar.c:912
Datum bpchareq(PG_FUNCTION_ARGS)
Definition varchar.c:746
Datum btbpchar_pattern_cmp(PG_FUNCTION_ARGS)
Definition varchar.c:1198
Datum bpchar_name(PG_FUNCTION_ARGS)
Definition varchar.c:373
Datum bpcharin(PG_FUNCTION_ARGS)
Definition varchar.c:198
Datum varchartypmodin(PG_FUNCTION_ARGS)
Definition varchar.c:651
Datum varchartypmodout(PG_FUNCTION_ARGS)
Definition varchar.c:659
Datum bpcharle(PG_FUNCTION_ARGS)
Definition varchar.c:849
Datum bpcharoctetlen(PG_FUNCTION_ARGS)
Definition varchar.c:712
Datum bpchar_pattern_gt(PG_FUNCTION_ARGS)
Definition varchar.c:1182
Datum char_bpchar(PG_FUNCTION_ARGS)
Definition varchar.c:354
Datum hashbpchar(PG_FUNCTION_ARGS)
Definition varchar.c:991
Datum textsend(PG_FUNCTION_ARGS)
Definition varlena.c:318
int varstr_cmp(const char *arg1, int len1, const char *arg2, int len2, Oid collid)
Definition varlena.c:1355
text * cstring_to_text_with_len(const char *s, int len)
Definition varlena.c:196
void varstr_sortsupport(SortSupport ssup, Oid typid, Oid collid)
Definition varlena.c:1672
text * cstring_to_text(const char *s)
Definition varlena.c:184