@@ -8419,35 +8419,14 @@ void
8419
8419
getTableAttrs(Archive *fout, TableInfo *tblinfo, int numTables)
8420
8420
{
8421
8421
DumpOptions *dopt = fout->dopt;
8422
- int i,
8423
- j;
8424
8422
PQExpBuffer q = createPQExpBuffer();
8425
- int i_attnum;
8426
- int i_attname;
8427
- int i_atttypname;
8428
- int i_atttypmod;
8429
- int i_attstattarget;
8430
- int i_attstorage;
8431
- int i_typstorage;
8432
- int i_attnotnull;
8433
- int i_atthasdef;
8434
- int i_attidentity;
8435
- int i_attgenerated;
8436
- int i_attisdropped;
8437
- int i_attlen;
8438
- int i_attalign;
8439
- int i_attislocal;
8440
- int i_attoptions;
8441
- int i_attcollation;
8442
- int i_attfdwoptions;
8443
- int i_attmissingval;
8444
- PGresult *res;
8445
- int ntups;
8446
- bool hasdefaults;
8447
8423
8448
- for (i = 0; i < numTables; i++)
8424
+ for (int i = 0; i < numTables; i++)
8449
8425
{
8450
8426
TableInfo *tbinfo = &tblinfo[i];
8427
+ PGresult *res;
8428
+ int ntups;
8429
+ bool hasdefaults;
8451
8430
8452
8431
/* Don't bother to collect info for sequences */
8453
8432
if (tbinfo->relkind == RELKIND_SEQUENCE)
@@ -8485,27 +8464,27 @@ getTableAttrs(Archive *fout, TableInfo *tblinfo, int numTables)
8485
8464
"a.attislocal,\n"
8486
8465
"pg_catalog.format_type(t.oid, a.atttypmod) AS atttypname,\n");
8487
8466
8488
- if (fout->remoteVersion >= 120000)
8489
- appendPQExpBufferStr(q,
8490
- "a.attgenerated,\n");
8491
- else
8492
- appendPQExpBufferStr(q,
8493
- "'' AS attgenerated,\n");
8494
-
8495
- if (fout->remoteVersion >= 110000)
8467
+ if (fout->remoteVersion >= 90000)
8496
8468
appendPQExpBufferStr(q,
8497
- "CASE WHEN a.atthasmissing AND NOT a.attisdropped "
8498
- "THEN a.attmissingval ELSE null END AS attmissingval,\n");
8469
+ "array_to_string(a.attoptions, ', ') AS attoptions,\n");
8499
8470
else
8500
8471
appendPQExpBufferStr(q,
8501
- "NULL AS attmissingval ,\n");
8472
+ "'' AS attoptions ,\n");
8502
8473
8503
- if (fout->remoteVersion >= 100000)
8474
+ if (fout->remoteVersion >= 90100)
8475
+ {
8476
+ /*
8477
+ * Since we only want to dump COLLATE clauses for attributes whose
8478
+ * collation is different from their type's default, we use a CASE
8479
+ * here to suppress uninteresting attcollations cheaply.
8480
+ */
8504
8481
appendPQExpBufferStr(q,
8505
- "a.attidentity,\n");
8482
+ "CASE WHEN a.attcollation <> t.typcollation "
8483
+ "THEN a.attcollation ELSE 0 END AS attcollation,\n");
8484
+ }
8506
8485
else
8507
8486
appendPQExpBufferStr(q,
8508
- "'' AS attidentity ,\n");
8487
+ "0 AS attcollation ,\n");
8509
8488
8510
8489
if (fout->remoteVersion >= 90200)
8511
8490
appendPQExpBufferStr(q,
@@ -8519,27 +8498,27 @@ getTableAttrs(Archive *fout, TableInfo *tblinfo, int numTables)
8519
8498
appendPQExpBufferStr(q,
8520
8499
"'' AS attfdwoptions,\n");
8521
8500
8522
- if (fout->remoteVersion >= 90100)
8523
- {
8524
- /*
8525
- * Since we only want to dump COLLATE clauses for attributes whose
8526
- * collation is different from their type's default, we use a CASE
8527
- * here to suppress uninteresting attcollations cheaply.
8528
- */
8501
+ if (fout->remoteVersion >= 100000)
8529
8502
appendPQExpBufferStr(q,
8530
- "CASE WHEN a.attcollation <> t.typcollation "
8531
- "THEN a.attcollation ELSE 0 END AS attcollation,\n");
8532
- }
8503
+ "a.attidentity,\n");
8533
8504
else
8534
8505
appendPQExpBufferStr(q,
8535
- "0 AS attcollation ,\n");
8506
+ "'' AS attidentity ,\n");
8536
8507
8537
- if (fout->remoteVersion >= 90000 )
8508
+ if (fout->remoteVersion >= 110000 )
8538
8509
appendPQExpBufferStr(q,
8539
- "array_to_string(a.attoptions, ', ') AS attoptions\n");
8510
+ "CASE WHEN a.atthasmissing AND NOT a.attisdropped "
8511
+ "THEN a.attmissingval ELSE null END AS attmissingval,\n");
8540
8512
else
8541
8513
appendPQExpBufferStr(q,
8542
- "'' AS attoptions\n");
8514
+ "NULL AS attmissingval,\n");
8515
+
8516
+ if (fout->remoteVersion >= 120000)
8517
+ appendPQExpBufferStr(q,
8518
+ "a.attgenerated\n");
8519
+ else
8520
+ appendPQExpBufferStr(q,
8521
+ "'' AS attgenerated\n");
8543
8522
8544
8523
/* need left join here to not fail on dropped columns ... */
8545
8524
appendPQExpBuffer(q,
@@ -8554,26 +8533,6 @@ getTableAttrs(Archive *fout, TableInfo *tblinfo, int numTables)
8554
8533
8555
8534
ntups = PQntuples(res);
8556
8535
8557
- i_attnum = PQfnumber(res, "attnum");
8558
- i_attname = PQfnumber(res, "attname");
8559
- i_atttypname = PQfnumber(res, "atttypname");
8560
- i_atttypmod = PQfnumber(res, "atttypmod");
8561
- i_attstattarget = PQfnumber(res, "attstattarget");
8562
- i_attstorage = PQfnumber(res, "attstorage");
8563
- i_typstorage = PQfnumber(res, "typstorage");
8564
- i_attnotnull = PQfnumber(res, "attnotnull");
8565
- i_atthasdef = PQfnumber(res, "atthasdef");
8566
- i_attidentity = PQfnumber(res, "attidentity");
8567
- i_attgenerated = PQfnumber(res, "attgenerated");
8568
- i_attisdropped = PQfnumber(res, "attisdropped");
8569
- i_attlen = PQfnumber(res, "attlen");
8570
- i_attalign = PQfnumber(res, "attalign");
8571
- i_attislocal = PQfnumber(res, "attislocal");
8572
- i_attoptions = PQfnumber(res, "attoptions");
8573
- i_attcollation = PQfnumber(res, "attcollation");
8574
- i_attfdwoptions = PQfnumber(res, "attfdwoptions");
8575
- i_attmissingval = PQfnumber(res, "attmissingval");
8576
-
8577
8536
tbinfo->numatts = ntups;
8578
8537
tbinfo->attnames = (char **) pg_malloc(ntups * sizeof(char *));
8579
8538
tbinfo->atttypnames = (char **) pg_malloc(ntups * sizeof(char *));
@@ -8596,31 +8555,31 @@ getTableAttrs(Archive *fout, TableInfo *tblinfo, int numTables)
8596
8555
tbinfo->attrdefs = (AttrDefInfo **) pg_malloc(ntups * sizeof(AttrDefInfo *));
8597
8556
hasdefaults = false;
8598
8557
8599
- for (j = 0; j < ntups; j++)
8558
+ for (int j = 0; j < ntups; j++)
8600
8559
{
8601
- if (j + 1 != atoi(PQgetvalue(res, j, i_attnum )))
8560
+ if (j + 1 != atoi(PQgetvalue(res, j, PQfnumber(res, "attnum") )))
8602
8561
fatal("invalid column numbering in table \"%s\"",
8603
8562
tbinfo->dobj.name);
8604
- tbinfo->attnames[j] = pg_strdup(PQgetvalue(res, j, i_attname ));
8605
- tbinfo->atttypnames[j] = pg_strdup(PQgetvalue(res, j, i_atttypname ));
8606
- tbinfo->atttypmod[j] = atoi(PQgetvalue(res, j, i_atttypmod ));
8607
- tbinfo->attstattarget[j] = atoi(PQgetvalue(res, j, i_attstattarget ));
8608
- tbinfo->attstorage[j] = *(PQgetvalue(res, j, i_attstorage ));
8609
- tbinfo->typstorage[j] = *(PQgetvalue(res, j, i_typstorage ));
8610
- tbinfo->attidentity[j] = *(PQgetvalue(res, j, i_attidentity ));
8611
- tbinfo->attgenerated[j] = *(PQgetvalue(res, j, i_attgenerated ));
8563
+ tbinfo->attnames[j] = pg_strdup(PQgetvalue(res, j, PQfnumber(res, "attname") ));
8564
+ tbinfo->atttypnames[j] = pg_strdup(PQgetvalue(res, j, PQfnumber(res, "atttypname") ));
8565
+ tbinfo->atttypmod[j] = atoi(PQgetvalue(res, j, PQfnumber(res, "atttypmod") ));
8566
+ tbinfo->attstattarget[j] = atoi(PQgetvalue(res, j, PQfnumber(res, "attstattarget") ));
8567
+ tbinfo->attstorage[j] = *(PQgetvalue(res, j, PQfnumber(res, "attstorage") ));
8568
+ tbinfo->typstorage[j] = *(PQgetvalue(res, j, PQfnumber(res, "typstorage") ));
8569
+ tbinfo->attidentity[j] = *(PQgetvalue(res, j, PQfnumber(res, "attidentity") ));
8570
+ tbinfo->attgenerated[j] = *(PQgetvalue(res, j, PQfnumber(res, "attgenerated") ));
8612
8571
tbinfo->needs_override = tbinfo->needs_override || (tbinfo->attidentity[j] == ATTRIBUTE_IDENTITY_ALWAYS);
8613
- tbinfo->attisdropped[j] = (PQgetvalue(res, j, i_attisdropped )[0] == 't');
8614
- tbinfo->attlen[j] = atoi(PQgetvalue(res, j, i_attlen ));
8615
- tbinfo->attalign[j] = *(PQgetvalue(res, j, i_attalign ));
8616
- tbinfo->attislocal[j] = (PQgetvalue(res, j, i_attislocal )[0] == 't');
8617
- tbinfo->notnull[j] = (PQgetvalue(res, j, i_attnotnull )[0] == 't');
8618
- tbinfo->attoptions[j] = pg_strdup(PQgetvalue(res, j, i_attoptions ));
8619
- tbinfo->attcollation[j] = atooid(PQgetvalue(res, j, i_attcollation ));
8620
- tbinfo->attfdwoptions[j] = pg_strdup(PQgetvalue(res, j, i_attfdwoptions ));
8621
- tbinfo->attmissingval[j] = pg_strdup(PQgetvalue(res, j, i_attmissingval ));
8572
+ tbinfo->attisdropped[j] = (PQgetvalue(res, j, PQfnumber(res, "attisdropped") )[0] == 't');
8573
+ tbinfo->attlen[j] = atoi(PQgetvalue(res, j, PQfnumber(res, "attlen") ));
8574
+ tbinfo->attalign[j] = *(PQgetvalue(res, j, PQfnumber(res, "attalign") ));
8575
+ tbinfo->attislocal[j] = (PQgetvalue(res, j, PQfnumber(res, "attislocal") )[0] == 't');
8576
+ tbinfo->notnull[j] = (PQgetvalue(res, j, PQfnumber(res, "attnotnull") )[0] == 't');
8577
+ tbinfo->attoptions[j] = pg_strdup(PQgetvalue(res, j, PQfnumber(res, "attoptions") ));
8578
+ tbinfo->attcollation[j] = atooid(PQgetvalue(res, j, PQfnumber(res, "attcollation") ));
8579
+ tbinfo->attfdwoptions[j] = pg_strdup(PQgetvalue(res, j, PQfnumber(res, "attfdwoptions") ));
8580
+ tbinfo->attmissingval[j] = pg_strdup(PQgetvalue(res, j, PQfnumber(res, "attmissingval") ));
8622
8581
tbinfo->attrdefs[j] = NULL; /* fix below */
8623
- if (PQgetvalue(res, j, i_atthasdef )[0] == 't')
8582
+ if (PQgetvalue(res, j, PQfnumber(res, "atthasdef") )[0] == 't')
8624
8583
hasdefaults = true;
8625
8584
/* these flags will be set in flagInhAttrs() */
8626
8585
tbinfo->inhNotNull[j] = false;
@@ -8651,7 +8610,7 @@ getTableAttrs(Archive *fout, TableInfo *tblinfo, int numTables)
8651
8610
numDefaults = PQntuples(res);
8652
8611
attrdefs = (AttrDefInfo *) pg_malloc(numDefaults * sizeof(AttrDefInfo));
8653
8612
8654
- for (j = 0; j < numDefaults; j++)
8613
+ for (int j = 0; j < numDefaults; j++)
8655
8614
{
8656
8615
int adnum;
8657
8616
@@ -8783,7 +8742,7 @@ getTableAttrs(Archive *fout, TableInfo *tblinfo, int numTables)
8783
8742
constrs = (ConstraintInfo *) pg_malloc(numConstrs * sizeof(ConstraintInfo));
8784
8743
tbinfo->checkexprs = constrs;
8785
8744
8786
- for (j = 0; j < numConstrs; j++)
8745
+ for (int j = 0; j < numConstrs; j++)
8787
8746
{
8788
8747
bool validated = PQgetvalue(res, j, 5)[0] == 't';
8789
8748
0 commit comments