]> granicus.if.org Git - postgresql/blobdiff - src/test/regress/regress.c
Update copyright for the year 2010.
[postgresql] / src / test / regress / regress.c
index 44172452d6c35f3fa2938957c749ab9823230c97..ffbe4e37b8338e5f4f11eaf108e79fc0ddd3e21a 100644 (file)
 /*
- * $Header: /cvsroot/pgsql/src/test/regress/regress.c,v 1.35 1999/12/16 22:20:03 wieck Exp $
+ * $PostgreSQL: pgsql/src/test/regress/regress.c,v 1.72 2009/01/07 13:44:37 tgl Exp $
  */
 
-#include <float.h>                             /* faked on sunos */
-
 #include "postgres.h"
 
-#include "utils/geo_decls.h"   /* includes <math.h> */
-#include "executor/executor.h" /* For GetAttributeByName */
+#include <float.h>
+#include <math.h>
+
+#include "access/transam.h"
+#include "access/xact.h"
+#include "catalog/pg_type.h"
+#include "commands/sequence.h"
+#include "commands/trigger.h"
+#include "executor/executor.h"
+#include "executor/spi.h"
+#include "utils/builtins.h"
+#include "utils/geo_decls.h"
+
 
 #define P_MAXDIG 12
 #define LDELIM                 '('
 #define RDELIM                 ')'
 #define DELIM                  ','
 
-typedef void *TUPLE;
-
-extern double *regress_dist_ptpath(Point *pt, PATH *path);
-extern double *regress_path_dist(PATH *p1, PATH *p2);
+extern Datum regress_dist_ptpath(PG_FUNCTION_ARGS);
+extern Datum regress_path_dist(PG_FUNCTION_ARGS);
 extern PATH *poly2path(POLYGON *poly);
-extern Point *interpt_pp(PATH *p1, PATH *p2);
+extern Datum interpt_pp(PG_FUNCTION_ARGS);
 extern void regress_lseg_construct(LSEG *lseg, Point *pt1, Point *pt2);
-extern char overpaid(TUPLE tuple);
-extern int     boxarea(BOX *box);
+extern Datum overpaid(PG_FUNCTION_ARGS);
+extern Datum boxarea(PG_FUNCTION_ARGS);
 extern char *reverse_name(char *string);
+extern int     oldstyle_length(int n, text *t);
+extern Datum int44in(PG_FUNCTION_ARGS);
+extern Datum int44out(PG_FUNCTION_ARGS);
+
+#ifdef PG_MODULE_MAGIC
+PG_MODULE_MAGIC;
+#endif
+
 
 /*
-** Distance from a point to a path
-*/
-double *
-regress_dist_ptpath(pt, path)
-Point     *pt;
-PATH      *path;
+ * Distance from a point to a path
+ */
+PG_FUNCTION_INFO_V1(regress_dist_ptpath);
+
+Datum
+regress_dist_ptpath(PG_FUNCTION_ARGS)
 {
-       double     *result;
-       double     *tmp;
+       Point      *pt = PG_GETARG_POINT_P(0);
+       PATH       *path = PG_GETARG_PATH_P(1);
+       float8          result = 0.0;   /* keep compiler quiet */
+       float8          tmp;
        int                     i;
        LSEG            lseg;
 
        switch (path->npts)
        {
                case 0:
-                       result = palloc(sizeof(double));
-                       *result = Abs((double) DBL_MAX);        /* +infinity */
-                       break;
+                       PG_RETURN_NULL();
                case 1:
-                       result = point_distance(pt, &path->p[0]);
+                       result = point_dt(pt, &path->p[0]);
                        break;
                default:
 
                        /*
-                        * the distance from a point to a path is the smallest
-                        * distance from the point to any of its constituent segments.
+                        * the distance from a point to a path is the smallest distance
+                        * from the point to any of its constituent segments.
                         */
                        Assert(path->npts > 1);
-                       result = palloc(sizeof(double));
                        for (i = 0; i < path->npts - 1; ++i)
                        {
                                regress_lseg_construct(&lseg, &path->p[i], &path->p[i + 1]);
-                               tmp = dist_ps(pt, &lseg);
-                               if (i == 0 || *tmp < *result)
-                                       *result = *tmp;
-                               pfree(tmp);
-
+                               tmp = DatumGetFloat8(DirectFunctionCall2(dist_ps,
+                                                                                                                PointPGetDatum(pt),
+                                                                                                         LsegPGetDatum(&lseg)));
+                               if (i == 0 || tmp < result)
+                                       result = tmp;
                        }
                        break;
        }
-       return result;
+       PG_RETURN_FLOAT8(result);
 }
 
-/* this essentially does a cartesian product of the lsegs in the
-   two paths, and finds the min distance between any two lsegs */
-double *
-regress_path_dist(p1, p2)
-PATH      *p1;
-PATH      *p2;
+/*
+ * this essentially does a cartesian product of the lsegs in the
+ * two paths, and finds the min distance between any two lsegs
+ */
+PG_FUNCTION_INFO_V1(regress_path_dist);
+
+Datum
+regress_path_dist(PG_FUNCTION_ARGS)
 {
-       double     *min,
-                          *tmp;
+       PATH       *p1 = PG_GETARG_PATH_P(0);
+       PATH       *p2 = PG_GETARG_PATH_P(1);
+       bool            have_min = false;
+       float8          min = 0.0;              /* initialize to keep compiler quiet */
+       float8          tmp;
        int                     i,
                                j;
        LSEG            seg1,
                                seg2;
 
-       regress_lseg_construct(&seg1, &p1->p[0], &p1->p[1]);
-       regress_lseg_construct(&seg2, &p2->p[0], &p2->p[1]);
-       min = lseg_distance(&seg1, &seg2);
-
        for (i = 0; i < p1->npts - 1; i++)
+       {
                for (j = 0; j < p2->npts - 1; j++)
                {
                        regress_lseg_construct(&seg1, &p1->p[i], &p1->p[i + 1]);
                        regress_lseg_construct(&seg2, &p2->p[j], &p2->p[j + 1]);
 
-                       if (*min < *(tmp = lseg_distance(&seg1, &seg2)))
-                               *min = *tmp;
-                       pfree(tmp);
+                       tmp = DatumGetFloat8(DirectFunctionCall2(lseg_distance,
+                                                                                                        LsegPGetDatum(&seg1),
+                                                                                                        LsegPGetDatum(&seg2)));
+                       if (!have_min || tmp < min)
+                       {
+                               min = tmp;
+                               have_min = true;
+                       }
                }
+       }
+
+       if (!have_min)
+               PG_RETURN_NULL();
 
-       return min;
+       PG_RETURN_FLOAT8(min);
 }
 
 PATH *
-poly2path(poly)
-POLYGON    *poly;
+poly2path(POLYGON *poly)
 {
        int                     i;
        char       *output = (char *) palloc(2 * (P_MAXDIG + 1) * poly->npts + 64);
@@ -113,61 +137,63 @@ POLYGON    *poly;
 
        for (i = 0; i < poly->npts; i++)
        {
-               sprintf(buf, ",%*g,%*g", P_MAXDIG, poly->p[i].x, P_MAXDIG, poly->p[i].y);
+               snprintf(buf, sizeof(buf), ",%*g,%*g",
+                                P_MAXDIG, poly->p[i].x, P_MAXDIG, poly->p[i].y);
                strcat(output, buf);
        }
 
-       sprintf(buf, "%c", RDELIM);
+       snprintf(buf, sizeof(buf), "%c", RDELIM);
        strcat(output, buf);
-       return path_in(output);
+       return DatumGetPathP(DirectFunctionCall1(path_in,
+                                                                                        CStringGetDatum(output)));
 }
 
-/* return the point where two paths intersect. Assumes that they do. */
-Point *
-interpt_pp(p1, p2)
-PATH      *p1;
-PATH      *p2;
-{
+/* return the point where two paths intersect, or NULL if no intersection. */
+PG_FUNCTION_INFO_V1(interpt_pp);
 
-       Point      *retval;
+Datum
+interpt_pp(PG_FUNCTION_ARGS)
+{
+       PATH       *p1 = PG_GETARG_PATH_P(0);
+       PATH       *p2 = PG_GETARG_PATH_P(1);
        int                     i,
                                j;
        LSEG            seg1,
                                seg2;
-
-#ifdef NOT_USED
-       LINE       *ln;
-
-#endif
        bool            found;                  /* We've found the intersection */
 
        found = false;                          /* Haven't found it yet */
 
        for (i = 0; i < p1->npts - 1 && !found; i++)
+       {
+               regress_lseg_construct(&seg1, &p1->p[i], &p1->p[i + 1]);
                for (j = 0; j < p2->npts - 1 && !found; j++)
                {
-                       regress_lseg_construct(&seg1, &p1->p[i], &p1->p[i + 1]);
                        regress_lseg_construct(&seg2, &p2->p[j], &p2->p[j + 1]);
-                       if (lseg_intersect(&seg1, &seg2))
+                       if (DatumGetBool(DirectFunctionCall2(lseg_intersect,
+                                                                                                LsegPGetDatum(&seg1),
+                                                                                                LsegPGetDatum(&seg2))))
                                found = true;
                }
+       }
 
-#ifdef NOT_USED
-       ln = line_construct_pp(&seg2.p[0], &seg2.p[1]);
-       retval = interpt_sl(&seg1, ln);
-#endif
-       retval = lseg_interpt(&seg1, &seg2);
-
-       return retval;
+       if (!found)
+               PG_RETURN_NULL();
+
+       /*
+        * Note: DirectFunctionCall2 will kick out an error if lseg_interpt()
+        * returns NULL, but that should be impossible since we know the two
+        * segments intersect.
+        */
+       PG_RETURN_DATUM(DirectFunctionCall2(lseg_interpt,
+                                                                               LsegPGetDatum(&seg1),
+                                                                               LsegPGetDatum(&seg2)));
 }
 
 
 /* like lseg_construct, but assume space already allocated */
 void
-regress_lseg_construct(lseg, pt1, pt2)
-LSEG      *lseg;
-Point     *pt1;
-Point     *pt2;
+regress_lseg_construct(LSEG *lseg, Point *pt1, Point *pt2)
 {
        lseg->p[0].x = pt1->x;
        lseg->p[0].y = pt1->y;
@@ -176,16 +202,19 @@ Point        *pt2;
        lseg->m = point_sl(pt1, pt2);
 }
 
+PG_FUNCTION_INFO_V1(overpaid);
 
-char
-overpaid(tuple)
-TUPLE          tuple;
+Datum
+overpaid(PG_FUNCTION_ARGS)
 {
+       HeapTupleHeader tuple = PG_GETARG_HEAPTUPLEHEADER(0);
        bool            isnull;
-       long            salary;
+       int32           salary;
 
-       salary = (long) GetAttributeByName(tuple, "salary", &isnull);
-       return salary > 699;
+       salary = DatumGetInt32(GetAttributeByName(tuple, "salary", &isnull));
+       if (isnull)
+               PG_RETURN_NULL();
+       PG_RETURN_BOOL(salary > 699);
 }
 
 /* New type "widget"
@@ -197,17 +226,16 @@ typedef struct
 {
        Point           center;
        double          radius;
-}                      WIDGET;
+}      WIDGET;
 
 WIDGET    *widget_in(char *str);
 char      *widget_out(WIDGET * widget);
-int                    pt_in_widget(Point *point, WIDGET * widget);
+extern Datum pt_in_widget(PG_FUNCTION_ARGS);
 
 #define NARGS  3
 
 WIDGET *
-widget_in(str)
-char      *str;
+widget_in(char *str)
 {
        char       *p,
                           *coord[NARGS],
@@ -227,14 +255,13 @@ char         *str;
        result->center.y = atof(coord[1]);
        result->radius = atof(coord[2]);
 
-       sprintf(buf2, "widget_in: read (%f, %f, %f)\n", result->center.x,
-                       result->center.y, result->radius);
+       snprintf(buf2, sizeof(buf2), "widget_in: read (%f, %f, %f)\n",
+                        result->center.x, result->center.y, result->radius);
        return result;
 }
 
 char *
-widget_out(widget)
-WIDGET    *widget;
+widget_out(WIDGET * widget)
 {
        char       *result;
 
@@ -247,46 +274,39 @@ WIDGET       *widget;
        return result;
 }
 
-int
-pt_in_widget(point, widget)
-Point     *point;
-WIDGET    *widget;
+PG_FUNCTION_INFO_V1(pt_in_widget);
+
+Datum
+pt_in_widget(PG_FUNCTION_ARGS)
 {
-       extern double point_dt();
+       Point      *point = PG_GETARG_POINT_P(0);
+       WIDGET     *widget = (WIDGET *) PG_GETARG_POINTER(1);
 
-       return point_dt(point, &widget->center) < widget->radius;
+       PG_RETURN_BOOL(point_dt(point, &widget->center) < widget->radius);
 }
 
-#define ABS(X) ((X) > 0 ? (X) : -(X))
-
-int
-boxarea(box)
-
-BOX               *box;
+PG_FUNCTION_INFO_V1(boxarea);
 
+Datum
+boxarea(PG_FUNCTION_ARGS)
 {
-       int                     width,
+       BOX                *box = PG_GETARG_BOX_P(0);
+       double          width,
                                height;
 
-       width = ABS(box->high.x - box->low.x);
-       height = ABS(box->high.y - box->low.y);
-       return width * height;
+       width = Abs(box->high.x - box->low.x);
+       height = Abs(box->high.y - box->low.y);
+       PG_RETURN_FLOAT8(width * height);
 }
 
 char *
-reverse_name(string)
-char      *string;
+reverse_name(char *string)
 {
        int                     i;
        int                     len;
        char       *new_string;
 
-       if (!(new_string = palloc(NAMEDATALEN)))
-       {
-               fprintf(stderr, "reverse_name: palloc failed\n");
-               return NULL;
-       }
-       MemSet(new_string, 0, NAMEDATALEN);
+       new_string = palloc0(NAMEDATALEN);
        for (i = 0; i < NAMEDATALEN && string[i]; ++i)
                ;
        if (i == NAMEDATALEN || !string[i])
@@ -297,8 +317,21 @@ char          *string;
        return new_string;
 }
 
-#include "executor/spi.h"              /* this is what you need to work with SPI */
-#include "commands/trigger.h"  /* -"- and triggers */
+/*
+ * This rather silly function is just to test that oldstyle functions
+ * work correctly on toast-able inputs.
+ */
+int
+oldstyle_length(int n, text *t)
+{
+       int                     len = 0;
+
+       if (t)
+               len = VARSIZE(t) - VARHDRSZ;
+
+       return n + len;
+}
+
 
 static TransactionId fd17b_xid = InvalidTransactionId;
 static TransactionId fd17a_xid = InvalidTransactionId;
@@ -306,11 +339,14 @@ static int        fd17b_level = 0;
 static int     fd17a_level = 0;
 static bool fd17b_recursion = true;
 static bool fd17a_recursion = true;
-HeapTuple      funny_dup17(void);
+extern Datum funny_dup17(PG_FUNCTION_ARGS);
+
+PG_FUNCTION_INFO_V1(funny_dup17);
 
-HeapTuple                                              /* have to return HeapTuple to Executor */
-funny_dup17()
+Datum
+funny_dup17(PG_FUNCTION_ARGS)
 {
+       TriggerData *trigdata = (TriggerData *) fcinfo->context;
        TransactionId *xid;
        int                *level;
        bool       *recursion;
@@ -325,10 +361,13 @@ funny_dup17()
        int                     selected = 0;
        int                     ret;
 
-       tuple = CurrentTriggerData->tg_trigtuple;
-       rel = CurrentTriggerData->tg_relation;
+       if (!CALLED_AS_TRIGGER(fcinfo))
+               elog(ERROR, "funny_dup17: not fired by trigger manager");
+
+       tuple = trigdata->tg_trigtuple;
+       rel = trigdata->tg_relation;
        tupdesc = rel->rd_att;
-       if (TRIGGER_FIRED_BEFORE(CurrentTriggerData->tg_event))
+       if (TRIGGER_FIRED_BEFORE(trigdata->tg_event))
        {
                xid = &fd17b_xid;
                level = &fd17b_level;
@@ -343,8 +382,6 @@ funny_dup17()
                when = "AFTER ";
        }
 
-       CurrentTriggerData = NULL;
-
        if (!TransactionIdIsCurrentTransactionId(*xid))
        {
                *xid = GetCurrentTransactionId();
@@ -355,11 +392,11 @@ funny_dup17()
        if (*level == 17)
        {
                *recursion = false;
-               return tuple;
+               return PointerGetDatum(tuple);
        }
 
        if (!(*recursion))
-               return tuple;
+               return PointerGetDatum(tuple);
 
        (*level)++;
 
@@ -368,7 +405,7 @@ funny_dup17()
        fieldval = SPI_getvalue(tuple, tupdesc, 1);
        fieldtype = SPI_gettype(tupdesc, 1);
 
-       query = (char *) palloc(100 + NAMEDATALEN*3 +
+       query = (char *) palloc(100 + NAMEDATALEN * 3 +
                                                        strlen(fieldval) + strlen(fieldtype));
 
        sprintf(query, "insert into %s select * from %s where %s = '%s'::%s",
@@ -393,16 +430,15 @@ funny_dup17()
 
        if (SPI_processed > 0)
        {
-               selected = int4in(
-                                                 SPI_getvalue(
-                                                                          SPI_tuptable->vals[0],
-                                                                          SPI_tuptable->tupdesc,
-                                                                          1
-                                                                          )
-                       );
+               selected = DatumGetInt32(DirectFunctionCall1(int4in,
+                                                                                               CStringGetDatum(SPI_getvalue(
+                                                                                                          SPI_tuptable->vals[0],
+                                                                                                          SPI_tuptable->tupdesc,
+                                                                                                                                                        1
+                                                                                                                                               ))));
        }
 
-       elog(NOTICE, "funny_dup17 (fired %s) on level %3d: %d/%d tuples inserted/selected",
+       elog(DEBUG4, "funny_dup17 (fired %s) on level %3d: %d/%d tuples inserted/selected",
                 when, *level, inserted, selected);
 
        SPI_finish();
@@ -412,22 +448,23 @@ funny_dup17()
        if (*level == 0)
                *xid = InvalidTransactionId;
 
-       return tuple;
+       return PointerGetDatum(tuple);
 }
 
-HeapTuple      ttdummy(void);
-int32          set_ttdummy(int32 on);
-
-extern int4 nextval(struct varlena * seqin);
+extern Datum ttdummy(PG_FUNCTION_ARGS);
+extern Datum set_ttdummy(PG_FUNCTION_ARGS);
 
 #define TTDUMMY_INFINITY       999999
 
-static void *splan = NULL;
+static SPIPlanPtr splan = NULL;
 static bool ttoff = false;
 
-HeapTuple
-ttdummy()
+PG_FUNCTION_INFO_V1(ttdummy);
+
+Datum
+ttdummy(PG_FUNCTION_ARGS)
 {
+       TriggerData *trigdata = (TriggerData *) fcinfo->context;
        Trigger    *trigger;            /* to get trigger name */
        char      **args;                       /* arguments */
        int                     attnum[2];              /* fnumbers of start/stop columns */
@@ -448,30 +485,30 @@ ttdummy()
        int                     ret;
        int                     i;
 
-       if (!CurrentTriggerData)
-               elog(ERROR, "ttdummy: triggers are not initialized");
-       if (TRIGGER_FIRED_FOR_STATEMENT(CurrentTriggerData->tg_event))
-               elog(ERROR, "ttdummy: can't process STATEMENT events");
-       if (TRIGGER_FIRED_AFTER(CurrentTriggerData->tg_event))
+       if (!CALLED_AS_TRIGGER(fcinfo))
+               elog(ERROR, "ttdummy: not fired by trigger manager");
+       if (TRIGGER_FIRED_FOR_STATEMENT(trigdata->tg_event))
+               elog(ERROR, "ttdummy: cannot process STATEMENT events");
+       if (TRIGGER_FIRED_AFTER(trigdata->tg_event))
                elog(ERROR, "ttdummy: must be fired before event");
-       if (TRIGGER_FIRED_BY_INSERT(CurrentTriggerData->tg_event))
-               elog(ERROR, "ttdummy: can't process INSERT event");
-       if (TRIGGER_FIRED_BY_UPDATE(CurrentTriggerData->tg_event))
-               newtuple = CurrentTriggerData->tg_newtuple;
+       if (TRIGGER_FIRED_BY_INSERT(trigdata->tg_event))
+               elog(ERROR, "ttdummy: cannot process INSERT event");
+       if (TRIGGER_FIRED_BY_UPDATE(trigdata->tg_event))
+               newtuple = trigdata->tg_newtuple;
 
-       trigtuple = CurrentTriggerData->tg_trigtuple;
+       trigtuple = trigdata->tg_trigtuple;
 
-       rel = CurrentTriggerData->tg_relation;
+       rel = trigdata->tg_relation;
        relname = SPI_getrelname(rel);
 
        /* check if TT is OFF for this relation */
        if (ttoff)                                      /* OFF - nothing to do */
        {
                pfree(relname);
-               return (newtuple != NULL) ? newtuple : trigtuple;
+               return PointerGetDatum((newtuple != NULL) ? newtuple : trigtuple);
        }
 
-       trigger = CurrentTriggerData->tg_trigger;
+       trigger = trigdata->tg_trigger;
 
        if (trigger->tgnargs != 2)
                elog(ERROR, "ttdummy (%s): invalid (!= 2) number of arguments %d",
@@ -481,8 +518,6 @@ ttdummy()
        tupdesc = rel->rd_att;
        natts = tupdesc->natts;
 
-       CurrentTriggerData = NULL;
-
        for (i = 0; i < 2; i++)
        {
                attnum[i] = SPI_fnumber(tupdesc, args[i]);
@@ -511,27 +546,24 @@ ttdummy()
                        elog(ERROR, "ttdummy (%s): %s must be NOT NULL", relname, args[1]);
 
                if (oldon != newon || oldoff != newoff)
-                       elog(ERROR, "ttdummy (%s): you can't change %s and/or %s columns (use set_ttdummy)",
+                       elog(ERROR, "ttdummy (%s): you cannot change %s and/or %s columns (use set_ttdummy)",
                                 relname, args[0], args[1]);
 
                if (newoff != TTDUMMY_INFINITY)
                {
                        pfree(relname);         /* allocated in upper executor context */
-                       return NULL;
+                       return PointerGetDatum(NULL);
                }
        }
        else if (oldoff != TTDUMMY_INFINITY)            /* DELETE */
        {
                pfree(relname);
-               return NULL;
+               return PointerGetDatum(NULL);
        }
 
-       {
-               struct varlena *seqname = textin("ttdummy_seq");
-
-               newoff = nextval(seqname);
-               pfree(seqname);
-       }
+       newoff = DirectFunctionCall1(nextval, CStringGetTextDatum("ttdummy_seq"));
+       /* nextval now returns int64; coerce down to int32 */
+       newoff = Int32GetDatum((int32) DatumGetInt64(newoff));
 
        /* Connect to SPI manager */
        if ((ret = SPI_connect()) < 0)
@@ -556,7 +588,7 @@ ttdummy()
                cnulls[attnum[1] - 1] = ' ';
        }
        else
-/* DELETE */
+               /* DELETE */
        {
                cvals[attnum[1] - 1] = newoff;  /* stop_date eq current date */
                cnulls[attnum[1] - 1] = ' ';
@@ -565,7 +597,7 @@ ttdummy()
        /* if there is no plan ... */
        if (splan == NULL)
        {
-               void       *pplan;
+               SPIPlanPtr      pplan;
                Oid                *ctypes;
                char       *query;
 
@@ -611,37 +643,97 @@ ttdummy()
                SPI_freetuple(tmptuple);
        }
        else
-/* DELETE */
+               /* DELETE */
                rettuple = trigtuple;
 
        SPI_finish();                           /* don't forget say Bye to SPI mgr */
 
        pfree(relname);
 
-       return rettuple;
+       return PointerGetDatum(rettuple);
 }
 
-int32
-set_ttdummy(int32 on)
+PG_FUNCTION_INFO_V1(set_ttdummy);
+
+Datum
+set_ttdummy(PG_FUNCTION_ARGS)
 {
+       int32           on = PG_GETARG_INT32(0);
 
        if (ttoff)                                      /* OFF currently */
        {
                if (on == 0)
-                       return 0;
+                       PG_RETURN_INT32(0);
 
                /* turn ON */
                ttoff = false;
-               return 0;
+               PG_RETURN_INT32(0);
        }
 
        /* ON currently */
        if (on != 0)
-               return 1;
+               PG_RETURN_INT32(1);
 
        /* turn OFF */
        ttoff = true;
 
-       return 1;
+       PG_RETURN_INT32(1);
+}
+
 
+/*
+ * Type int44 has no real-world use, but the regression tests use it.
+ * It's a four-element vector of int4's.
+ */
+
+/*
+ *             int44in                 - converts "num num ..." to internal form
+ *
+ *             Note: Fills any missing positions with zeroes.
+ */
+PG_FUNCTION_INFO_V1(int44in);
+
+Datum
+int44in(PG_FUNCTION_ARGS)
+{
+       char       *input_string = PG_GETARG_CSTRING(0);
+       int32      *result = (int32 *) palloc(4 * sizeof(int32));
+       int                     i;
+
+       i = sscanf(input_string,
+                          "%d, %d, %d, %d",
+                          &result[0],
+                          &result[1],
+                          &result[2],
+                          &result[3]);
+       while (i < 4)
+               result[i++] = 0;
+
+       PG_RETURN_POINTER(result);
+}
+
+/*
+ *             int44out                - converts internal form to "num num ..."
+ */
+PG_FUNCTION_INFO_V1(int44out);
+
+Datum
+int44out(PG_FUNCTION_ARGS)
+{
+       int32      *an_array = (int32 *) PG_GETARG_POINTER(0);
+       char       *result = (char *) palloc(16 * 4);           /* Allow 14 digits +
+                                                                                                                * sign */
+       int                     i;
+       char       *walk;
+
+       walk = result;
+       for (i = 0; i < 4; i++)
+       {
+               pg_ltoa(an_array[i], walk);
+               while (*++walk != '\0')
+                       ;
+               *walk++ = ' ';
+       }
+       *--walk = '\0';
+       PG_RETURN_CSTRING(result);
 }