4646#include "utils/lsyscache.h"
4747
4848#include <unistd.h>
49- #if PG_VERSION_NUM >= 120000
5049#include "access/external.h"
51- #endif
5250
5351PG_FUNCTION_INFO_V1 (gpdbwritableformatter_export );
5452PG_FUNCTION_INFO_V1 (gpdbwritableformatter_import );
@@ -106,7 +104,6 @@ typedef struct
106104/* Bit flag */
107105#define GPDBWRITABLE_BITFLAG_ISNULL 1 /* Column is null */
108106
109- #if PG_VERSION_NUM >= 90400
110107/*
111108 * appendStringInfoFill
112109 *
@@ -128,7 +125,6 @@ appendStringInfoFill(StringInfo str, int occurrences, char ch)
128125 str -> len += occurrences ;
129126 str -> data [str -> len ] = '\0' ;
130127}
131- #endif
132128
133129#ifndef unlikely
134130#if __GNUC__ > 3
@@ -148,11 +144,6 @@ appendStringInfoFill(StringInfo str, int occurrences, char ch)
148144 } \
149145 } while (0)
150146
151- #if PG_VERSION_NUM < 90400
152- // Copied from tupdesc.h (6.x), since this is not present in GPDB 5
153- /* Accessor for the i'th attribute of tupdesc. */
154- #define TupleDescAttr (tupdesc , i ) ((tupdesc)->attrs[(i)])
155- #endif
156147
157148/*
158149 * Write a int4 to the buffer
@@ -512,27 +503,20 @@ gpdbwritableformatter_export(PG_FUNCTION_ARGS)
512503 */
513504 if (myData == NULL )
514505 {
515- // In GP7 FORMATTER_GET_EXTENCODING(fcinfo) gets the database encoding which may not match the table encoding
516- // and thus results in exception here. So getting the table encoding from the ExtTableEntry
517- #if PG_VERSION_NUM < 120000
518- if (FORMATTER_GET_EXTENCODING (fcinfo ) != PG_UTF8 )
519- {
520- ereport (ERROR , (errcode (ERRCODE_EXTERNAL_ROUTINE_EXCEPTION ),
521- errmsg (FORMATTER_ENCODING_ERR_MSG , "export" )));
522- }
523- #else
506+ // FORMATTER_GET_EXTENCODING(fcinfo) may return database encoding; use table encoding instead.
524507 Relation rel = FORMATTER_GET_RELATION (fcinfo );
525- if (rel == NULL ) {
508+ if (rel == NULL )
509+ {
526510 ereport (ERROR , (errcode (ERRCODE_EXTERNAL_ROUTINE_EXCEPTION ),
527511 errmsg (FORMATTER_ENCODING_ERR_MSG , "export" )));
528512 }
529513
530514 ExtTableEntry * exttbl = GetExtTableEntry (rel -> rd_id );
531- if (exttbl -> encoding != PG_UTF8 ) {
515+ if (exttbl -> encoding != PG_UTF8 )
516+ {
532517 ereport (ERROR , (errcode (ERRCODE_EXTERNAL_ROUTINE_EXCEPTION ),
533- errmsg (FORMATTER_ENCODING_ERR_MSG , "export" )));
518+ errmsg (FORMATTER_ENCODING_ERR_MSG , "export" )));
534519 }
535- #endif
536520
537521 myData = palloc (sizeof (format_t ));
538522 myData -> values = palloc (sizeof (Datum ) * ncolumns );
@@ -785,27 +769,20 @@ gpdbwritableformatter_import(PG_FUNCTION_ARGS)
785769 */
786770 if (myData == NULL )
787771 {
788- // In GP7 FORMATTER_GET_EXTENCODING(fcinfo) gets the database encoding which may not match the table encoding
789- // and thus results in exception here. So getting the table encoding from the ExtTableEntry
790- #if PG_VERSION_NUM < 120000
791- if (FORMATTER_GET_EXTENCODING (fcinfo ) != PG_UTF8 )
792- {
793- ereport (ERROR , (errcode (ERRCODE_EXTERNAL_ROUTINE_EXCEPTION ),
794- errmsg (FORMATTER_ENCODING_ERR_MSG , "import" )));
795- }
796- #else
797- Relation rel = FORMATTER_GET_RELATION (fcinfo );
798- if (rel == NULL ) {
799- ereport (ERROR , (errcode (ERRCODE_EXTERNAL_ROUTINE_EXCEPTION ),
800- errmsg (FORMATTER_ENCODING_ERR_MSG , "import" )));
801- }
802-
803- ExtTableEntry * exttbl = GetExtTableEntry (rel -> rd_id );
804- if (exttbl -> encoding != PG_UTF8 ) {
805- ereport (ERROR , (errcode (ERRCODE_EXTERNAL_ROUTINE_EXCEPTION ),
806- errmsg (FORMATTER_ENCODING_ERR_MSG , "import" )));
807- }
808- #endif
772+ // FORMATTER_GET_EXTENCODING(fcinfo) may return database encoding; use table encoding instead.
773+ Relation rel = FORMATTER_GET_RELATION (fcinfo );
774+ if (rel == NULL )
775+ {
776+ ereport (ERROR , (errcode (ERRCODE_EXTERNAL_ROUTINE_EXCEPTION ),
777+ errmsg (FORMATTER_ENCODING_ERR_MSG , "import" )));
778+ }
779+
780+ ExtTableEntry * exttbl = GetExtTableEntry (rel -> rd_id );
781+ if (exttbl -> encoding != PG_UTF8 )
782+ {
783+ ereport (ERROR , (errcode (ERRCODE_EXTERNAL_ROUTINE_EXCEPTION ),
784+ errmsg (FORMATTER_ENCODING_ERR_MSG , "import" )));
785+ }
809786
810787 myData = palloc (sizeof (format_t ));
811788 myData -> values = palloc (sizeof (Datum ) * ncolumns );
@@ -1045,11 +1022,7 @@ static inline Form_pg_attribute
10451022getAttributeFromTupleDesc (TupleDesc tupdesc , int index )
10461023{
10471024 Form_pg_attribute attr ;
1048- #if PG_VERSION_NUM >= 120000
1049- attr = & tupdesc -> attrs [index ];
1050- #else
1051- attr = tupdesc -> attrs [index ];
1052- #endif
1025+ attr = & tupdesc -> attrs [index ];
10531026
10541027 return attr ;
10551028
0 commit comments