printtup.c 16.9 KB
Newer Older
1 2
/*-------------------------------------------------------------------------
 *
3
 * printtup.c
4
 *	  Routines to print out tuples to the destination (both frontend
5
 *	  clients and standalone backends are supported here).
6
 *
7
 *
P
 
PostgreSQL Daemon 已提交
8
 * Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
B
Add:  
Bruce Momjian 已提交
9
 * Portions Copyright (c) 1994, Regents of the University of California
10 11
 *
 * IDENTIFICATION
12
 *	  $PostgreSQL: pgsql/src/backend/access/common/printtup.c,v 1.87 2005/03/16 21:38:04 tgl Exp $
13 14 15
 *
 *-------------------------------------------------------------------------
 */
16 17 18 19
#include "postgres.h"

#include "access/heapam.h"
#include "access/printtup.h"
20
#include "libpq/libpq.h"
21
#include "libpq/pqformat.h"
22
#include "utils/lsyscache.h"
23
#include "utils/portal.h"
24

M
Marc G. Fournier 已提交
25

26
static void printtup_startup(DestReceiver *self, int operation,
B
Bruce Momjian 已提交
27
				 TupleDesc typeinfo);
28 29 30
static void printtup(TupleTableSlot *slot, DestReceiver *self);
static void printtup_20(TupleTableSlot *slot, DestReceiver *self);
static void printtup_internal_20(TupleTableSlot *slot, DestReceiver *self);
31 32 33
static void printtup_shutdown(DestReceiver *self);
static void printtup_destroy(DestReceiver *self);

34

35
/* ----------------------------------------------------------------
36
 *		printtup / debugtup support
37 38 39
 * ----------------------------------------------------------------
 */

40 41
/* ----------------
 *		Private state for a printtup destination object
42 43 44
 *
 * NOTE: finfo is the lookup info for either typoutput or typsend, whichever
 * we are using for this column.
45 46
 * ----------------
 */
B
Bruce Momjian 已提交
47 48
typedef struct
{								/* Per-attribute information */
49 50
	Oid			typoutput;		/* Oid for the type's text output fn */
	Oid			typsend;		/* Oid for the type's binary output fn */
51
	Oid			typioparam;		/* param to pass to the output fn */
52
	bool		typisvarlena;	/* is it varlena (ie possibly toastable)? */
53 54
	int16		format;			/* format code for this column */
	FmgrInfo	finfo;			/* Precomputed call info for output fn */
55
} PrinttupAttrInfo;
56

B
Bruce Momjian 已提交
57 58 59
typedef struct
{
	DestReceiver pub;			/* publicly-known function pointers */
60
	Portal		portal;			/* the Portal we are printing from */
61
	bool		sendDescrip;	/* send RowDescription at startup? */
B
Bruce Momjian 已提交
62 63 64
	TupleDesc	attrinfo;		/* The attr info we are set up for */
	int			nattrs;
	PrinttupAttrInfo *myinfo;	/* Cached info about each attr */
65
} DR_printtup;
66 67 68 69 70

/* ----------------
 *		Initialize: create a DestReceiver for printtup
 * ----------------
 */
B
Bruce Momjian 已提交
71
DestReceiver *
72
printtup_create_DR(CommandDest dest, Portal portal)
73
{
B
Bruce Momjian 已提交
74
	DR_printtup *self = (DR_printtup *) palloc(sizeof(DR_printtup));
75

76
	if (PG_PROTOCOL_MAJOR(FrontendProtocol) >= 3)
77
		self->pub.receiveSlot = printtup;
78
	else
79
	{
80
		/*
B
Bruce Momjian 已提交
81 82
		 * In protocol 2.0 the Bind message does not exist, so there is no
		 * way for the columns to have different print formats; it's
83 84 85
		 * sufficient to look at the first one.
		 */
		if (portal->formats && portal->formats[0] != 0)
86
			self->pub.receiveSlot = printtup_internal_20;
87
		else
88
			self->pub.receiveSlot = printtup_20;
89
	}
90 91 92
	self->pub.rStartup = printtup_startup;
	self->pub.rShutdown = printtup_shutdown;
	self->pub.rDestroy = printtup_destroy;
93
	self->pub.mydest = dest;
94

95 96 97 98
	self->portal = portal;

	/* Send T message automatically if Remote, but not if RemoteExecute */
	self->sendDescrip = (dest == Remote);
99

100 101 102 103
	self->attrinfo = NULL;
	self->nattrs = 0;
	self->myinfo = NULL;

B
Bruce Momjian 已提交
104
	return (DestReceiver *) self;
105 106 107
}

static void
108
printtup_startup(DestReceiver *self, int operation, TupleDesc typeinfo)
109
{
110
	DR_printtup *myState = (DR_printtup *) self;
B
Bruce Momjian 已提交
111
	Portal		portal = myState->portal;
112

113 114 115
	if (PG_PROTOCOL_MAJOR(FrontendProtocol) < 3)
	{
		/*
B
Bruce Momjian 已提交
116 117
		 * Send portal name to frontend (obsolete cruft, gone in proto
		 * 3.0)
118 119 120
		 *
		 * If portal name not specified, use "blank" portal.
		 */
121 122 123
		const char *portalName = portal->name;

		if (portalName == NULL || portalName[0] == '\0')
124 125 126 127
			portalName = "blank";

		pq_puttextmessage('P', portalName);
	}
128 129

	/*
B
Bruce Momjian 已提交
130 131
	 * If this is a retrieve, and we are supposed to emit row
	 * descriptions, then we send back the tuple descriptor of the tuples.
132
	 */
133
	if (operation == CMD_SELECT && myState->sendDescrip)
134 135 136 137
	{
		List	   *targetlist;

		if (portal->strategy == PORTAL_ONE_SELECT)
138
			targetlist = ((Query *) linitial(portal->parseTrees))->targetList;
139 140 141 142 143
		else
			targetlist = NIL;

		SendRowDescriptionMessage(typeinfo, targetlist, portal->formats);
	}
144

145 146
	/* ----------------
	 * We could set up the derived attr info at this time, but we postpone it
147
	 * until the first call of printtup, for 2 reasons:
148
	 * 1. We don't waste time (compared to the old way) if there are no
B
Bruce Momjian 已提交
149
	 *	  tuples at all to output.
150
	 * 2. Checking in printtup allows us to handle the case that the tuples
B
Bruce Momjian 已提交
151 152
	 *	  change type midway through (although this probably can't happen in
	 *	  the current executor).
153 154 155 156
	 * ----------------
	 */
}

157 158
/*
 * SendRowDescriptionMessage --- send a RowDescription message to the frontend
159 160 161 162
 *
 * Notes: the TupleDesc has typically been manufactured by ExecTypeFromTL()
 * or some similar function; it does not contain a full set of fields.
 * The targetlist will be NIL when executing a utility function that does
163
 * not have a plan.  If the targetlist isn't NIL then it is a Query node's
B
Bruce Momjian 已提交
164
 * targetlist; it is up to us to ignore resjunk columns in it.	The formats[]
165 166
 * array pointer might be NULL (if we are doing Describe on a prepared stmt);
 * send zeroes for the format codes in that case.
167 168
 */
void
169
SendRowDescriptionMessage(TupleDesc typeinfo, List *targetlist, int16 *formats)
170 171 172 173 174 175
{
	Form_pg_attribute *attrs = typeinfo->attrs;
	int			natts = typeinfo->natts;
	int			proto = PG_PROTOCOL_MAJOR(FrontendProtocol);
	int			i;
	StringInfoData buf;
176
	ListCell   *tlist_item = list_head(targetlist);
177

B
Bruce Momjian 已提交
178 179
	pq_beginmessage(&buf, 'T'); /* tuple descriptor message type */
	pq_sendint(&buf, natts, 2); /* # of attrs in tuples */
180 181 182

	for (i = 0; i < natts; ++i)
	{
B
Bruce Momjian 已提交
183 184 185
		Oid			atttypid = attrs[i]->atttypid;
		int32		atttypmod = attrs[i]->atttypmod;
		Oid			basetype;
186

187 188 189 190
		pq_sendstring(&buf, NameStr(attrs[i]->attname));
		/* column ID info appears in protocol 3.0 and up */
		if (proto >= 3)
		{
191
			/* Do we have a non-resjunk tlist item? */
192 193 194 195
			while (tlist_item &&
				   ((TargetEntry *) lfirst(tlist_item))->resdom->resjunk)
				tlist_item = lnext(tlist_item);
			if (tlist_item)
196
			{
197
				Resdom	   *res = ((TargetEntry *) lfirst(tlist_item))->resdom;
198 199 200

				pq_sendint(&buf, res->resorigtbl, 4);
				pq_sendint(&buf, res->resorigcol, 2);
201
				tlist_item = lnext(tlist_item);
202 203 204 205 206 207 208
			}
			else
			{
				/* No info available, so send zeroes */
				pq_sendint(&buf, 0, 4);
				pq_sendint(&buf, 0, 2);
			}
209
		}
210 211 212 213 214 215 216 217 218
		/* If column is a domain, send the base type and typmod instead */
		basetype = getBaseType(atttypid);
		if (basetype != atttypid)
		{
			atttypmod = get_typtypmod(atttypid);
			atttypid = basetype;
		}
		pq_sendint(&buf, (int) atttypid, sizeof(atttypid));
		pq_sendint(&buf, attrs[i]->attlen, sizeof(attrs[i]->attlen));
219 220
		/* typmod appears in protocol 2.0 and up */
		if (proto >= 2)
221
			pq_sendint(&buf, atttypmod, sizeof(atttypmod));
222 223 224 225 226 227 228 229
		/* format info appears in protocol 3.0 and up */
		if (proto >= 3)
		{
			if (formats)
				pq_sendint(&buf, formats[i], 2);
			else
				pq_sendint(&buf, 0, 2);
		}
230 231 232 233
	}
	pq_endmessage(&buf);
}

234 235 236
/*
 * Get the lookup info that printtup() needs
 */
237
static void
238
printtup_prepare_info(DR_printtup *myState, TupleDesc typeinfo, int numAttrs)
239
{
240
	int16	   *formats = myState->portal->formats;
B
Bruce Momjian 已提交
241
	int			i;
242

243
	/* get rid of any old data */
244
	if (myState->myinfo)
245
		pfree(myState->myinfo);
246
	myState->myinfo = NULL;
247

248 249 250 251
	myState->attrinfo = typeinfo;
	myState->nattrs = numAttrs;
	if (numAttrs <= 0)
		return;
252

B
Bruce Momjian 已提交
253
	myState->myinfo = (PrinttupAttrInfo *)
254
		palloc0(numAttrs * sizeof(PrinttupAttrInfo));
255

256 257
	for (i = 0; i < numAttrs; i++)
	{
B
Bruce Momjian 已提交
258
		PrinttupAttrInfo *thisState = myState->myinfo + i;
259
		int16		format = (formats ? formats[i] : 0);
B
Bruce Momjian 已提交
260

261 262 263 264 265
		thisState->format = format;
		if (format == 0)
		{
			getTypeOutputInfo(typeinfo->attrs[i]->atttypid,
							  &thisState->typoutput,
266
							  &thisState->typioparam,
267
							  &thisState->typisvarlena);
268
			fmgr_info(thisState->typoutput, &thisState->finfo);
269 270 271 272 273
		}
		else if (format == 1)
		{
			getTypeBinaryOutputInfo(typeinfo->attrs[i]->atttypid,
									&thisState->typsend,
274
									&thisState->typioparam,
275 276 277 278
									&thisState->typisvarlena);
			fmgr_info(thisState->typsend, &thisState->finfo);
		}
		else
279 280 281
			ereport(ERROR,
					(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
					 errmsg("unsupported format code: %d", format)));
282 283 284
	}
}

285
/* ----------------
286
 *		printtup --- print a tuple in protocol 3.0
287 288
 * ----------------
 */
289
static void
290
printtup(TupleTableSlot *slot, DestReceiver *self)
291
{
292
	TupleDesc typeinfo = slot->tts_tupleDescriptor;
293 294
	DR_printtup *myState = (DR_printtup *) self;
	StringInfoData buf;
295
	int			natts = typeinfo->natts;
296 297 298 299 300 301
	int			i;

	/* Set or update my derived attribute info, if needed */
	if (myState->attrinfo != typeinfo || myState->nattrs != natts)
		printtup_prepare_info(myState, typeinfo, natts);

302 303
	/* Make sure the tuple is fully deconstructed */
	slot_getallattrs(slot);
304

305 306 307 308 309 310 311 312 313 314 315 316 317
	/*
	 * Prepare a DataRow message
	 */
	pq_beginmessage(&buf, 'D');

	pq_sendint(&buf, natts, 2);

	/*
	 * send the attributes of this tuple
	 */
	for (i = 0; i < natts; ++i)
	{
		PrinttupAttrInfo *thisState = myState->myinfo + i;
318
		Datum		origattr = slot->tts_values[i],
319 320
					attr;

321
		if (slot->tts_isnull[i])
322 323 324 325 326
		{
			pq_sendint(&buf, -1, 4);
			continue;
		}

327
		/*
B
Bruce Momjian 已提交
328 329
		 * If we have a toasted datum, forcibly detoast it here to avoid
		 * memory leakage inside the type's output routine.
330 331 332 333 334
		 */
		if (thisState->typisvarlena)
			attr = PointerGetDatum(PG_DETOAST_DATUM(origattr));
		else
			attr = origattr;
335

336
		if (thisState->format == 0)
337
		{
338 339 340 341 342
			/* Text output */
			char	   *outputstr;

			outputstr = DatumGetCString(FunctionCall3(&thisState->finfo,
													  attr,
B
Bruce Momjian 已提交
343
								 ObjectIdGetDatum(thisState->typioparam),
344 345 346
						  Int32GetDatum(typeinfo->attrs[i]->atttypmod)));
			pq_sendcountedtext(&buf, outputstr, strlen(outputstr), false);
			pfree(outputstr);
347 348 349
		}
		else
		{
350 351 352 353 354
			/* Binary output */
			bytea	   *outputbytes;

			outputbytes = DatumGetByteaP(FunctionCall2(&thisState->finfo,
													   attr,
B
Bruce Momjian 已提交
355
							   ObjectIdGetDatum(thisState->typioparam)));
356 357 358 359 360
			/* We assume the result will not have been toasted */
			pq_sendint(&buf, VARSIZE(outputbytes) - VARHDRSZ, 4);
			pq_sendbytes(&buf, VARDATA(outputbytes),
						 VARSIZE(outputbytes) - VARHDRSZ);
			pfree(outputbytes);
361
		}
362 363 364 365

		/* Clean up detoasted copy, if any */
		if (attr != origattr)
			pfree(DatumGetPointer(attr));
366 367 368 369 370 371 372 373 374 375
	}

	pq_endmessage(&buf);
}

/* ----------------
 *		printtup_20 --- print a tuple in protocol 2.0
 * ----------------
 */
static void
376
printtup_20(TupleTableSlot *slot, DestReceiver *self)
377
{
378
	TupleDesc typeinfo = slot->tts_tupleDescriptor;
B
Bruce Momjian 已提交
379
	DR_printtup *myState = (DR_printtup *) self;
380
	StringInfoData buf;
381
	int			natts = typeinfo->natts;
382 383
	int			i,
				j,
384
				k;
385

386
	/* Set or update my derived attribute info, if needed */
387 388
	if (myState->attrinfo != typeinfo || myState->nattrs != natts)
		printtup_prepare_info(myState, typeinfo, natts);
389

390 391
	/* Make sure the tuple is fully deconstructed */
	slot_getallattrs(slot);
392

393 394
	/*
	 * tell the frontend to expect new tuple data (in ASCII style)
395
	 */
396
	pq_beginmessage(&buf, 'D');
397

398 399
	/*
	 * send a bitmap of which attributes are not null
400 401 402
	 */
	j = 0;
	k = 1 << 7;
403
	for (i = 0; i < natts; ++i)
404
	{
405
		if (slot->tts_isnull[i])
406
			j |= k;				/* set bit if not null */
407
		k >>= 1;
408
		if (k == 0)				/* end of byte? */
409
		{
410
			pq_sendint(&buf, j, 1);
411 412 413
			j = 0;
			k = 1 << 7;
		}
414
	}
415
	if (k != (1 << 7))			/* flush last partial byte */
416
		pq_sendint(&buf, j, 1);
417

418 419
	/*
	 * send the attributes of this tuple
420
	 */
421
	for (i = 0; i < natts; ++i)
422
	{
B
Bruce Momjian 已提交
423
		PrinttupAttrInfo *thisState = myState->myinfo + i;
424
		Datum		origattr = slot->tts_values[i],
425 426
					attr;
		char	   *outputstr;
B
Bruce Momjian 已提交
427

428
		if (slot->tts_isnull[i])
M
 
Marc G. Fournier 已提交
429
			continue;
430

431 432 433
		Assert(thisState->format == 0);

		/*
B
Bruce Momjian 已提交
434 435
		 * If we have a toasted datum, forcibly detoast it here to avoid
		 * memory leakage inside the type's output routine.
436 437 438 439 440 441 442 443
		 */
		if (thisState->typisvarlena)
			attr = PointerGetDatum(PG_DETOAST_DATUM(origattr));
		else
			attr = origattr;

		outputstr = DatumGetCString(FunctionCall3(&thisState->finfo,
												  attr,
B
Bruce Momjian 已提交
444
								 ObjectIdGetDatum(thisState->typioparam),
B
Bruce Momjian 已提交
445
						  Int32GetDatum(typeinfo->attrs[i]->atttypmod)));
446 447
		pq_sendcountedtext(&buf, outputstr, strlen(outputstr), true);
		pfree(outputstr);
448

449 450 451
		/* Clean up detoasted copy, if any */
		if (attr != origattr)
			pfree(DatumGetPointer(attr));
452
	}
453 454

	pq_endmessage(&buf);
455 456
}

457
/* ----------------
458
 *		printtup_shutdown
459 460 461
 * ----------------
 */
static void
462
printtup_shutdown(DestReceiver *self)
463
{
B
Bruce Momjian 已提交
464 465
	DR_printtup *myState = (DR_printtup *) self;

466 467
	if (myState->myinfo)
		pfree(myState->myinfo);
468
	myState->myinfo = NULL;
469

470 471 472 473 474 475 476 477 478 479 480
	myState->attrinfo = NULL;
}

/* ----------------
 *		printtup_destroy
 * ----------------
 */
static void
printtup_destroy(DestReceiver *self)
{
	pfree(self);
481 482
}

483
/* ----------------
484
 *		printatt
485 486 487 488
 * ----------------
 */
static void
printatt(unsigned attributeId,
489
		 Form_pg_attribute attributeP,
490
		 char *value)
491
{
B
Bruce Momjian 已提交
492
	printf("\t%2d: %s%s%s%s\t(typeid = %u, len = %d, typmod = %d, byval = %c)\n",
493
		   attributeId,
494
		   NameStr(attributeP->attname),
495 496 497 498 499
		   value != NULL ? " = \"" : "",
		   value != NULL ? value : "",
		   value != NULL ? "\"" : "",
		   (unsigned int) (attributeP->atttypid),
		   attributeP->attlen,
B
Bruce Momjian 已提交
500
		   attributeP->atttypmod,
501
		   attributeP->attbyval ? 't' : 'f');
502 503 504
}

/* ----------------
505
 *		debugStartup - prepare to print tuples for an interactive backend
506 507 508
 * ----------------
 */
void
509
debugStartup(DestReceiver *self, int operation, TupleDesc typeinfo)
510
{
511 512 513 514
	int			natts = typeinfo->natts;
	Form_pg_attribute *attinfo = typeinfo->attrs;
	int			i;

515 516 517
	/*
	 * show the return type of the tuples
	 */
518
	for (i = 0; i < natts; ++i)
519
		printatt((unsigned) i + 1, attinfo[i], NULL);
520
	printf("\t----\n");
521 522 523 524
}

/* ----------------
 *		debugtup - print one tuple for an interactive backend
525 526 527
 * ----------------
 */
void
528
debugtup(TupleTableSlot *slot, DestReceiver *self)
529
{
530
	TupleDesc	typeinfo = slot->tts_tupleDescriptor;
531
	int			natts = typeinfo->natts;
532
	int			i;
533 534
	Datum		origattr,
				attr;
535
	char	   *value;
536
	bool		isnull;
537
	Oid			typoutput,
538
				typioparam;
539
	bool		typisvarlena;
540

541
	for (i = 0; i < natts; ++i)
542
	{
543
		origattr = slot_getattr(slot, i + 1, &isnull);
544 545
		if (isnull)
			continue;
546
		getTypeOutputInfo(typeinfo->attrs[i]->atttypid,
547
						  &typoutput, &typioparam, &typisvarlena);
B
Bruce Momjian 已提交
548

549
		/*
B
Bruce Momjian 已提交
550 551
		 * If we have a toasted datum, forcibly detoast it here to avoid
		 * memory leakage inside the type's output routine.
552 553 554 555 556
		 */
		if (typisvarlena)
			attr = PointerGetDatum(PG_DETOAST_DATUM(origattr));
		else
			attr = origattr;
557

558 559
		value = DatumGetCString(OidFunctionCall3(typoutput,
												 attr,
B
Bruce Momjian 已提交
560
											ObjectIdGetDatum(typioparam),
B
Bruce Momjian 已提交
561
						  Int32GetDatum(typeinfo->attrs[i]->atttypmod)));
562

563
		printatt((unsigned) i + 1, typeinfo->attrs[i], value);
564

565 566 567 568 569
		pfree(value);

		/* Clean up detoasted copy, if any */
		if (attr != origattr)
			pfree(DatumGetPointer(attr));
570
	}
571
	printf("\t----\n");
572 573 574
}

/* ----------------
575 576 577 578
 *		printtup_internal_20 --- print a binary tuple in protocol 2.0
 *
 * We use a different message type, i.e. 'B' instead of 'D' to
 * indicate a tuple in internal (binary) form.
579
 *
580
 * This is largely same as printtup_20, except we use binary formatting.
581 582
 * ----------------
 */
583
static void
584
printtup_internal_20(TupleTableSlot *slot, DestReceiver *self)
585
{
586
	TupleDesc typeinfo = slot->tts_tupleDescriptor;
587
	DR_printtup *myState = (DR_printtup *) self;
588
	StringInfoData buf;
589
	int			natts = typeinfo->natts;
590 591 592
	int			i,
				j,
				k;
593 594 595 596

	/* Set or update my derived attribute info, if needed */
	if (myState->attrinfo != typeinfo || myState->nattrs != natts)
		printtup_prepare_info(myState, typeinfo, natts);
597

598 599
	/* Make sure the tuple is fully deconstructed */
	slot_getallattrs(slot);
600

601 602
	/*
	 * tell the frontend to expect new tuple data (in binary style)
603
	 */
604
	pq_beginmessage(&buf, 'B');
605

606 607
	/*
	 * send a bitmap of which attributes are not null
608 609 610
	 */
	j = 0;
	k = 1 << 7;
611
	for (i = 0; i < natts; ++i)
612
	{
613
		if (slot->tts_isnull[i])
614
			j |= k;				/* set bit if not null */
615
		k >>= 1;
616
		if (k == 0)				/* end of byte? */
617
		{
618
			pq_sendint(&buf, j, 1);
619 620 621
			j = 0;
			k = 1 << 7;
		}
622
	}
623
	if (k != (1 << 7))			/* flush last partial byte */
624
		pq_sendint(&buf, j, 1);
625

626 627
	/*
	 * send the attributes of this tuple
628
	 */
629
	for (i = 0; i < natts; ++i)
630
	{
631
		PrinttupAttrInfo *thisState = myState->myinfo + i;
632
		Datum		origattr = slot->tts_values[i],
633
					attr;
634
		bytea	   *outputbytes;
635

636
		if (slot->tts_isnull[i])
637
			continue;
638

639
		Assert(thisState->format == 1);
640

641
		/*
B
Bruce Momjian 已提交
642 643
		 * If we have a toasted datum, forcibly detoast it here to avoid
		 * memory leakage inside the type's output routine.
644 645 646
		 */
		if (thisState->typisvarlena)
			attr = PointerGetDatum(PG_DETOAST_DATUM(origattr));
647 648
		else
			attr = origattr;
649 650 651

		outputbytes = DatumGetByteaP(FunctionCall2(&thisState->finfo,
												   attr,
B
Bruce Momjian 已提交
652
							   ObjectIdGetDatum(thisState->typioparam)));
653 654 655 656 657 658 659 660 661
		/* We assume the result will not have been toasted */
		pq_sendint(&buf, VARSIZE(outputbytes) - VARHDRSZ, 4);
		pq_sendbytes(&buf, VARDATA(outputbytes),
					 VARSIZE(outputbytes) - VARHDRSZ);
		pfree(outputbytes);

		/* Clean up detoasted copy, if any */
		if (attr != origattr)
			pfree(DatumGetPointer(attr));
662
	}
663 664

	pq_endmessage(&buf);
665
}