PostgreSQL Source Code: src/backend/utils/adt/varchar.c File Reference (original) (raw)

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 BpChar * bpchar_input (const char *s, size_t len, int32 atttypmod, Node *escontext)
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 VarChar * varchar_input (const char *s, size_t len, int32 atttypmod, Node *escontext)
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)

anychar_typmodin()

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

Definition at line 33 of file varchar.c.

34{

37 int n;

38

40

41

42

43

44

45 if (n != 1)

47 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),

48 errmsg("invalid type modifier")));

49

50 if (*tl < 1)

52 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),

53 errmsg("length for type %s must be at least 1", typename)));

56 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),

57 errmsg("length for type %s cannot exceed %d",

59

60

61

62

63

64

66

67 return typmod;

68}

int32 * ArrayGetIntegerTypmods(ArrayType *arr, int *n)

int errcode(int sqlerrcode)

int errmsg(const char *fmt,...)

#define ereport(elevel,...)

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

Referenced by bpchartypmodin(), and varchartypmodin().

anychar_typmodout()

static char * anychar_typmodout ( int32 typmod) static

bcTruelen()

static int bcTruelen ( BpChar * arg) inlinestatic

Definition at line 670 of file varchar.c.

671{

673}

#define VARSIZE_ANY_EXHDR(PTR)

int bpchartruelen(char *s, int len)

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()

Definition at line 271 of file varchar.c.

272{

278 char *r;

279 char *s;

280 int i;

281 int charlen;

282

283

284

287

289

292

294

295

296 if (charlen == maxlen)

298

299 if (charlen > maxlen)

300 {

301

302 size_t maxmblen;

303

305

306 if (!isExplicit)

307 {

308 for (i = maxmblen; i < len; i++)

309 if (s[i] != ' ')

311 (errcode(ERRCODE_STRING_DATA_RIGHT_TRUNCATION),

312 errmsg("value too long for type character(%d)",

313 maxlen)));

314 }

315

316 len = maxmblen;

317

318

319

320

321

322 maxlen = len;

323 }

324 else

325 {

326

327

328

329

330 maxlen = len + (maxlen - charlen);

331 }

332

334

338

339 memcpy(r, s, len);

340

341

342 if (maxlen > len)

343 memset(r + len, ' ', maxlen - len);

344

346}

#define PG_GETARG_BPCHAR_PP(n)

#define PG_RETURN_BPCHAR_P(x)

#define PG_GETARG_INT32(n)

#define PG_GETARG_BOOL(n)

Assert(PointerIsAligned(start, uint64))

int pg_mbstrlen_with_len(const char *mbstr, int limit)

int pg_mbcharcliplen(const char *mbstr, int len, int limit)

static rewind_source * source

#define SET_VARSIZE(PTR, len)

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, Node * escontext ) static

Definition at line 130 of file varchar.c.

131{

133 char *r;

134 size_t maxlen;

135

136

138 maxlen = len;

139 else

140 {

141 size_t charlen;

142

143 maxlen = atttypmod - VARHDRSZ;

145 if (charlen > maxlen)

146 {

147

149 size_t j;

150

151

152

153

154

155

156 for (j = mbmaxlen; j < len; j++)

157 {

158 if (s[j] != ' ')

160 (errcode(ERRCODE_STRING_DATA_RIGHT_TRUNCATION),

161 errmsg("value too long for type character(%d)",

162 (int) maxlen)));

163 }

164

165

166

167

168

169 maxlen = len = mbmaxlen;

170 }

171 else

172 {

173

174

175

176

177 maxlen = len + (maxlen - charlen);

178 }

179 }

180

184 memcpy(r, s, len);

185

186

187 if (maxlen > len)

188 memset(r + len, ' ', maxlen - len);

189

190 return result;

191}

#define ereturn(context, dummy_value,...)

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

Referenced by bpcharin(), and bpcharrecv().

bpchar_larger()

Definition at line 947 of file varchar.c.

948{

951 int len1,

952 len2;

954

957

960

962}

#define PG_GET_COLLATION()

static int cmp(const chr *x, const chr *y, size_t len)

static int bcTruelen(BpChar *arg)

int varstr_cmp(const char *arg1, int len1, const char *arg2, int len2, Oid collid)

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

bpchar_name()

Definition at line 371 of file varchar.c.

372{

374 char *s_data;

377

380

381

384

385

386 while (len > 0)

387 {

388 if (s_data[len - 1] != ' ')

389 break;

391 }

392

393

395 memcpy(NameStr(*result), s_data, len);

396

398}

#define PG_RETURN_NAME(x)

int pg_mbcliplen(const char *mbstr, int len, int limit)

void * palloc0(Size size)

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

bpchar_pattern_ge()

bpchar_pattern_gt()

bpchar_pattern_le()

bpchar_pattern_lt()

bpchar_smaller()

bpchar_sortsupport()

bpcharcmp()

bpchareq()

Definition at line 743 of file varchar.c.

744{

747 int len1,

748 len2;

749 bool result;

752

754

757

759

761 {

762

763

764

765

766 if (len1 != len2)

767 result = false;

768 else

770 }

771 else

772 {

775 }

776

779

781}

pg_locale_t pg_newlocale_from_collation(Oid collid)

static void check_collation_set(Oid collid)

References bcTruelen(), check_collation_set(), collid, pg_locale_struct::deterministic, 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()

bpchargt()

bpcharin()

Definition at line 198 of file varchar.c.

199{

201#ifdef NOT_USED

203#endif

206

207 result = bpchar_input(s, strlen(s), atttypmod, fcinfo->context);

209}

#define PG_GETARG_CSTRING(n)

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

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

bpcharle()

bpcharlen()

bpcharlt()

bpcharne()

Definition at line 784 of file varchar.c.

785{

788 int len1,

789 len2;

790 bool result;

793

795

798

800

802 {

803

804

805

806

807 if (len1 != len2)

808 result = true;

809 else

811 }

812 else

813 {

816 }

817

820

822}

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

bpcharoctetlen()

bpcharout()

bpcharrecv()

Definition at line 230 of file varchar.c.

231{

233#ifdef NOT_USED

235#endif

238 char *str;

239 int nbytes;

240

245}

void pfree(void *pointer)

char * pq_getmsgtext(StringInfo msg, int rawbytes, int *nbytes)

StringInfoData * StringInfo

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

bpcharsend()

Definition at line 251 of file varchar.c.

252{

253

255}

Datum textsend(PG_FUNCTION_ARGS)

References textsend().

bpchartruelen()

int bpchartruelen ( char * s,
int len
)

bpchartypmodin()

bpchartypmodout()

btbpchar_pattern_cmp()

btbpchar_pattern_sortsupport()

char_bpchar()

check_collation_set()

static void check_collation_set ( Oid collid) static

Definition at line 727 of file varchar.c.

728{

730 {

731

732

733

734

736 (errcode(ERRCODE_INDETERMINATE_COLLATION),

737 errmsg("could not determine which collation to use for string comparison"),

738 errhint("Use the COLLATE clause to set the collation explicitly.")));

739 }

740}

#define OidIsValid(objectId)

int errhint(const char *fmt,...)

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

Referenced by bpchareq(), and bpcharne().

hashbpchar()

Definition at line 988 of file varchar.c.

989{

992 char *keydata;

993 int keylen;

996

999 (errcode(ERRCODE_INDETERMINATE_COLLATION),

1000 errmsg("could not determine which collation to use for string hashing"),

1001 errhint("Use the COLLATE clause to set the collation explicitly.")));

1002

1005

1007

1009 {

1010 result = hash_any((unsigned char *) keydata, keylen);

1011 }

1012 else

1013 {

1015 rsize;

1016 char *buf;

1017

1018 bsize = pg_strnxfrm(NULL, 0, keydata, keylen, mylocale);

1020

1021 rsize = pg_strnxfrm(buf, bsize + 1, keydata, keylen, mylocale);

1022

1023

1024 if (rsize > bsize)

1025 elog(ERROR, "pg_strnxfrm() returned unexpected result");

1026

1027

1028

1029

1030

1031

1032 result = hash_any((uint8_t *) buf, bsize + 1);

1033

1035 }

1036

1037

1039

1040 return result;

1041}

static Datum hash_any(const unsigned char *k, int keylen)

size_t pg_strnxfrm(char *dest, size_t destsize, const char *src, ssize_t srclen, pg_locale_t locale)

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

hashbpcharextended()

Definition at line 1044 of file varchar.c.

1045{

1048 char *keydata;

1049 int keylen;

1052

1055 (errcode(ERRCODE_INDETERMINATE_COLLATION),

1056 errmsg("could not determine which collation to use for string hashing"),

1057 errhint("Use the COLLATE clause to set the collation explicitly.")));

1058

1061

1063

1065 {

1068 }

1069 else

1070 {

1072 rsize;

1073 char *buf;

1074

1075 bsize = pg_strnxfrm(NULL, 0, keydata, keylen, mylocale);

1077

1078 rsize = pg_strnxfrm(buf, bsize + 1, keydata, keylen, mylocale);

1079

1080

1081 if (rsize > bsize)

1082 elog(ERROR, "pg_strnxfrm() returned unexpected result");

1083

1084

1085

1086

1087

1088

1091

1093 }

1094

1096

1097 return result;

1098}

#define PG_GETARG_INT64(n)

static Datum hash_any_extended(const unsigned char *k, int keylen, uint64 seed)

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

internal_bpchar_pattern_compare()

static int internal_bpchar_pattern_compare ( BpChar * arg1, BpChar * arg2 ) static

name_bpchar()

Definition at line 609 of file varchar.c.

610{

615 maxlen;

616 size_t maxmblen;

617 int i;

618 char *s_data;

619

623

624

625 if (maxlen < 0 || len <= maxlen)

627

628

629

630

632

633 if (!isExplicit)

634 {

635 for (i = maxmblen; i < len; i++)

636 if (s_data[i] != ' ')

638 (errcode(ERRCODE_STRING_DATA_RIGHT_TRUNCATION),

639 errmsg("value too long for type character varying(%d)",

640 maxlen)));

641 }

642

644 maxmblen));

645}

#define PG_GETARG_VARCHAR_PP(n)

#define PG_RETURN_VARCHAR_P(x)

text * cstring_to_text_with_len(const char *s, int len)

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, Node * escontext ) static

Definition at line 457 of file varchar.c.

458{

460 size_t maxlen;

461

462 maxlen = atttypmod - VARHDRSZ;

463

465 {

466

468 size_t j;

469

470 for (j = mbmaxlen; j < len; j++)

471 {

472 if (s[j] != ' ')

474 (errcode(ERRCODE_STRING_DATA_RIGHT_TRUNCATION),

475 errmsg("value too long for type character varying(%d)",

476 (int) maxlen)));

477 }

478

479 len = mbmaxlen;

480 }

481

482

483

484

485

487 return result;

488}

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

Referenced by varcharin(), and varcharrecv().

varchar_support()

Definition at line 565 of file varchar.c.

566{

568 Node *ret = NULL;

569

571 {

574 Node *typmod;

575

577

579

580 if (IsA(typmod, Const) && !((Const *) typmod)->constisnull)

581 {

587

588 if (new_typmod < 0 || (old_typmod >= 0 && old_max <= new_max))

590 }

591 }

592

594}

#define PG_RETURN_POINTER(x)

int32 exprTypmod(const Node *expr)

Node * relabel_to_typmod(Node *expr, int32 typmod)

#define IsA(nodeptr, _type_)

static int list_length(const List *l)

static int32 DatumGetInt32(Datum X)

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()

Definition at line 495 of file varchar.c.

496{

498#ifdef NOT_USED

500#endif

503

504 result = varchar_input(s, strlen(s), atttypmod, fcinfo->context);

506}

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

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

varcharout()

varcharrecv()

varcharsend()

varchartypmodin()

varchartypmodout()