PostgreSQL Source Code: src/backend/commands/copyfromparse.c Source File (original) (raw)

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

60

61#include <ctype.h>

63#include <sys/stat.h>

64

77

78#define ISOCTAL(c) (((c) >= '0') && ((c) <= '7'))

79#define OCTVALUE(c) ((c) - '0')

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

97#define IF_NEED_REFILL_AND_NOT_EOF_CONTINUE(extralen) \

98if (1) \

99{ \

100 if (input_buf_ptr + (extralen) >= copy_buf_len && !hit_eof) \

101 { \

102 input_buf_ptr = prev_raw_ptr; \

103 need_data = true; \

104 continue; \

105 } \

106} else ((void) 0)

107

108

109#define IF_NEED_REFILL_AND_EOF_BREAK(extralen) \

110if (1) \

111{ \

112 if (input_buf_ptr + (extralen) >= copy_buf_len && hit_eof) \

113 { \

114 if (extralen) \

115 input_buf_ptr = copy_buf_len; \

116 \

117 result = true; \

118 break; \

119 } \

120} else ((void) 0)

121

122

123

124

125

126#define REFILL_LINEBUF \

127if (1) \

128{ \

129 if (input_buf_ptr > cstate->input_buf_index) \

130 { \

131 appendBinaryStringInfo(&cstate->line_buf, \

132 cstate->input_buf + cstate->input_buf_index, \

133 input_buf_ptr - cstate->input_buf_index); \

134 cstate->input_buf_index = input_buf_ptr; \

135 } \

136} else ((void) 0)

137

138

140

141

142

148 Oid typioparam, int32 typmod,

149 bool *isnull);

153 bool *nulls,

154 bool is_csv);

156 char ***fields,

157 int *nfields,

158 bool is_csv);

159

160

161

163 int minread, int maxread);

168

169void

171{

175 int i;

176

180 for (i = 0; i < natts; i++)

185

187}

188

189void

191{

192 char readSig[11];

194

195

199 (errcode(ERRCODE_BAD_COPY_FILE_FORMAT),

200 errmsg("COPY file signature not recognized")));

201

204 (errcode(ERRCODE_BAD_COPY_FILE_FORMAT),

205 errmsg("invalid COPY file header (missing flags)")));

206 if ((tmp & (1 << 16)) != 0)

208 (errcode(ERRCODE_BAD_COPY_FILE_FORMAT),

209 errmsg("invalid COPY file header (WITH OIDS)")));

210 tmp &= ~(1 << 16);

211 if ((tmp >> 16) != 0)

213 (errcode(ERRCODE_BAD_COPY_FILE_FORMAT),

214 errmsg("unrecognized critical flags in COPY file header")));

215

217 tmp < 0)

219 (errcode(ERRCODE_BAD_COPY_FILE_FORMAT),

220 errmsg("invalid COPY file header (missing length)")));

221

222 while (tmp-- > 0)

223 {

226 (errcode(ERRCODE_BAD_COPY_FILE_FORMAT),

227 errmsg("invalid COPY file header (wrong length)")));

228 }

229}

230

231

232

233

234

235

236

237

238

239

240

241

242

243

244static int

246{

247 int bytesread = 0;

248

250 {

252 bytesread = fread(databuf, 1, maxread, cstate->copy_file);

256 errmsg("could not read from COPY file: %m")));

257 if (bytesread == 0)

259 break;

261 while (maxread > 0 && bytesread < minread && !cstate->raw_reached_eof)

262 {

263 int avail;

264

266 {

267

268 int mtype;

269 int maxmsglen;

270

271 readmessage:

275 if (mtype == EOF)

277 (errcode(ERRCODE_CONNECTION_FAILURE),

278 errmsg("unexpected EOF on client connection with an open transaction")));

279

280 switch (mtype)

281 {

284 break;

290 break;

291 default:

293 (errcode(ERRCODE_PROTOCOL_VIOLATION),

294 errmsg("unexpected message type 0x%02X during COPY from stdin",

295 mtype)));

296 maxmsglen = 0;

297 break;

298 }

299

302 (errcode(ERRCODE_CONNECTION_FAILURE),

303 errmsg("unexpected EOF on client connection with an open transaction")));

305

306 switch (mtype)

307 {

309 break;

311

313 return bytesread;

316 (errcode(ERRCODE_QUERY_CANCELED),

317 errmsg("COPY from stdin failed: %s",

319 break;

322

323

324

325

326

327

328

329 goto readmessage;

330 default:

331 Assert(false);

332 }

333 }

335 if (avail > maxread)

336 avail = maxread;

338 databuf = (void *) ((char *) databuf + avail);

339 maxread -= avail;

340 bytesread += avail;

341 }

342 break;

344 bytesread = cstate->data_source_cb(databuf, minread, maxread);

345 break;

346 }

347

348 return bytesread;

349}

350

351

352

353

354

355

356

357

358

359

360

361static inline bool

363{

365

367 {

368 *val = 0;

369 return false;

370 }

372 return true;

373}

374

375

376

377

378static inline bool

380{

382

384 {

385 *val = 0;

386 return false;

387 }

389 return true;

390}

391

392

393

394

395

396

397

398

399static void

401{

402

403

404

405

406

408 {

409

410

411

412

413

414

417 int nverified;

418

419 if (unverifiedlen == 0)

420 {

421

422

423

426 return;

427 }

428

429

430

431

432

434 cstate->raw_buf + preverifiedlen,

435 unverifiedlen);

436 if (nverified == 0)

437 {

438

439

440

441

442

443

444

445

446

449 return;

450 }

452 }

453 else

454 {

455

456

457

458 int nbytes;

459 unsigned char *src;

460 int srclen;

461 unsigned char *dst;

462 int dstlen;

463 int convertedlen;

464

466 {

467

468

469

472 return;

473 }

474

475

476

477

481 nbytes);

484 cstate->input_buf[nbytes] = '\0';

485

490

491

492

493

494

495

496

497

498

499

500

501

502

503

507 src, srclen,

508 dst, dstlen,

509 true);

510 if (convertedlen == 0)

511 {

512

513

514

515

516

517

518

519

522 return;

523 }

526 }

527}

528

529

530

531

532static void

534{

537

539 {

540

541

542

543

547 }

548 else

549 {

550

551

552

553

554

555

556

557

558 unsigned char *src;

559 int srclen;

560 unsigned char *dst;

561 int dstlen;

562

567

571 src, srclen,

572 dst, dstlen,

573 false);

574

575

576

577

578

579 elog(ERROR, "encoding conversion failed without error");

580 }

581}

582

583

584

585

586

587

588

589static void

591{

592 int nbytes;

593 int inbytes;

594

595

596

597

598

600 {

604 }

605

606

607

608

612 nbytes);

615

616

617

618

619

621 {

624 }

625

626

629 nbytes += inbytes;

630 cstate->raw_buf[nbytes] = '\0';

632

635

636 if (inbytes == 0)

638}

639

640

641

642

643

644

645

646

647

648

649static void

651{

653

654

655

656

657

658

660 {

664 }

665

666 for (;;)

667 {

668

670

671

673 return;

674

675

676

677

678

679

682

683

685 break;

686

687

690 }

691}

692

693

694

695

696

697

698

699

700static int

702{

703 int copied_bytes = 0;

704

706 {

707

710 copied_bytes = nbytes;

711 }

712 else

713 {

714

715

716

717

718 do

719 {

720 int copy_bytes;

721

722

724 {

727 break;

728 }

729

730

731 copy_bytes = Min(nbytes - copied_bytes, RAW_BUF_BYTES(cstate));

734 dest += copy_bytes;

735 copied_bytes += copy_bytes;

736 } while (copied_bytes < nbytes);

737 }

738

739 return copied_bytes;

740}

741

742

743

744

745

746bool

748{

751}

752

753

754

755

756

757

758

759

760

761

762

763

764

765

766

767

768

769

772{

773 int fldct;

774 bool done;

775

776

778

779

781 {

784

786

789

791 {

792 int fldnum;

793

794 if (is_csv)

796 else

798

801 (errcode(ERRCODE_BAD_COPY_FILE_FORMAT),

802 errmsg("wrong number of fields in header line: got %d, expected %d",

804

805 fldnum = 0;

807 {

809 char *colName;

811

812 Assert(fldnum < cstate->max_fields);

813

814 colName = cstate->raw_fields[fldnum++];

815 if (colName == NULL)

817 (errcode(ERRCODE_BAD_COPY_FILE_FORMAT),

818 errmsg("column name mismatch in header line field %d: got null value (\"%s\"), expected \"%s\"",

820

821 if (namestrcmp(&attr->attname, colName) != 0)

822 {

824 (errcode(ERRCODE_BAD_COPY_FILE_FORMAT),

825 errmsg("column name mismatch in header line field %d: got \"%s\", expected \"%s\"",

826 fldnum, colName, NameStr(attr->attname))));

827 }

828 }

829 }

830

831 if (done)

832 return false;

833 }

834

836

837

839

840

841

842

843

844

846 return false;

847

848

849 if (is_csv)

851 else

853

855 *nfields = fldct;

856 return true;

857}

858

859

860

861

862

863

864

865

866

867

868

869

870bool

873{

877 int i;

878 int *defmap = cstate->defmap;

880

882 num_phys_attrs = tupDesc->natts;

883

884

886 MemSet(nulls, true, num_phys_attrs * sizeof(bool));

887 MemSet(cstate->defaults, false, num_phys_attrs * sizeof(bool));

888

889

891 return false;

892

893

894

895

896

897

898 for (i = 0; i < num_defaults; i++)

899 {

900

901

902

903

904 Assert(econtext != NULL);

906

908 &nulls[defmap[i]]);

909 }

910

911 return true;

912}

913

914

915bool

917 bool *nulls)

918{

920}

921

922

923bool

925 bool *nulls)

926{

928}

929

930

931

932

933

934

935

939{

945 char **field_strings;

947 int fldct;

948 int fieldno;

950

953

954

956 return false;

957

958

959 if (attr_count > 0 && fldct > attr_count)

961 (errcode(ERRCODE_BAD_COPY_FILE_FORMAT),

962 errmsg("extra data after last expected column")));

963

964 fieldno = 0;

965

966

968 {

972

973 if (fieldno >= fldct)

975 (errcode(ERRCODE_BAD_COPY_FILE_FORMAT),

976 errmsg("missing data for column \"%s\"",

977 NameStr(att->attname))));

978 string = field_strings[fieldno++];

979

982 {

983

984 continue;

985 }

986

987 if (is_csv)

988 {

989 if (string == NULL &&

991 {

992

993

994

995

997 }

1000 {

1001

1002

1003

1004

1005

1006

1007 string = NULL;

1008 }

1009 }

1010

1013

1014 if (string != NULL)

1015 nulls[m] = false;

1016

1018 {

1019

1020 Assert(econtext != NULL);

1022

1024 }

1025

1026

1027

1028

1030 string,

1031 typioparams[m],

1032 att->atttypmod,

1035 {

1037

1039

1041 {

1042

1043

1044

1045

1046

1049

1051 {

1052 char *attval;

1053

1056 errmsg("skipping row due to data type incompatibility at line %" PRIu64 " for column \"%s\": \"%s\"",

1059 attval));

1061 }

1062 else

1064 errmsg("skipping row due to data type incompatibility at line %" PRIu64 " for column \"%s\": null input",

1067

1068

1070 }

1071

1072 return true;

1073 }

1074

1077 }

1078

1079 Assert(fieldno == attr_count);

1080

1081 return true;

1082}

1083

1084

1085bool

1087 bool *nulls)

1088{

1093 int16 fld_count;

1095

1098

1100

1102 {

1103

1104 return false;

1105 }

1106

1107 if (fld_count == -1)

1108 {

1109

1110

1111

1112

1113

1114

1115

1116

1117 char dummy;

1118

1121 (errcode(ERRCODE_BAD_COPY_FILE_FORMAT),

1122 errmsg("received copy data after EOF marker")));

1123 return false;

1124 }

1125

1126 if (fld_count != attr_count)

1128 (errcode(ERRCODE_BAD_COPY_FILE_FORMAT),

1129 errmsg("row field count is %d, expected %d",

1130 (int) fld_count, attr_count)));

1131

1133 {

1137

1140 &in_functions[m],

1141 typioparams[m],

1142 att->atttypmod,

1143 &nulls[m]);

1145 }

1146

1147 return true;

1148}

1149

1150

1151

1152

1153

1154

1155

1156

1157static bool

1159{

1160 bool result;

1161

1164

1165

1167

1168 if (result)

1169 {

1170

1171

1172

1173

1174

1176 {

1177 int inbytes;

1178

1179 do

1180 {

1183 } while (inbytes > 0);

1188 }

1189 }

1190 else

1191 {

1192

1193

1194

1195

1197 {

1203 break;

1209 break;

1216 break;

1218

1220 break;

1221 }

1222 }

1223

1224

1226

1227 return result;

1228}

1229

1230

1231

1232

1233static bool

1235{

1236 char *copy_input_buf;

1237 int input_buf_ptr;

1238 int copy_buf_len;

1239 bool need_data = false;

1240 bool hit_eof = false;

1241 bool result = false;

1242

1243

1244 bool in_quote = false,

1245 last_was_esc = false;

1246 char quotec = '\0';

1247 char escapec = '\0';

1248

1249 if (is_csv)

1250 {

1253

1254 if (quotec == escapec)

1255 escapec = '\0';

1256 }

1257

1258

1259

1260

1261

1262

1263

1264

1265

1266

1267

1268

1269

1270

1271

1272

1273

1274

1275

1276

1277

1278

1279

1280

1281

1282

1283 copy_input_buf = cstate->input_buf;

1286

1287 for (;;)

1288 {

1289 int prev_raw_ptr;

1290 char c;

1291

1292

1293

1294

1295

1296

1297

1298

1299

1300 if (input_buf_ptr >= copy_buf_len || need_data)

1301 {

1303

1305

1309

1310

1311

1312

1313

1315 {

1316 result = true;

1317 break;

1318 }

1319 need_data = false;

1320 }

1321

1322

1323 prev_raw_ptr = input_buf_ptr;

1324 c = copy_input_buf[input_buf_ptr++];

1325

1326 if (is_csv)

1327 {

1328

1329

1330

1331

1332

1333

1334 if (c == '\r')

1335 {

1337 }

1338

1339

1340

1341

1342

1343

1344

1345

1346

1347 if (in_quote && c == escapec)

1348 last_was_esc = !last_was_esc;

1349 if (c == quotec && !last_was_esc)

1350 in_quote = !in_quote;

1351 if (c != escapec)

1352 last_was_esc = false;

1353

1354

1355

1356

1357

1358

1359

1360 if (in_quote && c == (cstate->eol_type == EOL_NL ? '\n' : '\r'))

1362 }

1363

1364

1365 if (c == '\r' && (!is_csv || !in_quote))

1366 {

1367

1370 {

1371

1372

1373

1374

1375

1376

1378

1379

1380 c = copy_input_buf[input_buf_ptr];

1381

1382 if (c == '\n')

1383 {

1384 input_buf_ptr++;

1386 }

1387 else

1388 {

1389

1392 (errcode(ERRCODE_BAD_COPY_FILE_FORMAT),

1393 !is_csv ?

1394 errmsg("literal carriage return found in data") :

1395 errmsg("unquoted carriage return found in data"),

1396 !is_csv ?

1397 errhint("Use \"\\r\" to represent carriage return.") :

1398 errhint("Use quoted CSV field to represent carriage return.")));

1399

1400

1401

1402

1403

1405 }

1406 }

1409 (errcode(ERRCODE_BAD_COPY_FILE_FORMAT),

1410 !is_csv ?

1411 errmsg("literal carriage return found in data") :

1412 errmsg("unquoted carriage return found in data"),

1413 !is_csv ?

1414 errhint("Use \"\\r\" to represent carriage return.") :

1415 errhint("Use quoted CSV field to represent carriage return.")));

1416

1417 break;

1418 }

1419

1420

1421 if (c == '\n' && (!is_csv || !in_quote))

1422 {

1425 (errcode(ERRCODE_BAD_COPY_FILE_FORMAT),

1426 !is_csv ?

1427 errmsg("literal newline found in data") :

1428 errmsg("unquoted newline found in data"),

1429 !is_csv ?

1430 errhint("Use \"\\n\" to represent newline.") :

1431 errhint("Use quoted CSV field to represent newline.")));

1432 cstate->eol_type = EOL_NL;

1433

1434 break;

1435 }

1436

1437

1438

1439

1440

1441 if (c == '\\' && !is_csv)

1442 {

1443 char c2;

1444

1447

1448

1449

1450

1451

1452

1453

1454 c2 = copy_input_buf[input_buf_ptr];

1455

1456 if (c2 == '.')

1457 {

1458 input_buf_ptr++;

1460 {

1461

1463

1464 c2 = copy_input_buf[input_buf_ptr++];

1465

1466 if (c2 == '\n')

1468 (errcode(ERRCODE_BAD_COPY_FILE_FORMAT),

1469 errmsg("end-of-copy marker does not match previous newline style")));

1470 else if (c2 != '\r')

1472 (errcode(ERRCODE_BAD_COPY_FILE_FORMAT),

1473 errmsg("end-of-copy marker is not alone on its line")));

1474 }

1475

1476

1478

1479 c2 = copy_input_buf[input_buf_ptr++];

1480

1481 if (c2 != '\r' && c2 != '\n')

1483 (errcode(ERRCODE_BAD_COPY_FILE_FORMAT),

1484 errmsg("end-of-copy marker is not alone on its line")));

1485

1490 (errcode(ERRCODE_BAD_COPY_FILE_FORMAT),

1491 errmsg("end-of-copy marker does not match previous newline style")));

1492

1493

1494

1495

1499 (errcode(ERRCODE_BAD_COPY_FILE_FORMAT),

1500 errmsg("end-of-copy marker is not alone on its line")));

1501

1502

1503

1504

1506 result = true;

1507 break;

1508 }

1509 else

1510 {

1511

1512

1513

1514

1515

1516

1517

1518

1519 input_buf_ptr++;

1520 }

1521 }

1522 }

1523

1524

1525

1526

1528

1529 return result;

1530}

1531

1532

1533

1534

1535static int

1537{

1538 if (isdigit((unsigned char) hex))

1539 return hex - '0';

1540 else

1541 return tolower((unsigned char) hex) - 'a' + 10;

1542}

1543

1544

1545

1546

1547

1548

1549

1550

1551

1552

1553

1554

1555

1556

1557

1558

1559

1560

1561

1562

1563static int

1565{

1566 char delimc = cstate->opts.delim[0];

1567 int fieldno;

1568 char *output_ptr;

1569 char *cur_ptr;

1570 char *line_end_ptr;

1571

1572

1573

1574

1575

1577 {

1580 (errcode(ERRCODE_BAD_COPY_FILE_FORMAT),

1581 errmsg("extra data after last expected column")));

1582 return 0;

1583 }

1584

1586

1587

1588

1589

1590

1591

1592

1593

1597

1598

1601

1602

1603 fieldno = 0;

1604 for (;;)

1605 {

1606 bool found_delim = false;

1607 char *start_ptr;

1608 char *end_ptr;

1609 int input_len;

1610 bool saw_non_ascii = false;

1611

1612

1614 {

1618 }

1619

1620

1621 start_ptr = cur_ptr;

1622 cstate->raw_fields[fieldno] = output_ptr;

1623

1624

1625

1626

1627

1628

1629

1630

1631

1632

1633

1634

1635 for (;;)

1636 {

1637 char c;

1638

1639 end_ptr = cur_ptr;

1640 if (cur_ptr >= line_end_ptr)

1641 break;

1642 c = *cur_ptr++;

1643 if (c == delimc)

1644 {

1645 found_delim = true;

1646 break;

1647 }

1648 if (c == '\\')

1649 {

1650 if (cur_ptr >= line_end_ptr)

1651 break;

1652 c = *cur_ptr++;

1653 switch (c)

1654 {

1655 case '0':

1656 case '1':

1657 case '2':

1658 case '3':

1659 case '4':

1660 case '5':

1661 case '6':

1662 case '7':

1663 {

1664

1665 int val;

1666

1668 if (cur_ptr < line_end_ptr)

1669 {

1670 c = *cur_ptr;

1672 {

1673 cur_ptr++;

1675 if (cur_ptr < line_end_ptr)

1676 {

1677 c = *cur_ptr;

1679 {

1680 cur_ptr++;

1682 }

1683 }

1684 }

1685 }

1686 c = val & 0377;

1688 saw_non_ascii = true;

1689 }

1690 break;

1691 case 'x':

1692

1693 if (cur_ptr < line_end_ptr)

1694 {

1695 char hexchar = *cur_ptr;

1696

1697 if (isxdigit((unsigned char) hexchar))

1698 {

1700

1701 cur_ptr++;

1702 if (cur_ptr < line_end_ptr)

1703 {

1704 hexchar = *cur_ptr;

1705 if (isxdigit((unsigned char) hexchar))

1706 {

1707 cur_ptr++;

1709 }

1710 }

1711 c = val & 0xff;

1713 saw_non_ascii = true;

1714 }

1715 }

1716 break;

1717 case 'b':

1718 c = '\b';

1719 break;

1720 case 'f':

1721 c = '\f';

1722 break;

1723 case 'n':

1724 c = '\n';

1725 break;

1726 case 'r':

1727 c = '\r';

1728 break;

1729 case 't':

1730 c = '\t';

1731 break;

1732 case 'v':

1733 c = '\v';

1734 break;

1735

1736

1737

1738

1739

1740 }

1741 }

1742

1743

1744 *output_ptr++ = c;

1745 }

1746

1747

1748 input_len = end_ptr - start_ptr;

1750 strncmp(start_ptr, cstate->opts.null_print, input_len) == 0)

1752

1757 {

1758

1760

1761 if (cstate->defexprs[m] != NULL)

1762 {

1763

1765 }

1766 else

1767 {

1770

1772 (errcode(ERRCODE_BAD_COPY_FILE_FORMAT),

1773 errmsg("unexpected default marker in COPY data"),

1774 errdetail("Column \"%s\" has no default value.",

1775 NameStr(att->attname))));

1776 }

1777 }

1778 else

1779 {

1780

1781

1782

1783

1784

1785

1786 if (saw_non_ascii)

1787 {

1788 char *fld = cstate->raw_fields[fieldno];

1789

1791 }

1792 }

1793

1794

1795 *output_ptr++ = '\0';

1796

1797 fieldno++;

1798

1799 if (!found_delim)

1800 break;

1801 }

1802

1803

1804 output_ptr--;

1805 Assert(*output_ptr == '\0');

1807

1808 return fieldno;

1809}

1810

1811

1812

1813

1814

1815

1816

1817static int

1819{

1820 char delimc = cstate->opts.delim[0];

1821 char quotec = cstate->opts.quote[0];

1822 char escapec = cstate->opts.escape[0];

1823 int fieldno;

1824 char *output_ptr;

1825 char *cur_ptr;

1826 char *line_end_ptr;

1827

1828

1829

1830

1831

1833 {

1836 (errcode(ERRCODE_BAD_COPY_FILE_FORMAT),

1837 errmsg("extra data after last expected column")));

1838 return 0;

1839 }

1840

1842

1843

1844

1845

1846

1847

1848

1849

1853

1854

1857

1858

1859 fieldno = 0;

1860 for (;;)

1861 {

1862 bool found_delim = false;

1863 bool saw_quote = false;

1864 char *start_ptr;

1865 char *end_ptr;

1866 int input_len;

1867

1868

1870 {

1874 }

1875

1876

1877 start_ptr = cur_ptr;

1878 cstate->raw_fields[fieldno] = output_ptr;

1879

1880

1881

1882

1883

1884

1885

1886

1887 for (;;)

1888 {

1889 char c;

1890

1891

1892 for (;;)

1893 {

1894 end_ptr = cur_ptr;

1895 if (cur_ptr >= line_end_ptr)

1896 goto endfield;

1897 c = *cur_ptr++;

1898

1899 if (c == delimc)

1900 {

1901 found_delim = true;

1902 goto endfield;

1903 }

1904

1905 if (c == quotec)

1906 {

1907 saw_quote = true;

1908 break;

1909 }

1910

1911 *output_ptr++ = c;

1912 }

1913

1914

1915 for (;;)

1916 {

1917 end_ptr = cur_ptr;

1918 if (cur_ptr >= line_end_ptr)

1920 (errcode(ERRCODE_BAD_COPY_FILE_FORMAT),

1921 errmsg("unterminated CSV quoted field")));

1922

1923 c = *cur_ptr++;

1924

1925

1926 if (c == escapec)

1927 {

1928

1929

1930

1931

1932 if (cur_ptr < line_end_ptr)

1933 {

1934 char nextc = *cur_ptr;

1935

1936 if (nextc == escapec || nextc == quotec)

1937 {

1938 *output_ptr++ = nextc;

1939 cur_ptr++;

1940 continue;

1941 }

1942 }

1943 }

1944

1945

1946

1947

1948

1949

1950 if (c == quotec)

1951 break;

1952

1953

1954 *output_ptr++ = c;

1955 }

1956 }

1957endfield:

1958

1959

1960 *output_ptr++ = '\0';

1961

1962

1963 input_len = end_ptr - start_ptr;

1965 strncmp(start_ptr, cstate->opts.null_print, input_len) == 0)

1967

1972 {

1973

1975

1976 if (cstate->defexprs[m] != NULL)

1977 {

1978

1980 }

1981 else

1982 {

1985

1987 (errcode(ERRCODE_BAD_COPY_FILE_FORMAT),

1988 errmsg("unexpected default marker in COPY data"),

1989 errdetail("Column \"%s\" has no default value.",

1990 NameStr(att->attname))));

1991 }

1992 }

1993

1994 fieldno++;

1995

1996 if (!found_delim)

1997 break;

1998 }

1999

2000

2001 output_ptr--;

2002 Assert(*output_ptr == '\0');

2004

2005 return fieldno;

2006}

2007

2008

2009

2010

2011

2014 Oid typioparam, int32 typmod,

2015 bool *isnull)

2016{

2019

2022 (errcode(ERRCODE_BAD_COPY_FILE_FORMAT),

2023 errmsg("unexpected EOF in COPY data")));

2024 if (fld_size == -1)

2025 {

2026 *isnull = true;

2028 }

2029 if (fld_size < 0)

2031 (errcode(ERRCODE_BAD_COPY_FILE_FORMAT),

2032 errmsg("invalid field size")));

2033

2034

2036

2039 fld_size) != fld_size)

2041 (errcode(ERRCODE_BAD_COPY_FILE_FORMAT),

2042 errmsg("unexpected EOF in COPY data")));

2043

2046

2047

2049 typioparam, typmod);

2050

2051

2054 (errcode(ERRCODE_INVALID_BINARY_REPRESENTATION),

2055 errmsg("incorrect binary data format")));

2056

2057 *isnull = false;

2058 return result;

2059}

void pgstat_progress_update_param(int index, int64 val)

static Datum values[MAXATTR]

#define IS_HIGHBIT_SET(ch)

#define pg_attribute_always_inline

#define MemSet(start, val, len)

char * CopyLimitPrintoutLength(const char *str)

#define RAW_BUF_BYTES(cstate)

#define INPUT_BUF_BYTES(cstate)

static pg_attribute_always_inline bool CopyFromTextLikeOneRow(CopyFromState cstate, ExprContext *econtext, Datum *values, bool *nulls, bool is_csv)

static pg_attribute_always_inline bool NextCopyFromRawFieldsInternal(CopyFromState cstate, char ***fields, int *nfields, bool is_csv)

bool CopyFromTextOneRow(CopyFromState cstate, ExprContext *econtext, Datum *values, bool *nulls)

bool CopyFromCSVOneRow(CopyFromState cstate, ExprContext *econtext, Datum *values, bool *nulls)

static int CopyReadAttributesCSV(CopyFromState cstate)

static bool CopyGetInt16(CopyFromState cstate, int16 *val)

static void CopyConversionError(CopyFromState cstate)

static bool CopyGetInt32(CopyFromState cstate, int32 *val)

static void CopyLoadRawBuf(CopyFromState cstate)

static void CopyLoadInputBuf(CopyFromState cstate)

void ReceiveCopyBinaryHeader(CopyFromState cstate)

static int CopyGetData(CopyFromState cstate, void *databuf, int minread, int maxread)

static Datum CopyReadBinaryAttribute(CopyFromState cstate, FmgrInfo *flinfo, Oid typioparam, int32 typmod, bool *isnull)

static int GetDecimalFromHex(char hex)

void ReceiveCopyBegin(CopyFromState cstate)

static bool CopyReadLineText(CopyFromState cstate, bool is_csv)

#define IF_NEED_REFILL_AND_EOF_BREAK(extralen)

static int CopyReadAttributesText(CopyFromState cstate)

static const char BinarySignature[11]

#define IF_NEED_REFILL_AND_NOT_EOF_CONTINUE(extralen)

static bool CopyReadLine(CopyFromState cstate, bool is_csv)

static int CopyReadBinaryData(CopyFromState cstate, char *dest, int nbytes)

bool CopyFromBinaryOneRow(CopyFromState cstate, ExprContext *econtext, Datum *values, bool *nulls)

static void CopyConvertBuf(CopyFromState cstate)

bool NextCopyFrom(CopyFromState cstate, ExprContext *econtext, Datum *values, bool *nulls)

bool NextCopyFromRawFields(CopyFromState cstate, char ***fields, int *nfields)

int errcode_for_file_access(void)

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

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

int errcode(int sqlerrcode)

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

#define ereport(elevel,...)

static Datum ExecEvalExpr(ExprState *state, ExprContext *econtext, bool *isNull)

bool InputFunctionCallSafe(FmgrInfo *flinfo, char *str, Oid typioparam, int32 typmod, fmNodePtr escontext, Datum *result)

Datum ReceiveFunctionCall(FmgrInfo *flinfo, StringInfo buf, Oid typioparam, int32 typmod)

Assert(PointerIsAligned(start, uint64))

@ COPY_LOG_VERBOSITY_VERBOSE

if(TABLE==NULL||TABLE_index==NULL)

#define PQ_SMALL_MESSAGE_LIMIT

#define PQ_LARGE_MESSAGE_LIMIT

int GetDatabaseEncoding(void)

bool pg_verifymbstr(const char *mbstr, int len, bool noError)

int pg_do_encoding_conversion_buf(Oid proc, int src_encoding, int dest_encoding, unsigned char *src, int srclen, unsigned char *dest, int destlen, bool noError)

void report_invalid_encoding(int encoding, const char *mbstr, int len)

void * repalloc(void *pointer, Size size)

void pfree(void *pointer)

MemoryContext CurrentMemoryContext

#define HOLD_CANCEL_INTERRUPTS()

#define RESUME_CANCEL_INTERRUPTS()

int namestrcmp(Name name, const char *str)

FormData_pg_attribute * Form_pg_attribute

static int list_length(const List *l)

static int list_nth_int(const List *list, int n)

#define MAX_CONVERSION_INPUT_LENGTH

int pq_getmessage(StringInfo s, int maxlen)

void pq_startmsgread(void)

const char * pq_getmsgstring(StringInfo msg)

void pq_endmessage(StringInfo buf)

void pq_copymsgbytes(StringInfo msg, void *buf, int datalen)

void pq_beginmessage(StringInfo buf, char msgtype)

static void pq_sendbyte(StringInfo buf, uint8 byt)

static void pq_sendint16(StringInfo buf, uint16 i)

#define PROGRESS_COPY_BYTES_PROCESSED

#define PqMsg_CopyInResponse

#define RelationGetDescr(relation)

StringInfo makeStringInfo(void)

void resetStringInfo(StringInfo str)

void enlargeStringInfo(StringInfo str, int needed)

CopyLogVerbosityChoice log_verbosity

CopyOnErrorChoice on_error

CopyHeaderChoice header_line

bool * force_notnull_flags

bool(* CopyFromOneRow)(CopyFromState cstate, ExprContext *econtext, Datum *values, bool *nulls)

copy_data_source_cb data_source_cb

const struct CopyFromRoutine * routine

StringInfoData attribute_buf

bool * convert_select_flags

ErrorSaveContext * escontext

MemoryContext ecxt_per_tuple_memory

static FormData_pg_attribute * TupleDescAttr(TupleDesc tupdesc, int i)

int pg_encoding_verifymbstr(int encoding, const char *mbstr, int len)

int pg_encoding_max_length(int encoding)