PostgreSQL Source Code  git master
varchar.c File Reference
#include "postgres.h"
#include "access/detoast.h"
#include "access/htup_details.h"
#include "catalog/pg_collation.h"
#include "catalog/pg_type.h"
#include "common/hashfn.h"
#include "libpq/pqformat.h"
#include "mb/pg_wchar.h"
#include "nodes/nodeFuncs.h"
#include "nodes/supportnodes.h"
#include "utils/array.h"
#include "utils/builtins.h"
#include "utils/lsyscache.h"
#include "utils/pg_locale.h"
#include "utils/varlena.h"
Include dependency graph for varchar.c:

Go to the source code of this file.

Functions

static int32 anychar_typmodin (ArrayType *ta, const char *typename)
 
static char * anychar_typmodout (int32 typmod)
 
static BpCharbpchar_input (const char *s, size_t len, int32 atttypmod)
 
Datum bpcharin (PG_FUNCTION_ARGS)
 
Datum bpcharout (PG_FUNCTION_ARGS)
 
Datum bpcharrecv (PG_FUNCTION_ARGS)
 
Datum bpcharsend (PG_FUNCTION_ARGS)
 
Datum bpchar (PG_FUNCTION_ARGS)
 
Datum char_bpchar (PG_FUNCTION_ARGS)
 
Datum bpchar_name (PG_FUNCTION_ARGS)
 
Datum name_bpchar (PG_FUNCTION_ARGS)
 
Datum bpchartypmodin (PG_FUNCTION_ARGS)
 
Datum bpchartypmodout (PG_FUNCTION_ARGS)
 
static VarCharvarchar_input (const char *s, size_t len, int32 atttypmod)
 
Datum varcharin (PG_FUNCTION_ARGS)
 
Datum varcharout (PG_FUNCTION_ARGS)
 
Datum varcharrecv (PG_FUNCTION_ARGS)
 
Datum varcharsend (PG_FUNCTION_ARGS)
 
Datum varchar_support (PG_FUNCTION_ARGS)
 
Datum varchar (PG_FUNCTION_ARGS)
 
Datum varchartypmodin (PG_FUNCTION_ARGS)
 
Datum varchartypmodout (PG_FUNCTION_ARGS)
 
static int bcTruelen (BpChar *arg)
 
int bpchartruelen (char *s, int len)
 
Datum bpcharlen (PG_FUNCTION_ARGS)
 
Datum bpcharoctetlen (PG_FUNCTION_ARGS)
 
static void check_collation_set (Oid collid)
 
Datum bpchareq (PG_FUNCTION_ARGS)
 
Datum bpcharne (PG_FUNCTION_ARGS)
 
Datum bpcharlt (PG_FUNCTION_ARGS)
 
Datum bpcharle (PG_FUNCTION_ARGS)
 
Datum bpchargt (PG_FUNCTION_ARGS)
 
Datum bpcharge (PG_FUNCTION_ARGS)
 
Datum bpcharcmp (PG_FUNCTION_ARGS)
 
Datum bpchar_sortsupport (PG_FUNCTION_ARGS)
 
Datum bpchar_larger (PG_FUNCTION_ARGS)
 
Datum bpchar_smaller (PG_FUNCTION_ARGS)
 
Datum hashbpchar (PG_FUNCTION_ARGS)
 
Datum hashbpcharextended (PG_FUNCTION_ARGS)
 
static int internal_bpchar_pattern_compare (BpChar *arg1, BpChar *arg2)
 
Datum bpchar_pattern_lt (PG_FUNCTION_ARGS)
 
Datum bpchar_pattern_le (PG_FUNCTION_ARGS)
 
Datum bpchar_pattern_ge (PG_FUNCTION_ARGS)
 
Datum bpchar_pattern_gt (PG_FUNCTION_ARGS)
 
Datum btbpchar_pattern_cmp (PG_FUNCTION_ARGS)
 
Datum btbpchar_pattern_sortsupport (PG_FUNCTION_ARGS)
 

Function Documentation

◆ anychar_typmodin()

static int32 anychar_typmodin ( ArrayType ta,
const char *  typename 
)
static

Definition at line 34 of file varchar.c.

35 {
36  int32 typmod;
37  int32 *tl;
38  int n;
39 
40  tl = ArrayGetIntegerTypmods(ta, &n);
41 
42  /*
43  * we're not too tense about good error message here because grammar
44  * shouldn't allow wrong number of modifiers for CHAR
45  */
46  if (n != 1)
47  ereport(ERROR,
48  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
49  errmsg("invalid type modifier")));
50 
51  if (*tl < 1)
52  ereport(ERROR,
53  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
54  errmsg("length for type %s must be at least 1", typename)));
55  if (*tl > MaxAttrSize)
56  ereport(ERROR,
57  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
58  errmsg("length for type %s cannot exceed %d",
59  typename, MaxAttrSize)));
60 
61  /*
62  * For largely historical reasons, the typmod is VARHDRSZ plus the number
63  * of characters; there is enough client-side code that knows about that
64  * that we'd better not change it.
65  */
66  typmod = VARHDRSZ + *tl;
67 
68  return typmod;
69 }
int32 * ArrayGetIntegerTypmods(ArrayType *arr, int *n)
Definition: arrayutils.c:231
signed int int32
Definition: c.h:430
#define VARHDRSZ
Definition: c.h:628
int errcode(int sqlerrcode)
Definition: elog.c:735
int errmsg(const char *fmt,...)
Definition: elog.c:946
#define ERROR
Definition: elog.h:35
#define ereport(elevel,...)
Definition: elog.h:145
#define MaxAttrSize
Definition: htup_details.h:579

References ArrayGetIntegerTypmods(), ereport, errcode(), errmsg(), ERROR, MaxAttrSize, and VARHDRSZ.

Referenced by bpchartypmodin(), and varchartypmodin().

◆ anychar_typmodout()

static char* anychar_typmodout ( int32  typmod)
static

Definition at line 73 of file varchar.c.

74 {
75  char *res = (char *) palloc(64);
76 
77  if (typmod > VARHDRSZ)
78  snprintf(res, 64, "(%d)", (int) (typmod - VARHDRSZ));
79  else
80  *res = '\0';
81 
82  return res;
83 }
void * palloc(Size size)
Definition: mcxt.c:1199
#define snprintf
Definition: port.h:238

References palloc(), res, snprintf, and VARHDRSZ.

Referenced by bpchartypmodout(), and varchartypmodout().

◆ bcTruelen()

static int bcTruelen ( BpChar arg)
inlinestatic

Definition at line 666 of file varchar.c.

667 {
669 }
void * arg
#define VARDATA_ANY(PTR)
Definition: postgres.h:362
#define VARSIZE_ANY_EXHDR(PTR)
Definition: postgres.h:355
int bpchartruelen(char *s, int len)
Definition: varchar.c:672

References arg, bpchartruelen(), VARDATA_ANY, and VARSIZE_ANY_EXHDR.

Referenced by bpchar_larger(), bpchar_smaller(), bpcharcmp(), bpchareq(), bpcharge(), bpchargt(), bpcharle(), bpcharlen(), bpcharlt(), bpcharne(), hashbpchar(), hashbpcharextended(), and internal_bpchar_pattern_compare().

◆ bpchar()

Datum bpchar ( PG_FUNCTION_ARGS  )

Definition at line 270 of file varchar.c.

271 {
273  int32 maxlen = PG_GETARG_INT32(1);
274  bool isExplicit = PG_GETARG_BOOL(2);
275  BpChar *result;
276  int32 len;
277  char *r;
278  char *s;
279  int i;
280  int charlen; /* number of characters in the input string +
281  * VARHDRSZ */
282 
283  /* No work if typmod is invalid */
284  if (maxlen < (int32) VARHDRSZ)
286 
287  maxlen -= VARHDRSZ;
288 
290  s = VARDATA_ANY(source);
291 
292  charlen = pg_mbstrlen_with_len(s, len);
293 
294  /* No work if supplied data matches typmod already */
295  if (charlen == maxlen)
297 
298  if (charlen > maxlen)
299  {
300  /* Verify that extra characters are spaces, and clip them off */
301  size_t maxmblen;
302 
303  maxmblen = pg_mbcharcliplen(s, len, maxlen);
304 
305  if (!isExplicit)
306  {
307  for (i = maxmblen; i < len; i++)
308  if (s[i] != ' ')
309  ereport(ERROR,
310  (errcode(ERRCODE_STRING_DATA_RIGHT_TRUNCATION),
311  errmsg("value too long for type character(%d)",
312  maxlen)));
313  }
314 
315  len = maxmblen;
316 
317  /*
318  * At this point, maxlen is the necessary byte length, not the number
319  * of CHARACTERS!
320  */
321  maxlen = len;
322  }
323  else
324  {
325  /*
326  * At this point, maxlen is the necessary byte length, not the number
327  * of CHARACTERS!
328  */
329  maxlen = len + (maxlen - charlen);
330  }
331 
332  Assert(maxlen >= len);
333 
334  result = palloc(maxlen + VARHDRSZ);
335  SET_VARSIZE(result, maxlen + VARHDRSZ);
336  r = VARDATA(result);
337 
338  memcpy(r, s, len);
339 
340  /* blank pad the string if necessary */
341  if (maxlen > len)
342  memset(r + len, ' ', maxlen - len);
343 
344  PG_RETURN_BPCHAR_P(result);
345 }
#define PG_GETARG_BPCHAR_PP(n)
Definition: fmgr.h:310
#define PG_RETURN_BPCHAR_P(x)
Definition: fmgr.h:373
#define PG_GETARG_INT32(n)
Definition: fmgr.h:269
#define PG_GETARG_BOOL(n)
Definition: fmgr.h:274
int i
Definition: isn.c:73
Assert(fmt[strlen(fmt) - 1] !='\n')
int pg_mbstrlen_with_len(const char *mbstr, int limit)
Definition: mbutils.c:1000
int pg_mbcharcliplen(const char *mbstr, int len, int limit)
Definition: mbutils.c:1068
const void size_t len
static rewind_source * source
Definition: pg_rewind.c:81
#define VARDATA(PTR)
Definition: postgres.h:316
#define SET_VARSIZE(PTR, len)
Definition: postgres.h:343
Definition: c.h:623

References Assert(), ereport, errcode(), errmsg(), ERROR, i, len, palloc(), PG_GETARG_BOOL, PG_GETARG_BPCHAR_PP, PG_GETARG_INT32, pg_mbcharcliplen(), pg_mbstrlen_with_len(), PG_RETURN_BPCHAR_P, SET_VARSIZE, source, VARDATA, VARDATA_ANY, VARHDRSZ, and VARSIZE_ANY_EXHDR.

◆ bpchar_input()

static BpChar* bpchar_input ( const char *  s,
size_t  len,
int32  atttypmod 
)
static

Definition at line 127 of file varchar.c.

128 {
129  BpChar *result;
130  char *r;
131  size_t maxlen;
132 
133  /* If typmod is -1 (or invalid), use the actual string length */
134  if (atttypmod < (int32) VARHDRSZ)
135  maxlen = len;
136  else
137  {
138  size_t charlen; /* number of CHARACTERS in the input */
139 
140  maxlen = atttypmod - VARHDRSZ;
141  charlen = pg_mbstrlen_with_len(s, len);
142  if (charlen > maxlen)
143  {
144  /* Verify that extra characters are spaces, and clip them off */
145  size_t mbmaxlen = pg_mbcharcliplen(s, len, maxlen);
146  size_t j;
147 
148  /*
149  * at this point, len is the actual BYTE length of the input
150  * string, maxlen is the max number of CHARACTERS allowed for this
151  * bpchar type, mbmaxlen is the length in BYTES of those chars.
152  */
153  for (j = mbmaxlen; j < len; j++)
154  {
155  if (s[j] != ' ')
156  ereport(ERROR,
157  (errcode(ERRCODE_STRING_DATA_RIGHT_TRUNCATION),
158  errmsg("value too long for type character(%d)",
159  (int) maxlen)));
160  }
161 
162  /*
163  * Now we set maxlen to the necessary byte length, not the number
164  * of CHARACTERS!
165  */
166  maxlen = len = mbmaxlen;
167  }
168  else
169  {
170  /*
171  * Now we set maxlen to the necessary byte length, not the number
172  * of CHARACTERS!
173  */
174  maxlen = len + (maxlen - charlen);
175  }
176  }
177 
178  result = (BpChar *) palloc(maxlen + VARHDRSZ);
179  SET_VARSIZE(result, maxlen + VARHDRSZ);
180  r = VARDATA(result);
181  memcpy(r, s, len);
182 
183  /* blank pad the string if necessary */
184  if (maxlen > len)
185  memset(r + len, ' ', maxlen - len);
186 
187  return result;
188 }
int j
Definition: isn.c:74

References ereport, errcode(), errmsg(), ERROR, j, len, palloc(), pg_mbcharcliplen(), pg_mbstrlen_with_len(), SET_VARSIZE, VARDATA, and VARHDRSZ.

Referenced by bpcharin(), and bpcharrecv().

◆ bpchar_larger()

Datum bpchar_larger ( PG_FUNCTION_ARGS  )

Definition at line 951 of file varchar.c.

952 {
953  BpChar *arg1 = PG_GETARG_BPCHAR_PP(0);
954  BpChar *arg2 = PG_GETARG_BPCHAR_PP(1);
955  int len1,
956  len2;
957  int cmp;
958 
959  len1 = bcTruelen(arg1);
960  len2 = bcTruelen(arg2);
961 
962  cmp = varstr_cmp(VARDATA_ANY(arg1), len1, VARDATA_ANY(arg2), len2,
963  PG_GET_COLLATION());
964 
965  PG_RETURN_BPCHAR_P((cmp >= 0) ? arg1 : arg2);
966 }
#define PG_GET_COLLATION()
Definition: fmgr.h:198
static int cmp(const chr *x, const chr *y, size_t len)
Definition: regc_locale.c:747
static int bcTruelen(BpChar *arg)
Definition: varchar.c:666
int varstr_cmp(const char *arg1, int len1, const char *arg2, int len2, Oid collid)
Definition: varlena.c:1518

References bcTruelen(), cmp(), PG_GET_COLLATION, PG_GETARG_BPCHAR_PP, PG_RETURN_BPCHAR_P, VARDATA_ANY, and varstr_cmp().

◆ bpchar_name()

Datum bpchar_name ( PG_FUNCTION_ARGS  )

Definition at line 370 of file varchar.c.

371 {
372  BpChar *s = PG_GETARG_BPCHAR_PP(0);
373  char *s_data;
374  Name result;
375  int len;
376 
377  len = VARSIZE_ANY_EXHDR(s);
378  s_data = VARDATA_ANY(s);
379 
380  /* Truncate oversize input */
381  if (len >= NAMEDATALEN)
382  len = pg_mbcliplen(s_data, len, NAMEDATALEN - 1);
383 
384  /* Remove trailing blanks */
385  while (len > 0)
386  {
387  if (s_data[len - 1] != ' ')
388  break;
389  len--;
390  }
391 
392  /* We use palloc0 here to ensure result is zero-padded */
393  result = (Name) palloc0(NAMEDATALEN);
394  memcpy(NameStr(*result), s_data, len);
395 
396  PG_RETURN_NAME(result);
397 }
#define NameStr(name)
Definition: c.h:682
NameData * Name
Definition: c.h:680
#define PG_RETURN_NAME(x)
Definition: fmgr.h:363
int pg_mbcliplen(const char *mbstr, int len, int limit)
Definition: mbutils.c:1026
void * palloc0(Size size)
Definition: mcxt.c:1230
#define NAMEDATALEN
Definition: c.h:677

References len, NAMEDATALEN, NameStr, palloc0(), PG_GETARG_BPCHAR_PP, pg_mbcliplen(), PG_RETURN_NAME, VARDATA_ANY, and VARSIZE_ANY_EXHDR.

◆ bpchar_pattern_ge()

Datum bpchar_pattern_ge ( PG_FUNCTION_ARGS  )

Definition at line 1176 of file varchar.c.

1177 {
1178  BpChar *arg1 = PG_GETARG_BPCHAR_PP(0);
1179  BpChar *arg2 = PG_GETARG_BPCHAR_PP(1);
1180  int result;
1181 
1182  result = internal_bpchar_pattern_compare(arg1, arg2);
1183 
1184  PG_FREE_IF_COPY(arg1, 0);
1185  PG_FREE_IF_COPY(arg2, 1);
1186 
1187  PG_RETURN_BOOL(result >= 0);
1188 }
#define PG_FREE_IF_COPY(ptr, n)
Definition: fmgr.h:260
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:359
static int internal_bpchar_pattern_compare(BpChar *arg1, BpChar *arg2)
Definition: varchar.c:1122

References internal_bpchar_pattern_compare(), PG_FREE_IF_COPY, PG_GETARG_BPCHAR_PP, and PG_RETURN_BOOL.

◆ bpchar_pattern_gt()

Datum bpchar_pattern_gt ( PG_FUNCTION_ARGS  )

Definition at line 1192 of file varchar.c.

1193 {
1194  BpChar *arg1 = PG_GETARG_BPCHAR_PP(0);
1195  BpChar *arg2 = PG_GETARG_BPCHAR_PP(1);
1196  int result;
1197 
1198  result = internal_bpchar_pattern_compare(arg1, arg2);
1199 
1200  PG_FREE_IF_COPY(arg1, 0);
1201  PG_FREE_IF_COPY(arg2, 1);
1202 
1203  PG_RETURN_BOOL(result > 0);
1204 }

References internal_bpchar_pattern_compare(), PG_FREE_IF_COPY, PG_GETARG_BPCHAR_PP, and PG_RETURN_BOOL.

◆ bpchar_pattern_le()

Datum bpchar_pattern_le ( PG_FUNCTION_ARGS  )

Definition at line 1160 of file varchar.c.

1161 {
1162  BpChar *arg1 = PG_GETARG_BPCHAR_PP(0);
1163  BpChar *arg2 = PG_GETARG_BPCHAR_PP(1);
1164  int result;
1165 
1166  result = internal_bpchar_pattern_compare(arg1, arg2);
1167 
1168  PG_FREE_IF_COPY(arg1, 0);
1169  PG_FREE_IF_COPY(arg2, 1);
1170 
1171  PG_RETURN_BOOL(result <= 0);
1172 }

References internal_bpchar_pattern_compare(), PG_FREE_IF_COPY, PG_GETARG_BPCHAR_PP, and PG_RETURN_BOOL.

◆ bpchar_pattern_lt()

Datum bpchar_pattern_lt ( PG_FUNCTION_ARGS  )

Definition at line 1144 of file varchar.c.

1145 {
1146  BpChar *arg1 = PG_GETARG_BPCHAR_PP(0);
1147  BpChar *arg2 = PG_GETARG_BPCHAR_PP(1);
1148  int result;
1149 
1150  result = internal_bpchar_pattern_compare(arg1, arg2);
1151 
1152  PG_FREE_IF_COPY(arg1, 0);
1153  PG_FREE_IF_COPY(arg2, 1);
1154 
1155  PG_RETURN_BOOL(result < 0);
1156 }

References internal_bpchar_pattern_compare(), PG_FREE_IF_COPY, PG_GETARG_BPCHAR_PP, and PG_RETURN_BOOL.

◆ bpchar_smaller()

Datum bpchar_smaller ( PG_FUNCTION_ARGS  )

Definition at line 969 of file varchar.c.

970 {
971  BpChar *arg1 = PG_GETARG_BPCHAR_PP(0);
972  BpChar *arg2 = PG_GETARG_BPCHAR_PP(1);
973  int len1,
974  len2;
975  int cmp;
976 
977  len1 = bcTruelen(arg1);
978  len2 = bcTruelen(arg2);
979 
980  cmp = varstr_cmp(VARDATA_ANY(arg1), len1, VARDATA_ANY(arg2), len2,
981  PG_GET_COLLATION());
982 
983  PG_RETURN_BPCHAR_P((cmp <= 0) ? arg1 : arg2);
984 }

References bcTruelen(), cmp(), PG_GET_COLLATION, PG_GETARG_BPCHAR_PP, PG_RETURN_BPCHAR_P, VARDATA_ANY, and varstr_cmp().

◆ bpchar_sortsupport()

Datum bpchar_sortsupport ( PG_FUNCTION_ARGS  )

Definition at line 934 of file varchar.c.

935 {
937  Oid collid = ssup->ssup_collation;
938  MemoryContext oldcontext;
939 
940  oldcontext = MemoryContextSwitchTo(ssup->ssup_cxt);
941 
942  /* Use generic string SortSupport */
943  varstr_sortsupport(ssup, BPCHAROID, collid);
944 
945  MemoryContextSwitchTo(oldcontext);
946 
947  PG_RETURN_VOID();
948 }
#define PG_RETURN_VOID()
Definition: fmgr.h:349
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:276
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:135
unsigned int Oid
Definition: postgres_ext.h:31
struct SortSupportData * SortSupport
Definition: sortsupport.h:58
MemoryContext ssup_cxt
Definition: sortsupport.h:66
void varstr_sortsupport(SortSupport ssup, Oid typid, Oid collid)
Definition: varlena.c:2012

References MemoryContextSwitchTo(), PG_GETARG_POINTER, PG_RETURN_VOID, SortSupportData::ssup_collation, SortSupportData::ssup_cxt, and varstr_sortsupport().

◆ bpcharcmp()

Datum bpcharcmp ( PG_FUNCTION_ARGS  )

Definition at line 913 of file varchar.c.

914 {
915  BpChar *arg1 = PG_GETARG_BPCHAR_PP(0);
916  BpChar *arg2 = PG_GETARG_BPCHAR_PP(1);
917  int len1,
918  len2;
919  int cmp;
920 
921  len1 = bcTruelen(arg1);
922  len2 = bcTruelen(arg2);
923 
924  cmp = varstr_cmp(VARDATA_ANY(arg1), len1, VARDATA_ANY(arg2), len2,
925  PG_GET_COLLATION());
926 
927  PG_FREE_IF_COPY(arg1, 0);
928  PG_FREE_IF_COPY(arg2, 1);
929 
931 }
#define PG_RETURN_INT32(x)
Definition: fmgr.h:354

References bcTruelen(), cmp(), PG_FREE_IF_COPY, PG_GET_COLLATION, PG_GETARG_BPCHAR_PP, PG_RETURN_INT32, VARDATA_ANY, and varstr_cmp().

Referenced by gbt_bpcharcmp().

◆ bpchareq()

Datum bpchareq ( PG_FUNCTION_ARGS  )

Definition at line 739 of file varchar.c.

740 {
741  BpChar *arg1 = PG_GETARG_BPCHAR_PP(0);
742  BpChar *arg2 = PG_GETARG_BPCHAR_PP(1);
743  int len1,
744  len2;
745  bool result;
746  Oid collid = PG_GET_COLLATION();
747  bool locale_is_c = false;
748  pg_locale_t mylocale = 0;
749 
750  check_collation_set(collid);
751 
752  len1 = bcTruelen(arg1);
753  len2 = bcTruelen(arg2);
754 
755  if (lc_collate_is_c(collid))
756  locale_is_c = true;
757  else
758  mylocale = pg_newlocale_from_collation(collid);
759 
760  if (locale_is_c || !mylocale || mylocale->deterministic)
761  {
762  /*
763  * Since we only care about equality or not-equality, we can avoid all
764  * the expense of strcoll() here, and just do bitwise comparison.
765  */
766  if (len1 != len2)
767  result = false;
768  else
769  result = (memcmp(VARDATA_ANY(arg1), VARDATA_ANY(arg2), len1) == 0);
770  }
771  else
772  {
773  result = (varstr_cmp(VARDATA_ANY(arg1), len1, VARDATA_ANY(arg2), len2,
774  collid) == 0);
775  }
776 
777  PG_FREE_IF_COPY(arg1, 0);
778  PG_FREE_IF_COPY(arg2, 1);
779 
780  PG_RETURN_BOOL(result);
781 }
bool lc_collate_is_c(Oid collation)
Definition: pg_locale.c:1299
pg_locale_t pg_newlocale_from_collation(Oid collid)
Definition: pg_locale.c:1481
bool deterministic
Definition: pg_locale.h:76
static void check_collation_set(Oid collid)
Definition: varchar.c:723

References bcTruelen(), check_collation_set(), pg_locale_struct::deterministic, lc_collate_is_c(), PG_FREE_IF_COPY, PG_GET_COLLATION, PG_GETARG_BPCHAR_PP, pg_newlocale_from_collation(), PG_RETURN_BOOL, VARDATA_ANY, and varstr_cmp().

Referenced by gbt_bpchareq().

◆ bpcharge()

Datum bpcharge ( PG_FUNCTION_ARGS  )

Definition at line 892 of file varchar.c.

893 {
894  BpChar *arg1 = PG_GETARG_BPCHAR_PP(0);
895  BpChar *arg2 = PG_GETARG_BPCHAR_PP(1);
896  int len1,
897  len2;
898  int cmp;
899 
900  len1 = bcTruelen(arg1);
901  len2 = bcTruelen(arg2);
902 
903  cmp = varstr_cmp(VARDATA_ANY(arg1), len1, VARDATA_ANY(arg2), len2,
904  PG_GET_COLLATION());
905 
906  PG_FREE_IF_COPY(arg1, 0);
907  PG_FREE_IF_COPY(arg2, 1);
908 
909  PG_RETURN_BOOL(cmp >= 0);
910 }

References bcTruelen(), cmp(), PG_FREE_IF_COPY, PG_GET_COLLATION, PG_GETARG_BPCHAR_PP, PG_RETURN_BOOL, VARDATA_ANY, and varstr_cmp().

Referenced by gbt_bpcharge().

◆ bpchargt()

Datum bpchargt ( PG_FUNCTION_ARGS  )

Definition at line 871 of file varchar.c.

872 {
873  BpChar *arg1 = PG_GETARG_BPCHAR_PP(0);
874  BpChar *arg2 = PG_GETARG_BPCHAR_PP(1);
875  int len1,
876  len2;
877  int cmp;
878 
879  len1 = bcTruelen(arg1);
880  len2 = bcTruelen(arg2);
881 
882  cmp = varstr_cmp(VARDATA_ANY(arg1), len1, VARDATA_ANY(arg2), len2,
883  PG_GET_COLLATION());
884 
885  PG_FREE_IF_COPY(arg1, 0);
886  PG_FREE_IF_COPY(arg2, 1);
887 
888  PG_RETURN_BOOL(cmp > 0);
889 }

References bcTruelen(), cmp(), PG_FREE_IF_COPY, PG_GET_COLLATION, PG_GETARG_BPCHAR_PP, PG_RETURN_BOOL, VARDATA_ANY, and varstr_cmp().

Referenced by gbt_bpchargt().

◆ bpcharin()

Datum bpcharin ( PG_FUNCTION_ARGS  )

Definition at line 195 of file varchar.c.

196 {
197  char *s = PG_GETARG_CSTRING(0);
198 
199 #ifdef NOT_USED
200  Oid typelem = PG_GETARG_OID(1);
201 #endif
202  int32 atttypmod = PG_GETARG_INT32(2);
203  BpChar *result;
204 
205  result = bpchar_input(s, strlen(s), atttypmod);
206  PG_RETURN_BPCHAR_P(result);
207 }
#define PG_GETARG_OID(n)
Definition: fmgr.h:275
#define PG_GETARG_CSTRING(n)
Definition: fmgr.h:277
static BpChar * bpchar_input(const char *s, size_t len, int32 atttypmod)
Definition: varchar.c:127

References bpchar_input(), PG_GETARG_CSTRING, PG_GETARG_INT32, PG_GETARG_OID, and PG_RETURN_BPCHAR_P.

◆ bpcharle()

Datum bpcharle ( PG_FUNCTION_ARGS  )

Definition at line 850 of file varchar.c.

851 {
852  BpChar *arg1 = PG_GETARG_BPCHAR_PP(0);
853  BpChar *arg2 = PG_GETARG_BPCHAR_PP(1);
854  int len1,
855  len2;
856  int cmp;
857 
858  len1 = bcTruelen(arg1);
859  len2 = bcTruelen(arg2);
860 
861  cmp = varstr_cmp(VARDATA_ANY(arg1), len1, VARDATA_ANY(arg2), len2,
862  PG_GET_COLLATION());
863 
864  PG_FREE_IF_COPY(arg1, 0);
865  PG_FREE_IF_COPY(arg2, 1);
866 
867  PG_RETURN_BOOL(cmp <= 0);
868 }

References bcTruelen(), cmp(), PG_FREE_IF_COPY, PG_GET_COLLATION, PG_GETARG_BPCHAR_PP, PG_RETURN_BOOL, VARDATA_ANY, and varstr_cmp().

Referenced by gbt_bpcharle().

◆ bpcharlen()

Datum bpcharlen ( PG_FUNCTION_ARGS  )

Definition at line 689 of file varchar.c.

690 {
692  int len;
693 
694  /* get number of bytes, ignoring trailing spaces */
695  len = bcTruelen(arg);
696 
697  /* in multibyte encoding, convert to number of characters */
700 
702 }
int pg_database_encoding_max_length(void)
Definition: mbutils.c:1495

References arg, bcTruelen(), len, pg_database_encoding_max_length(), PG_GETARG_BPCHAR_PP, pg_mbstrlen_with_len(), PG_RETURN_INT32, and VARDATA_ANY.

◆ bpcharlt()

Datum bpcharlt ( PG_FUNCTION_ARGS  )

Definition at line 829 of file varchar.c.

830 {
831  BpChar *arg1 = PG_GETARG_BPCHAR_PP(0);
832  BpChar *arg2 = PG_GETARG_BPCHAR_PP(1);
833  int len1,
834  len2;
835  int cmp;
836 
837  len1 = bcTruelen(arg1);
838  len2 = bcTruelen(arg2);
839 
840  cmp = varstr_cmp(VARDATA_ANY(arg1), len1, VARDATA_ANY(arg2), len2,
841  PG_GET_COLLATION());
842 
843  PG_FREE_IF_COPY(arg1, 0);
844  PG_FREE_IF_COPY(arg2, 1);
845 
846  PG_RETURN_BOOL(cmp < 0);
847 }

References bcTruelen(), cmp(), PG_FREE_IF_COPY, PG_GET_COLLATION, PG_GETARG_BPCHAR_PP, PG_RETURN_BOOL, VARDATA_ANY, and varstr_cmp().

Referenced by gbt_bpcharlt().

◆ bpcharne()

Datum bpcharne ( PG_FUNCTION_ARGS  )

Definition at line 784 of file varchar.c.

785 {
786  BpChar *arg1 = PG_GETARG_BPCHAR_PP(0);
787  BpChar *arg2 = PG_GETARG_BPCHAR_PP(1);
788  int len1,
789  len2;
790  bool result;
791  Oid collid = PG_GET_COLLATION();
792  bool locale_is_c = false;
793  pg_locale_t mylocale = 0;
794 
795  check_collation_set(collid);
796 
797  len1 = bcTruelen(arg1);
798  len2 = bcTruelen(arg2);
799 
800  if (lc_collate_is_c(collid))
801  locale_is_c = true;
802  else
803  mylocale = pg_newlocale_from_collation(collid);
804 
805  if (locale_is_c || !mylocale || mylocale->deterministic)
806  {
807  /*
808  * Since we only care about equality or not-equality, we can avoid all
809  * the expense of strcoll() here, and just do bitwise comparison.
810  */
811  if (len1 != len2)
812  result = true;
813  else
814  result = (memcmp(VARDATA_ANY(arg1), VARDATA_ANY(arg2), len1) != 0);
815  }
816  else
817  {
818  result = (varstr_cmp(VARDATA_ANY(arg1), len1, VARDATA_ANY(arg2), len2,
819  collid) != 0);
820  }
821 
822  PG_FREE_IF_COPY(arg1, 0);
823  PG_FREE_IF_COPY(arg2, 1);
824 
825  PG_RETURN_BOOL(result);
826 }

References bcTruelen(), check_collation_set(), pg_locale_struct::deterministic, lc_collate_is_c(), PG_FREE_IF_COPY, PG_GET_COLLATION, PG_GETARG_BPCHAR_PP, pg_newlocale_from_collation(), PG_RETURN_BOOL, VARDATA_ANY, and varstr_cmp().

◆ bpcharoctetlen()

Datum bpcharoctetlen ( PG_FUNCTION_ARGS  )

Definition at line 705 of file varchar.c.

706 {
708 
709  /* We need not detoast the input at all */
711 }
Size toast_raw_datum_size(Datum value)
Definition: detoast.c:545
#define PG_GETARG_DATUM(n)
Definition: fmgr.h:268
uintptr_t Datum
Definition: postgres.h:412

References arg, PG_GETARG_DATUM, PG_RETURN_INT32, toast_raw_datum_size(), and VARHDRSZ.

◆ bpcharout()

Datum bpcharout ( PG_FUNCTION_ARGS  )

Definition at line 217 of file varchar.c.

218 {
219  Datum txt = PG_GETARG_DATUM(0);
220 
222 }
#define TextDatumGetCString(d)
Definition: builtins.h:86
#define PG_RETURN_CSTRING(x)
Definition: fmgr.h:362

References PG_GETARG_DATUM, PG_RETURN_CSTRING, and TextDatumGetCString.

◆ bpcharrecv()

Datum bpcharrecv ( PG_FUNCTION_ARGS  )

Definition at line 228 of file varchar.c.

229 {
231 
232 #ifdef NOT_USED
233  Oid typelem = PG_GETARG_OID(1);
234 #endif
235  int32 atttypmod = PG_GETARG_INT32(2);
236  BpChar *result;
237  char *str;
238  int nbytes;
239 
240  str = pq_getmsgtext(buf, buf->len - buf->cursor, &nbytes);
241  result = bpchar_input(str, nbytes, atttypmod);
242  pfree(str);
243  PG_RETURN_BPCHAR_P(result);
244 }
void pfree(void *pointer)
Definition: mcxt.c:1306
static char * buf
Definition: pg_test_fsync.c:67
char * pq_getmsgtext(StringInfo msg, int rawbytes, int *nbytes)
Definition: pqformat.c:548
StringInfoData * StringInfo
Definition: stringinfo.h:44

References bpchar_input(), buf, pfree(), PG_GETARG_INT32, PG_GETARG_OID, PG_GETARG_POINTER, PG_RETURN_BPCHAR_P, pq_getmsgtext(), and generate_unaccent_rules::str.

◆ bpcharsend()

Datum bpcharsend ( PG_FUNCTION_ARGS  )

Definition at line 250 of file varchar.c.

251 {
252  /* Exactly the same as textsend, so share code */
253  return textsend(fcinfo);
254 }
Datum textsend(PG_FUNCTION_ARGS)
Definition: varlena.c:599

References textsend().

◆ bpchartruelen()

int bpchartruelen ( char *  s,
int  len 
)

Definition at line 672 of file varchar.c.

673 {
674  int i;
675 
676  /*
677  * Note that we rely on the assumption that ' ' is a singleton unit on
678  * every supported multibyte server encoding.
679  */
680  for (i = len - 1; i >= 0; i--)
681  {
682  if (s[i] != ' ')
683  break;
684  }
685  return i + 1;
686 }

References i, and len.

Referenced by bcTruelen(), bpcharfastcmp_c(), varstr_abbrev_convert(), and varstrfastcmp_locale().

◆ bpchartypmodin()

Datum bpchartypmodin ( PG_FUNCTION_ARGS  )

Definition at line 416 of file varchar.c.

417 {
419 
420  PG_RETURN_INT32(anychar_typmodin(ta, "char"));
421 }
#define PG_GETARG_ARRAYTYPE_P(n)
Definition: array.h:256
static int32 anychar_typmodin(ArrayType *ta, const char *typename)
Definition: varchar.c:34

References anychar_typmodin(), PG_GETARG_ARRAYTYPE_P, and PG_RETURN_INT32.

◆ bpchartypmodout()

Datum bpchartypmodout ( PG_FUNCTION_ARGS  )

Definition at line 424 of file varchar.c.

425 {
426  int32 typmod = PG_GETARG_INT32(0);
427 
429 }
static char * anychar_typmodout(int32 typmod)
Definition: varchar.c:73

References anychar_typmodout(), PG_GETARG_INT32, and PG_RETURN_CSTRING.

◆ btbpchar_pattern_cmp()

Datum btbpchar_pattern_cmp ( PG_FUNCTION_ARGS  )

Definition at line 1208 of file varchar.c.

1209 {
1210  BpChar *arg1 = PG_GETARG_BPCHAR_PP(0);
1211  BpChar *arg2 = PG_GETARG_BPCHAR_PP(1);
1212  int result;
1213 
1214  result = internal_bpchar_pattern_compare(arg1, arg2);
1215 
1216  PG_FREE_IF_COPY(arg1, 0);
1217  PG_FREE_IF_COPY(arg2, 1);
1218 
1219  PG_RETURN_INT32(result);
1220 }

References internal_bpchar_pattern_compare(), PG_FREE_IF_COPY, PG_GETARG_BPCHAR_PP, and PG_RETURN_INT32.

◆ btbpchar_pattern_sortsupport()

Datum btbpchar_pattern_sortsupport ( PG_FUNCTION_ARGS  )

Definition at line 1224 of file varchar.c.

1225 {
1227  MemoryContext oldcontext;
1228 
1229  oldcontext = MemoryContextSwitchTo(ssup->ssup_cxt);
1230 
1231  /* Use generic string SortSupport, forcing "C" collation */
1232  varstr_sortsupport(ssup, BPCHAROID, C_COLLATION_OID);
1233 
1234  MemoryContextSwitchTo(oldcontext);
1235 
1236  PG_RETURN_VOID();
1237 }

References MemoryContextSwitchTo(), PG_GETARG_POINTER, PG_RETURN_VOID, SortSupportData::ssup_cxt, and varstr_sortsupport().

◆ char_bpchar()

Datum char_bpchar ( PG_FUNCTION_ARGS  )

Definition at line 352 of file varchar.c.

353 {
354  char c = PG_GETARG_CHAR(0);
355  BpChar *result;
356 
357  result = (BpChar *) palloc(VARHDRSZ + 1);
358 
359  SET_VARSIZE(result, VARHDRSZ + 1);
360  *(VARDATA(result)) = c;
361 
362  PG_RETURN_BPCHAR_P(result);
363 }
#define PG_GETARG_CHAR(n)
Definition: fmgr.h:273
char * c

References palloc(), PG_GETARG_CHAR, PG_RETURN_BPCHAR_P, SET_VARSIZE, VARDATA, and VARHDRSZ.

◆ check_collation_set()

static void check_collation_set ( Oid  collid)
static

Definition at line 723 of file varchar.c.

724 {
725  if (!OidIsValid(collid))
726  {
727  /*
728  * This typically means that the parser could not resolve a conflict
729  * of implicit collations, so report it that way.
730  */
731  ereport(ERROR,
732  (errcode(ERRCODE_INDETERMINATE_COLLATION),
733  errmsg("could not determine which collation to use for string comparison"),
734  errhint("Use the COLLATE clause to set the collation explicitly.")));
735  }
736 }
#define OidIsValid(objectId)
Definition: c.h:711
int errhint(const char *fmt,...)
Definition: elog.c:1193

References ereport, errcode(), errhint(), errmsg(), ERROR, and OidIsValid.

Referenced by bpchareq(), and bpcharne().

◆ hashbpchar()

Datum hashbpchar ( PG_FUNCTION_ARGS  )

Definition at line 992 of file varchar.c.

993 {
995  Oid collid = PG_GET_COLLATION();
996  char *keydata;
997  int keylen;
998  pg_locale_t mylocale = 0;
999  Datum result;
1000 
1001  if (!collid)
1002  ereport(ERROR,
1003  (errcode(ERRCODE_INDETERMINATE_COLLATION),
1004  errmsg("could not determine which collation to use for string hashing"),
1005  errhint("Use the COLLATE clause to set the collation explicitly.")));
1006 
1007  keydata = VARDATA_ANY(key);
1008  keylen = bcTruelen(key);
1009 
1010  if (!lc_collate_is_c(collid))
1011  mylocale = pg_newlocale_from_collation(collid);
1012 
1013  if (!mylocale || mylocale->deterministic)
1014  {
1015  result = hash_any((unsigned char *) keydata, keylen);
1016  }
1017  else
1018  {
1019 #ifdef USE_ICU
1020  if (mylocale->provider == COLLPROVIDER_ICU)
1021  {
1022  int32_t ulen = -1;
1023  UChar *uchar = NULL;
1024  Size bsize;
1025  uint8_t *buf;
1026 
1027  ulen = icu_to_uchar(&uchar, keydata, keylen);
1028 
1029  bsize = ucol_getSortKey(mylocale->info.icu.ucol,
1030  uchar, ulen, NULL, 0);
1031  buf = palloc(bsize);
1032  ucol_getSortKey(mylocale->info.icu.ucol,
1033  uchar, ulen, buf, bsize);
1034  pfree(uchar);
1035 
1036  result = hash_any(buf, bsize);
1037 
1038  pfree(buf);
1039  }
1040  else
1041 #endif
1042  /* shouldn't happen */
1043  elog(ERROR, "unsupported collprovider: %c", mylocale->provider);
1044  }
1045 
1046  /* Avoid leaking memory for toasted inputs */
1047  PG_FREE_IF_COPY(key, 0);
1048 
1049  return result;
1050 }
size_t Size
Definition: c.h:541
static Datum hash_any(const unsigned char *k, int keylen)
Definition: hashfn.h:31
union pg_locale_struct::@142 info

References bcTruelen(), buf, pg_locale_struct::deterministic, elog(), ereport, errcode(), errhint(), errmsg(), ERROR, hash_any(), pg_locale_struct::info, sort-test::key, lc_collate_is_c(), palloc(), pfree(), PG_FREE_IF_COPY, PG_GET_COLLATION, PG_GETARG_BPCHAR_PP, pg_newlocale_from_collation(), pg_locale_struct::provider, and VARDATA_ANY.

◆ hashbpcharextended()

Datum hashbpcharextended ( PG_FUNCTION_ARGS  )

Definition at line 1053 of file varchar.c.

1054 {
1056  Oid collid = PG_GET_COLLATION();
1057  char *keydata;
1058  int keylen;
1059  pg_locale_t mylocale = 0;
1060  Datum result;
1061 
1062  if (!collid)
1063  ereport(ERROR,
1064  (errcode(ERRCODE_INDETERMINATE_COLLATION),
1065  errmsg("could not determine which collation to use for string hashing"),
1066  errhint("Use the COLLATE clause to set the collation explicitly.")));
1067 
1068  keydata = VARDATA_ANY(key);
1069  keylen = bcTruelen(key);
1070 
1071  if (!lc_collate_is_c(collid))
1072  mylocale = pg_newlocale_from_collation(collid);
1073 
1074  if (!mylocale || mylocale->deterministic)
1075  {
1076  result = hash_any_extended((unsigned char *) keydata, keylen,
1077  PG_GETARG_INT64(1));
1078  }
1079  else
1080  {
1081 #ifdef USE_ICU
1082  if (mylocale->provider == COLLPROVIDER_ICU)
1083  {
1084  int32_t ulen = -1;
1085  UChar *uchar = NULL;
1086  Size bsize;
1087  uint8_t *buf;
1088 
1089  ulen = icu_to_uchar(&uchar, keydata, keylen);
1090 
1091  bsize = ucol_getSortKey(mylocale->info.icu.ucol,
1092  uchar, ulen, NULL, 0);
1093  buf = palloc(bsize);
1094  ucol_getSortKey(mylocale->info.icu.ucol,
1095  uchar, ulen, buf, bsize);
1096  pfree(uchar);
1097 
1098  result = hash_any_extended(buf, bsize, PG_GETARG_INT64(1));
1099 
1100  pfree(buf);
1101  }
1102  else
1103 #endif
1104  /* shouldn't happen */
1105  elog(ERROR, "unsupported collprovider: %c", mylocale->provider);
1106  }
1107 
1108  PG_FREE_IF_COPY(key, 0);
1109 
1110  return result;
1111 }
#define PG_GETARG_INT64(n)
Definition: fmgr.h:283
static Datum hash_any_extended(const unsigned char *k, int keylen, uint64 seed)
Definition: hashfn.h:37

References bcTruelen(), buf, pg_locale_struct::deterministic, elog(), ereport, errcode(), errhint(), errmsg(), ERROR, hash_any_extended(), pg_locale_struct::info, sort-test::key, lc_collate_is_c(), palloc(), pfree(), PG_FREE_IF_COPY, PG_GET_COLLATION, PG_GETARG_BPCHAR_PP, PG_GETARG_INT64, pg_newlocale_from_collation(), pg_locale_struct::provider, and VARDATA_ANY.

◆ internal_bpchar_pattern_compare()

static int internal_bpchar_pattern_compare ( BpChar arg1,
BpChar arg2 
)
static

Definition at line 1122 of file varchar.c.

1123 {
1124  int result;
1125  int len1,
1126  len2;
1127 
1128  len1 = bcTruelen(arg1);
1129  len2 = bcTruelen(arg2);
1130 
1131  result = memcmp(VARDATA_ANY(arg1), VARDATA_ANY(arg2), Min(len1, len2));
1132  if (result != 0)
1133  return result;
1134  else if (len1 < len2)
1135  return -1;
1136  else if (len1 > len2)
1137  return 1;
1138  else
1139  return 0;
1140 }
#define Min(x, y)
Definition: c.h:937

References bcTruelen(), Min, and VARDATA_ANY.

Referenced by bpchar_pattern_ge(), bpchar_pattern_gt(), bpchar_pattern_le(), bpchar_pattern_lt(), and btbpchar_pattern_cmp().

◆ name_bpchar()

Datum name_bpchar ( PG_FUNCTION_ARGS  )

Definition at line 406 of file varchar.c.

407 {
408  Name s = PG_GETARG_NAME(0);
409  BpChar *result;
410 
411  result = (BpChar *) cstring_to_text(NameStr(*s));
412  PG_RETURN_BPCHAR_P(result);
413 }
#define PG_GETARG_NAME(n)
Definition: fmgr.h:278
text * cstring_to_text(const char *s)
Definition: varlena.c:189

References cstring_to_text(), NameStr, PG_GETARG_NAME, and PG_RETURN_BPCHAR_P.

◆ varchar()

Datum varchar ( PG_FUNCTION_ARGS  )

Definition at line 605 of file varchar.c.

606 {
608  int32 typmod = PG_GETARG_INT32(1);
609  bool isExplicit = PG_GETARG_BOOL(2);
610  int32 len,
611  maxlen;
612  size_t maxmblen;
613  int i;
614  char *s_data;
615 
617  s_data = VARDATA_ANY(source);
618  maxlen = typmod - VARHDRSZ;
619 
620  /* No work if typmod is invalid or supplied data fits it already */
621  if (maxlen < 0 || len <= maxlen)
623 
624  /* only reach here if string is too long... */
625 
626  /* truncate multibyte string preserving multibyte boundary */
627  maxmblen = pg_mbcharcliplen(s_data, len, maxlen);
628 
629  if (!isExplicit)
630  {
631  for (i = maxmblen; i < len; i++)
632  if (s_data[i] != ' ')
633  ereport(ERROR,
634  (errcode(ERRCODE_STRING_DATA_RIGHT_TRUNCATION),
635  errmsg("value too long for type character varying(%d)",
636  maxlen)));
637  }
638 
640  maxmblen));
641 }
#define PG_GETARG_VARCHAR_PP(n)
Definition: fmgr.h:311
#define PG_RETURN_VARCHAR_P(x)
Definition: fmgr.h:374
text * cstring_to_text_with_len(const char *s, int len)
Definition: varlena.c:201

References cstring_to_text_with_len(), ereport, errcode(), errmsg(), ERROR, i, len, PG_GETARG_BOOL, PG_GETARG_INT32, PG_GETARG_VARCHAR_PP, pg_mbcharcliplen(), PG_RETURN_VARCHAR_P, source, VARDATA_ANY, VARHDRSZ, and VARSIZE_ANY_EXHDR.

Referenced by main().

◆ varchar_input()

static VarChar* varchar_input ( const char *  s,
size_t  len,
int32  atttypmod 
)
static

Definition at line 455 of file varchar.c.

456 {
457  VarChar *result;
458  size_t maxlen;
459 
460  maxlen = atttypmod - VARHDRSZ;
461 
462  if (atttypmod >= (int32) VARHDRSZ && len > maxlen)
463  {
464  /* Verify that extra characters are spaces, and clip them off */
465  size_t mbmaxlen = pg_mbcharcliplen(s, len, maxlen);
466  size_t j;
467 
468  for (j = mbmaxlen; j < len; j++)
469  {
470  if (s[j] != ' ')
471  ereport(ERROR,
472  (errcode(ERRCODE_STRING_DATA_RIGHT_TRUNCATION),
473  errmsg("value too long for type character varying(%d)",
474  (int) maxlen)));
475  }
476 
477  len = mbmaxlen;
478  }
479 
480  result = (VarChar *) cstring_to_text_with_len(s, len);
481  return result;
482 }

References cstring_to_text_with_len(), ereport, errcode(), errmsg(), ERROR, j, len, pg_mbcharcliplen(), and VARHDRSZ.

Referenced by varcharin(), and varcharrecv().

◆ varchar_support()

Datum varchar_support ( PG_FUNCTION_ARGS  )

Definition at line 561 of file varchar.c.

562 {
563  Node *rawreq = (Node *) PG_GETARG_POINTER(0);
564  Node *ret = NULL;
565 
566  if (IsA(rawreq, SupportRequestSimplify))
567  {
569  FuncExpr *expr = req->fcall;
570  Node *typmod;
571 
572  Assert(list_length(expr->args) >= 2);
573 
574  typmod = (Node *) lsecond(expr->args);
575 
576  if (IsA(typmod, Const) && !((Const *) typmod)->constisnull)
577  {
578  Node *source = (Node *) linitial(expr->args);
579  int32 old_typmod = exprTypmod(source);
580  int32 new_typmod = DatumGetInt32(((Const *) typmod)->constvalue);
581  int32 old_max = old_typmod - VARHDRSZ;
582  int32 new_max = new_typmod - VARHDRSZ;
583 
584  if (new_typmod < 0 || (old_typmod >= 0 && old_max <= new_max))
585  ret = relabel_to_typmod(source, new_typmod);
586  }
587  }
588 
589  PG_RETURN_POINTER(ret);
590 }
#define PG_RETURN_POINTER(x)
Definition: fmgr.h:361
int32 exprTypmod(const Node *expr)
Definition: nodeFuncs.c:266
Node * relabel_to_typmod(Node *expr, int32 typmod)
Definition: nodeFuncs.c:632
#define IsA(nodeptr, _type_)
Definition: nodes.h:168
static int list_length(const List *l)
Definition: pg_list.h:150
#define linitial(l)
Definition: pg_list.h:176
#define lsecond(l)
Definition: pg_list.h:181
static int32 DatumGetInt32(Datum X)
Definition: postgres.h:550
List * args
Definition: primnodes.h:606
Definition: nodes.h:118

References FuncExpr::args, Assert(), DatumGetInt32(), exprTypmod(), SupportRequestSimplify::fcall, IsA, linitial, list_length(), lsecond, PG_GETARG_POINTER, PG_RETURN_POINTER, relabel_to_typmod(), source, and VARHDRSZ.

◆ varcharin()

Datum varcharin ( PG_FUNCTION_ARGS  )

Definition at line 489 of file varchar.c.

490 {
491  char *s = PG_GETARG_CSTRING(0);
492 
493 #ifdef NOT_USED
494  Oid typelem = PG_GETARG_OID(1);
495 #endif
496  int32 atttypmod = PG_GETARG_INT32(2);
497  VarChar *result;
498 
499  result = varchar_input(s, strlen(s), atttypmod);
500  PG_RETURN_VARCHAR_P(result);
501 }
static VarChar * varchar_input(const char *s, size_t len, int32 atttypmod)
Definition: varchar.c:455

References PG_GETARG_CSTRING, PG_GETARG_INT32, PG_GETARG_OID, PG_RETURN_VARCHAR_P, and varchar_input().

◆ varcharout()

Datum varcharout ( PG_FUNCTION_ARGS  )

Definition at line 511 of file varchar.c.

512 {
513  Datum txt = PG_GETARG_DATUM(0);
514 
516 }

References PG_GETARG_DATUM, PG_RETURN_CSTRING, and TextDatumGetCString.

◆ varcharrecv()

Datum varcharrecv ( PG_FUNCTION_ARGS  )

Definition at line 522 of file varchar.c.

523 {
525 
526 #ifdef NOT_USED
527  Oid typelem = PG_GETARG_OID(1);
528 #endif
529  int32 atttypmod = PG_GETARG_INT32(2);
530  VarChar *result;
531  char *str;
532  int nbytes;
533 
534  str = pq_getmsgtext(buf, buf->len - buf->cursor, &nbytes);
535  result = varchar_input(str, nbytes, atttypmod);
536  pfree(str);
537  PG_RETURN_VARCHAR_P(result);
538 }

References buf, pfree(), PG_GETARG_INT32, PG_GETARG_OID, PG_GETARG_POINTER, PG_RETURN_VARCHAR_P, pq_getmsgtext(), generate_unaccent_rules::str, and varchar_input().

◆ varcharsend()

Datum varcharsend ( PG_FUNCTION_ARGS  )

Definition at line 544 of file varchar.c.

545 {
546  /* Exactly the same as textsend, so share code */
547  return textsend(fcinfo);
548 }

References textsend().

◆ varchartypmodin()

Datum varchartypmodin ( PG_FUNCTION_ARGS  )

Definition at line 644 of file varchar.c.

645 {
647 
648  PG_RETURN_INT32(anychar_typmodin(ta, "varchar"));
649 }

References anychar_typmodin(), PG_GETARG_ARRAYTYPE_P, and PG_RETURN_INT32.

◆ varchartypmodout()

Datum varchartypmodout ( PG_FUNCTION_ARGS  )

Definition at line 652 of file varchar.c.

653 {
654  int32 typmod = PG_GETARG_INT32(0);
655 
657 }

References anychar_typmodout(), PG_GETARG_INT32, and PG_RETURN_CSTRING.