1 /*-------------------------------------------------------------------------
4 * Functions for the built-in types char(n) and varchar(n).
6 * Portions Copyright (c) 1996-2014, PostgreSQL Global Development Group
7 * Portions Copyright (c) 1994, Regents of the University of California
11 * src/backend/utils/adt/varchar.c
13 *-------------------------------------------------------------------------
18 #include "access/hash.h"
19 #include "access/tuptoaster.h"
20 #include "libpq/pqformat.h"
21 #include "nodes/nodeFuncs.h"
22 #include "utils/array.h"
23 #include "utils/builtins.h"
24 #include "mb/pg_wchar.h"
27 /* common code for bpchartypmodin and varchartypmodin */
29 anychar_typmodin(ArrayType *ta, const char *typename)
35 tl = ArrayGetIntegerTypmods(ta, &n);
38 * we're not too tense about good error message here because grammar
39 * shouldn't allow wrong number of modifiers for CHAR
43 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
44 errmsg("invalid type modifier")));
48 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
49 errmsg("length for type %s must be at least 1", typename)));
50 if (*tl > MaxAttrSize)
52 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
53 errmsg("length for type %s cannot exceed %d",
54 typename, MaxAttrSize)));
57 * For largely historical reasons, the typmod is VARHDRSZ plus the number
58 * of characters; there is enough client-side code that knows about that
59 * that we'd better not change it.
61 typmod = VARHDRSZ + *tl;
66 /* common code for bpchartypmodout and varchartypmodout */
68 anychar_typmodout(int32 typmod)
70 char *res = (char *) palloc(64);
72 if (typmod > VARHDRSZ)
73 snprintf(res, 64, "(%d)", (int) (typmod - VARHDRSZ));
82 * CHAR() and VARCHAR() types are part of the SQL standard. CHAR()
83 * is for blank-padded string whose length is specified in CREATE TABLE.
84 * VARCHAR is for storing string whose length is at most the length specified
85 * at CREATE TABLE time.
87 * It's hard to implement these types because we cannot figure out
88 * the length of the type from the type itself. I changed (hopefully all) the
89 * fmgr calls that invoke input functions of a data type to supply the
90 * length also. (eg. in INSERTs, we have the tupleDescriptor which contains
91 * the length of the attributes and hence the exact length of the char() or
92 * varchar(). We pass this to bpcharin() or varcharin().) In the case where
93 * we cannot determine the length, we pass in -1 instead and the input
94 * converter does not enforce any length check.
96 * We actually implement this as a varlena so that we don't have to pass in
97 * the length for the comparison functions. (The difference between these
98 * types and "text" is that we truncate and possibly blank-pad the string
105 /*****************************************************************************
107 *****************************************************************************/
110 * bpchar_input -- common guts of bpcharin and bpcharrecv
112 * s is the input text of length len (may not be null-terminated)
113 * atttypmod is the typmod value to apply
115 * Note that atttypmod is measured in characters, which
116 * is not necessarily the same as the number of bytes.
118 * If the input string is too long, raise an error, unless the extra
119 * characters are spaces, in which case they're truncated. (per SQL)
122 bpchar_input(const char *s, size_t len, int32 atttypmod)
128 /* If typmod is -1 (or invalid), use the actual string length */
129 if (atttypmod < (int32) VARHDRSZ)
133 size_t charlen; /* number of CHARACTERS in the input */
135 maxlen = atttypmod - VARHDRSZ;
136 charlen = pg_mbstrlen_with_len(s, len);
137 if (charlen > maxlen)
139 /* Verify that extra characters are spaces, and clip them off */
140 size_t mbmaxlen = pg_mbcharcliplen(s, len, maxlen);
144 * at this point, len is the actual BYTE length of the input
145 * string, maxlen is the max number of CHARACTERS allowed for this
146 * bpchar type, mbmaxlen is the length in BYTES of those chars.
148 for (j = mbmaxlen; j < len; j++)
152 (errcode(ERRCODE_STRING_DATA_RIGHT_TRUNCATION),
153 errmsg("value too long for type character(%d)",
158 * Now we set maxlen to the necessary byte length, not the number
161 maxlen = len = mbmaxlen;
166 * Now we set maxlen to the necessary byte length, not the number
169 maxlen = len + (maxlen - charlen);
173 result = (BpChar *) palloc(maxlen + VARHDRSZ);
174 SET_VARSIZE(result, maxlen + VARHDRSZ);
178 /* blank pad the string if necessary */
180 memset(r + len, ' ', maxlen - len);
186 * Convert a C string to CHARACTER internal representation. atttypmod
187 * is the declared length of the type plus VARHDRSZ.
190 bpcharin(PG_FUNCTION_ARGS)
192 char *s = PG_GETARG_CSTRING(0);
195 Oid typelem = PG_GETARG_OID(1);
197 int32 atttypmod = PG_GETARG_INT32(2);
200 result = bpchar_input(s, strlen(s), atttypmod);
201 PG_RETURN_BPCHAR_P(result);
206 * Convert a CHARACTER value to a C string.
208 * Uses the text conversion functions, which is only appropriate if BpChar
209 * and text are equivalent types.
212 bpcharout(PG_FUNCTION_ARGS)
214 Datum txt = PG_GETARG_DATUM(0);
216 PG_RETURN_CSTRING(TextDatumGetCString(txt));
220 * bpcharrecv - converts external binary format to bpchar
223 bpcharrecv(PG_FUNCTION_ARGS)
225 StringInfo buf = (StringInfo) PG_GETARG_POINTER(0);
228 Oid typelem = PG_GETARG_OID(1);
230 int32 atttypmod = PG_GETARG_INT32(2);
235 str = pq_getmsgtext(buf, buf->len - buf->cursor, &nbytes);
236 result = bpchar_input(str, nbytes, atttypmod);
238 PG_RETURN_BPCHAR_P(result);
242 * bpcharsend - converts bpchar to binary format
245 bpcharsend(PG_FUNCTION_ARGS)
247 /* Exactly the same as textsend, so share code */
248 return textsend(fcinfo);
253 * Converts a CHARACTER type to the specified size.
255 * maxlen is the typmod, ie, declared length plus VARHDRSZ bytes.
256 * isExplicit is true if this is for an explicit cast to char(N).
258 * Truncation rules: for an explicit cast, silently truncate to the given
259 * length; for an implicit cast, raise error unless extra characters are
260 * all spaces. (This is sort-of per SQL: the spec would actually have us
261 * raise a "completion condition" for the explicit cast case, but Postgres
262 * hasn't got such a concept.)
265 bpchar(PG_FUNCTION_ARGS)
267 BpChar *source = PG_GETARG_BPCHAR_PP(0);
268 int32 maxlen = PG_GETARG_INT32(1);
269 bool isExplicit = PG_GETARG_BOOL(2);
275 int charlen; /* number of characters in the input string +
278 /* No work if typmod is invalid */
279 if (maxlen < (int32) VARHDRSZ)
280 PG_RETURN_BPCHAR_P(source);
284 len = VARSIZE_ANY_EXHDR(source);
285 s = VARDATA_ANY(source);
287 charlen = pg_mbstrlen_with_len(s, len);
289 /* No work if supplied data matches typmod already */
290 if (charlen == maxlen)
291 PG_RETURN_BPCHAR_P(source);
293 if (charlen > maxlen)
295 /* Verify that extra characters are spaces, and clip them off */
298 maxmblen = pg_mbcharcliplen(s, len, maxlen);
302 for (i = maxmblen; i < len; i++)
305 (errcode(ERRCODE_STRING_DATA_RIGHT_TRUNCATION),
306 errmsg("value too long for type character(%d)",
313 * At this point, maxlen is the necessary byte length, not the number
321 * At this point, maxlen is the necessary byte length, not the number
324 maxlen = len + (maxlen - charlen);
327 Assert(maxlen >= len);
329 result = palloc(maxlen + VARHDRSZ);
330 SET_VARSIZE(result, maxlen + VARHDRSZ);
335 /* blank pad the string if necessary */
337 memset(r + len, ' ', maxlen - len);
339 PG_RETURN_BPCHAR_P(result);
344 * Convert char to bpchar(1).
347 char_bpchar(PG_FUNCTION_ARGS)
349 char c = PG_GETARG_CHAR(0);
352 result = (BpChar *) palloc(VARHDRSZ + 1);
354 SET_VARSIZE(result, VARHDRSZ + 1);
355 *(VARDATA(result)) = c;
357 PG_RETURN_BPCHAR_P(result);
362 * Converts a bpchar() type to a NameData type.
365 bpchar_name(PG_FUNCTION_ARGS)
367 BpChar *s = PG_GETARG_BPCHAR_PP(0);
372 len = VARSIZE_ANY_EXHDR(s);
373 s_data = VARDATA_ANY(s);
375 /* Truncate oversize input */
376 if (len >= NAMEDATALEN)
377 len = pg_mbcliplen(s_data, len, NAMEDATALEN - 1);
379 /* Remove trailing blanks */
382 if (s_data[len - 1] != ' ')
387 /* We use palloc0 here to ensure result is zero-padded */
388 result = (Name) palloc0(NAMEDATALEN);
389 memcpy(NameStr(*result), s_data, len);
391 PG_RETURN_NAME(result);
395 * Converts a NameData type to a bpchar type.
397 * Uses the text conversion functions, which is only appropriate if BpChar
398 * and text are equivalent types.
401 name_bpchar(PG_FUNCTION_ARGS)
403 Name s = PG_GETARG_NAME(0);
406 result = (BpChar *) cstring_to_text(NameStr(*s));
407 PG_RETURN_BPCHAR_P(result);
411 bpchartypmodin(PG_FUNCTION_ARGS)
413 ArrayType *ta = PG_GETARG_ARRAYTYPE_P(0);
415 PG_RETURN_INT32(anychar_typmodin(ta, "char"));
419 bpchartypmodout(PG_FUNCTION_ARGS)
421 int32 typmod = PG_GETARG_INT32(0);
423 PG_RETURN_CSTRING(anychar_typmodout(typmod));
427 /*****************************************************************************
428 * varchar - varchar(n)
430 * Note: varchar piggybacks on type text for most operations, and so has no
431 * C-coded functions except for I/O and typmod checking.
432 *****************************************************************************/
435 * varchar_input -- common guts of varcharin and varcharrecv
437 * s is the input text of length len (may not be null-terminated)
438 * atttypmod is the typmod value to apply
440 * Note that atttypmod is measured in characters, which
441 * is not necessarily the same as the number of bytes.
443 * If the input string is too long, raise an error, unless the extra
444 * characters are spaces, in which case they're truncated. (per SQL)
446 * Uses the C string to text conversion function, which is only appropriate
447 * if VarChar and text are equivalent types.
450 varchar_input(const char *s, size_t len, int32 atttypmod)
455 maxlen = atttypmod - VARHDRSZ;
457 if (atttypmod >= (int32) VARHDRSZ && len > maxlen)
459 /* Verify that extra characters are spaces, and clip them off */
460 size_t mbmaxlen = pg_mbcharcliplen(s, len, maxlen);
463 for (j = mbmaxlen; j < len; j++)
467 (errcode(ERRCODE_STRING_DATA_RIGHT_TRUNCATION),
468 errmsg("value too long for type character varying(%d)",
475 result = (VarChar *) cstring_to_text_with_len(s, len);
480 * Convert a C string to VARCHAR internal representation. atttypmod
481 * is the declared length of the type plus VARHDRSZ.
484 varcharin(PG_FUNCTION_ARGS)
486 char *s = PG_GETARG_CSTRING(0);
489 Oid typelem = PG_GETARG_OID(1);
491 int32 atttypmod = PG_GETARG_INT32(2);
494 result = varchar_input(s, strlen(s), atttypmod);
495 PG_RETURN_VARCHAR_P(result);
500 * Convert a VARCHAR value to a C string.
502 * Uses the text to C string conversion function, which is only appropriate
503 * if VarChar and text are equivalent types.
506 varcharout(PG_FUNCTION_ARGS)
508 Datum txt = PG_GETARG_DATUM(0);
510 PG_RETURN_CSTRING(TextDatumGetCString(txt));
514 * varcharrecv - converts external binary format to varchar
517 varcharrecv(PG_FUNCTION_ARGS)
519 StringInfo buf = (StringInfo) PG_GETARG_POINTER(0);
522 Oid typelem = PG_GETARG_OID(1);
524 int32 atttypmod = PG_GETARG_INT32(2);
529 str = pq_getmsgtext(buf, buf->len - buf->cursor, &nbytes);
530 result = varchar_input(str, nbytes, atttypmod);
532 PG_RETURN_VARCHAR_P(result);
536 * varcharsend - converts varchar to binary format
539 varcharsend(PG_FUNCTION_ARGS)
541 /* Exactly the same as textsend, so share code */
542 return textsend(fcinfo);
547 * varchar_transform()
548 * Flatten calls to varchar's length coercion function that set the new maximum
549 * length >= the previous maximum length. We can ignore the isExplicit
550 * argument, since that only affects truncation cases.
553 varchar_transform(PG_FUNCTION_ARGS)
555 FuncExpr *expr = (FuncExpr *) PG_GETARG_POINTER(0);
559 Assert(IsA(expr, FuncExpr));
560 Assert(list_length(expr->args) >= 2);
562 typmod = (Node *) lsecond(expr->args);
564 if (IsA(typmod, Const) &&!((Const *) typmod)->constisnull)
566 Node *source = (Node *) linitial(expr->args);
567 int32 old_typmod = exprTypmod(source);
568 int32 new_typmod = DatumGetInt32(((Const *) typmod)->constvalue);
569 int32 old_max = old_typmod - VARHDRSZ;
570 int32 new_max = new_typmod - VARHDRSZ;
572 if (new_typmod < 0 || (old_typmod >= 0 && old_max <= new_max))
573 ret = relabel_to_typmod(source, new_typmod);
576 PG_RETURN_POINTER(ret);
580 * Converts a VARCHAR type to the specified size.
582 * maxlen is the typmod, ie, declared length plus VARHDRSZ bytes.
583 * isExplicit is true if this is for an explicit cast to varchar(N).
585 * Truncation rules: for an explicit cast, silently truncate to the given
586 * length; for an implicit cast, raise error unless extra characters are
587 * all spaces. (This is sort-of per SQL: the spec would actually have us
588 * raise a "completion condition" for the explicit cast case, but Postgres
589 * hasn't got such a concept.)
592 varchar(PG_FUNCTION_ARGS)
594 VarChar *source = PG_GETARG_VARCHAR_PP(0);
595 int32 typmod = PG_GETARG_INT32(1);
596 bool isExplicit = PG_GETARG_BOOL(2);
603 len = VARSIZE_ANY_EXHDR(source);
604 s_data = VARDATA_ANY(source);
605 maxlen = typmod - VARHDRSZ;
607 /* No work if typmod is invalid or supplied data fits it already */
608 if (maxlen < 0 || len <= maxlen)
609 PG_RETURN_VARCHAR_P(source);
611 /* only reach here if string is too long... */
613 /* truncate multibyte string preserving multibyte boundary */
614 maxmblen = pg_mbcharcliplen(s_data, len, maxlen);
618 for (i = maxmblen; i < len; i++)
619 if (s_data[i] != ' ')
621 (errcode(ERRCODE_STRING_DATA_RIGHT_TRUNCATION),
622 errmsg("value too long for type character varying(%d)",
626 PG_RETURN_VARCHAR_P((VarChar *) cstring_to_text_with_len(s_data,
631 varchartypmodin(PG_FUNCTION_ARGS)
633 ArrayType *ta = PG_GETARG_ARRAYTYPE_P(0);
635 PG_RETURN_INT32(anychar_typmodin(ta, "varchar"));
639 varchartypmodout(PG_FUNCTION_ARGS)
641 int32 typmod = PG_GETARG_INT32(0);
643 PG_RETURN_CSTRING(anychar_typmodout(typmod));
647 /*****************************************************************************
649 *****************************************************************************/
651 /* "True" length (not counting trailing blanks) of a BpChar */
653 bcTruelen(BpChar *arg)
655 char *s = VARDATA_ANY(arg);
659 len = VARSIZE_ANY_EXHDR(arg);
660 for (i = len - 1; i >= 0; i--)
669 bpcharlen(PG_FUNCTION_ARGS)
671 BpChar *arg = PG_GETARG_BPCHAR_PP(0);
674 /* get number of bytes, ignoring trailing spaces */
675 len = bcTruelen(arg);
677 /* in multibyte encoding, convert to number of characters */
678 if (pg_database_encoding_max_length() != 1)
679 len = pg_mbstrlen_with_len(VARDATA_ANY(arg), len);
681 PG_RETURN_INT32(len);
685 bpcharoctetlen(PG_FUNCTION_ARGS)
687 Datum arg = PG_GETARG_DATUM(0);
689 /* We need not detoast the input at all */
690 PG_RETURN_INT32(toast_raw_datum_size(arg) - VARHDRSZ);
694 /*****************************************************************************
695 * Comparison Functions used for bpchar
697 * Note: btree indexes need these routines not to leak memory; therefore,
698 * be careful to free working copies of toasted datums. Most places don't
699 * need to be so careful.
700 *****************************************************************************/
703 bpchareq(PG_FUNCTION_ARGS)
705 BpChar *arg1 = PG_GETARG_BPCHAR_PP(0);
706 BpChar *arg2 = PG_GETARG_BPCHAR_PP(1);
711 len1 = bcTruelen(arg1);
712 len2 = bcTruelen(arg2);
715 * Since we only care about equality or not-equality, we can avoid all the
716 * expense of strcoll() here, and just do bitwise comparison.
721 result = (memcmp(VARDATA_ANY(arg1), VARDATA_ANY(arg2), len1) == 0);
723 PG_FREE_IF_COPY(arg1, 0);
724 PG_FREE_IF_COPY(arg2, 1);
726 PG_RETURN_BOOL(result);
730 bpcharne(PG_FUNCTION_ARGS)
732 BpChar *arg1 = PG_GETARG_BPCHAR_PP(0);
733 BpChar *arg2 = PG_GETARG_BPCHAR_PP(1);
738 len1 = bcTruelen(arg1);
739 len2 = bcTruelen(arg2);
742 * Since we only care about equality or not-equality, we can avoid all the
743 * expense of strcoll() here, and just do bitwise comparison.
748 result = (memcmp(VARDATA_ANY(arg1), VARDATA_ANY(arg2), len1) != 0);
750 PG_FREE_IF_COPY(arg1, 0);
751 PG_FREE_IF_COPY(arg2, 1);
753 PG_RETURN_BOOL(result);
757 bpcharlt(PG_FUNCTION_ARGS)
759 BpChar *arg1 = PG_GETARG_BPCHAR_PP(0);
760 BpChar *arg2 = PG_GETARG_BPCHAR_PP(1);
765 len1 = bcTruelen(arg1);
766 len2 = bcTruelen(arg2);
768 cmp = varstr_cmp(VARDATA_ANY(arg1), len1, VARDATA_ANY(arg2), len2,
771 PG_FREE_IF_COPY(arg1, 0);
772 PG_FREE_IF_COPY(arg2, 1);
774 PG_RETURN_BOOL(cmp < 0);
778 bpcharle(PG_FUNCTION_ARGS)
780 BpChar *arg1 = PG_GETARG_BPCHAR_PP(0);
781 BpChar *arg2 = PG_GETARG_BPCHAR_PP(1);
786 len1 = bcTruelen(arg1);
787 len2 = bcTruelen(arg2);
789 cmp = varstr_cmp(VARDATA_ANY(arg1), len1, VARDATA_ANY(arg2), len2,
792 PG_FREE_IF_COPY(arg1, 0);
793 PG_FREE_IF_COPY(arg2, 1);
795 PG_RETURN_BOOL(cmp <= 0);
799 bpchargt(PG_FUNCTION_ARGS)
801 BpChar *arg1 = PG_GETARG_BPCHAR_PP(0);
802 BpChar *arg2 = PG_GETARG_BPCHAR_PP(1);
807 len1 = bcTruelen(arg1);
808 len2 = bcTruelen(arg2);
810 cmp = varstr_cmp(VARDATA_ANY(arg1), len1, VARDATA_ANY(arg2), len2,
813 PG_FREE_IF_COPY(arg1, 0);
814 PG_FREE_IF_COPY(arg2, 1);
816 PG_RETURN_BOOL(cmp > 0);
820 bpcharge(PG_FUNCTION_ARGS)
822 BpChar *arg1 = PG_GETARG_BPCHAR_PP(0);
823 BpChar *arg2 = PG_GETARG_BPCHAR_PP(1);
828 len1 = bcTruelen(arg1);
829 len2 = bcTruelen(arg2);
831 cmp = varstr_cmp(VARDATA_ANY(arg1), len1, VARDATA_ANY(arg2), len2,
834 PG_FREE_IF_COPY(arg1, 0);
835 PG_FREE_IF_COPY(arg2, 1);
837 PG_RETURN_BOOL(cmp >= 0);
841 bpcharcmp(PG_FUNCTION_ARGS)
843 BpChar *arg1 = PG_GETARG_BPCHAR_PP(0);
844 BpChar *arg2 = PG_GETARG_BPCHAR_PP(1);
850 * Trimming trailing spaces off of both strings can cause a string
851 * with a character less than a space to compare greater than a
852 * space-extended string, e.g. this returns false:
853 * SELECT E'ab\n'::CHAR(10) < E'ab '::CHAR(10);
854 * even though '\n' is less than the space if CHAR(10) was
855 * space-extended. The correct solution would be to trim only
856 * the longer string to be the same length of the shorter, if
857 * possible, then do the comparison. However, changing this
858 * might break existing indexes, breaking binary upgrades.
859 * For details, see http://www.postgresql.org/message-id/CAK+WP1xdmyswEehMuetNztM4H199Z1w9KWRHVMKzyyFM+hV=zA@mail.gmail.com
861 len1 = bcTruelen(arg1);
862 len2 = bcTruelen(arg2);
864 cmp = varstr_cmp(VARDATA_ANY(arg1), len1, VARDATA_ANY(arg2), len2,
867 PG_FREE_IF_COPY(arg1, 0);
868 PG_FREE_IF_COPY(arg2, 1);
870 PG_RETURN_INT32(cmp);
874 bpchar_larger(PG_FUNCTION_ARGS)
876 BpChar *arg1 = PG_GETARG_BPCHAR_PP(0);
877 BpChar *arg2 = PG_GETARG_BPCHAR_PP(1);
882 len1 = bcTruelen(arg1);
883 len2 = bcTruelen(arg2);
885 cmp = varstr_cmp(VARDATA_ANY(arg1), len1, VARDATA_ANY(arg2), len2,
888 PG_RETURN_BPCHAR_P((cmp >= 0) ? arg1 : arg2);
892 bpchar_smaller(PG_FUNCTION_ARGS)
894 BpChar *arg1 = PG_GETARG_BPCHAR_PP(0);
895 BpChar *arg2 = PG_GETARG_BPCHAR_PP(1);
900 len1 = bcTruelen(arg1);
901 len2 = bcTruelen(arg2);
903 cmp = varstr_cmp(VARDATA_ANY(arg1), len1, VARDATA_ANY(arg2), len2,
906 PG_RETURN_BPCHAR_P((cmp <= 0) ? arg1 : arg2);
911 * bpchar needs a specialized hash function because we want to ignore
912 * trailing blanks in comparisons.
914 * Note: currently there is no need for locale-specific behavior here,
915 * but if we ever change the semantics of bpchar comparison to trust
916 * strcoll() completely, we'd need to do something different in non-C locales.
919 hashbpchar(PG_FUNCTION_ARGS)
921 BpChar *key = PG_GETARG_BPCHAR_PP(0);
926 keydata = VARDATA_ANY(key);
927 keylen = bcTruelen(key);
929 result = hash_any((unsigned char *) keydata, keylen);
931 /* Avoid leaking memory for toasted inputs */
932 PG_FREE_IF_COPY(key, 0);
939 * The following operators support character-by-character comparison
940 * of bpchar datums, to allow building indexes suitable for LIKE clauses.
941 * Note that the regular bpchareq/bpcharne comparison operators are assumed
942 * to be compatible with these!
946 internal_bpchar_pattern_compare(BpChar *arg1, BpChar *arg2)
952 len1 = bcTruelen(arg1);
953 len2 = bcTruelen(arg2);
955 result = memcmp(VARDATA_ANY(arg1), VARDATA_ANY(arg2), Min(len1, len2));
958 else if (len1 < len2)
960 else if (len1 > len2)
968 bpchar_pattern_lt(PG_FUNCTION_ARGS)
970 BpChar *arg1 = PG_GETARG_BPCHAR_PP(0);
971 BpChar *arg2 = PG_GETARG_BPCHAR_PP(1);
974 result = internal_bpchar_pattern_compare(arg1, arg2);
976 PG_FREE_IF_COPY(arg1, 0);
977 PG_FREE_IF_COPY(arg2, 1);
979 PG_RETURN_BOOL(result < 0);
984 bpchar_pattern_le(PG_FUNCTION_ARGS)
986 BpChar *arg1 = PG_GETARG_BPCHAR_PP(0);
987 BpChar *arg2 = PG_GETARG_BPCHAR_PP(1);
990 result = internal_bpchar_pattern_compare(arg1, arg2);
992 PG_FREE_IF_COPY(arg1, 0);
993 PG_FREE_IF_COPY(arg2, 1);
995 PG_RETURN_BOOL(result <= 0);
1000 bpchar_pattern_ge(PG_FUNCTION_ARGS)
1002 BpChar *arg1 = PG_GETARG_BPCHAR_PP(0);
1003 BpChar *arg2 = PG_GETARG_BPCHAR_PP(1);
1006 result = internal_bpchar_pattern_compare(arg1, arg2);
1008 PG_FREE_IF_COPY(arg1, 0);
1009 PG_FREE_IF_COPY(arg2, 1);
1011 PG_RETURN_BOOL(result >= 0);
1016 bpchar_pattern_gt(PG_FUNCTION_ARGS)
1018 BpChar *arg1 = PG_GETARG_BPCHAR_PP(0);
1019 BpChar *arg2 = PG_GETARG_BPCHAR_PP(1);
1022 result = internal_bpchar_pattern_compare(arg1, arg2);
1024 PG_FREE_IF_COPY(arg1, 0);
1025 PG_FREE_IF_COPY(arg2, 1);
1027 PG_RETURN_BOOL(result > 0);
1032 btbpchar_pattern_cmp(PG_FUNCTION_ARGS)
1034 BpChar *arg1 = PG_GETARG_BPCHAR_PP(0);
1035 BpChar *arg2 = PG_GETARG_BPCHAR_PP(1);
1038 result = internal_bpchar_pattern_compare(arg1, arg2);
1040 PG_FREE_IF_COPY(arg1, 0);
1041 PG_FREE_IF_COPY(arg2, 1);
1043 PG_RETURN_INT32(result);