Skip to content

Commit 0ea9467

Browse files
committed
Merge branch 'master' into rel_future_beta
2 parents fb7c67e + 5c36a5d commit 0ea9467

File tree

3 files changed

+82
-1
lines changed

3 files changed

+82
-1
lines changed

src/compat/pg_compat.c

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include "optimizer/prep.h"
2525
#include "parser/parse_utilcmd.h"
2626
#include "port.h"
27+
#include "utils/builtins.h"
2728
#include "utils/lsyscache.h"
2829
#include "utils/syscache.h"
2930

@@ -520,6 +521,73 @@ get_rel_persistence(Oid relid)
520521
#endif
521522

522523

524+
#if (PG_VERSION_NUM >= 90500 && PG_VERSION_NUM <= 90505) || \
525+
(PG_VERSION_NUM >= 90600 && PG_VERSION_NUM <= 90601)
526+
/*
527+
* Return a palloc'd bare attribute map for tuple conversion, matching input
528+
* and output columns by name. (Dropped columns are ignored in both input and
529+
* output.) This is normally a subroutine for convert_tuples_by_name, but can
530+
* be used standalone.
531+
*/
532+
AttrNumber *
533+
convert_tuples_by_name_map(TupleDesc indesc,
534+
TupleDesc outdesc,
535+
const char *msg)
536+
{
537+
AttrNumber *attrMap;
538+
int n;
539+
int i;
540+
541+
n = outdesc->natts;
542+
attrMap = (AttrNumber *) palloc0(n * sizeof(AttrNumber));
543+
for (i = 0; i < n; i++)
544+
{
545+
Form_pg_attribute att = outdesc->attrs[i];
546+
char *attname;
547+
Oid atttypid;
548+
int32 atttypmod;
549+
int j;
550+
551+
if (att->attisdropped)
552+
continue; /* attrMap[i] is already 0 */
553+
attname = NameStr(att->attname);
554+
atttypid = att->atttypid;
555+
atttypmod = att->atttypmod;
556+
for (j = 0; j < indesc->natts; j++)
557+
{
558+
att = indesc->attrs[j];
559+
if (att->attisdropped)
560+
continue;
561+
if (strcmp(attname, NameStr(att->attname)) == 0)
562+
{
563+
/* Found it, check type */
564+
if (atttypid != att->atttypid || atttypmod != att->atttypmod)
565+
ereport(ERROR,
566+
(errcode(ERRCODE_DATATYPE_MISMATCH),
567+
errmsg_internal("%s", _(msg)),
568+
errdetail("Attribute \"%s\" of type %s does not match corresponding attribute of type %s.",
569+
attname,
570+
format_type_be(outdesc->tdtypeid),
571+
format_type_be(indesc->tdtypeid))));
572+
attrMap[i] = (AttrNumber) (j + 1);
573+
break;
574+
}
575+
}
576+
if (attrMap[i] == 0)
577+
ereport(ERROR,
578+
(errcode(ERRCODE_DATATYPE_MISMATCH),
579+
errmsg_internal("%s", _(msg)),
580+
errdetail("Attribute \"%s\" of type %s does not exist in type %s.",
581+
attname,
582+
format_type_be(outdesc->tdtypeid),
583+
format_type_be(indesc->tdtypeid))));
584+
}
585+
586+
return attrMap;
587+
}
588+
#endif
589+
590+
523591

524592
/*
525593
* -------------

src/include/compat/pg_compat.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -549,6 +549,20 @@ extern void set_rel_consider_parallel(PlannerInfo *root,
549549
#endif
550550

551551

552+
/*
553+
* convert_tuples_by_name_map()
554+
*/
555+
#if (PG_VERSION_NUM >= 90500 && PG_VERSION_NUM <= 90505) || \
556+
(PG_VERSION_NUM >= 90600 && PG_VERSION_NUM <= 90601)
557+
extern AttrNumber *convert_tuples_by_name_map(TupleDesc indesc,
558+
TupleDesc outdesc,
559+
const char *msg);
560+
#else
561+
#include "access/tupconvert.h"
562+
#endif
563+
564+
565+
552566
/*
553567
* -------------
554568
* Common code

src/pl_funcs.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
#include "xact_handling.h"
1919
#include "utils.h"
2020

21-
#include "access/tupconvert.h"
2221
#include "access/htup_details.h"
2322
#include "catalog/dependency.h"
2423
#include "catalog/indexing.h"

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy