1996-08-27 23:50:29 +02:00
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
*
|
1999-02-14 00:22:53 +01:00
|
|
|
* tupdesc.h
|
1997-09-07 07:04:48 +02:00
|
|
|
* POSTGRES tuple descriptor definitions.
|
1996-08-27 23:50:29 +02:00
|
|
|
*
|
|
|
|
*
|
2006-03-05 16:59:11 +01:00
|
|
|
* Portions Copyright (c) 1996-2006, PostgreSQL Global Development Group
|
2000-01-26 06:58:53 +01:00
|
|
|
* Portions Copyright (c) 1994, Regents of the University of California
|
1996-08-27 23:50:29 +02:00
|
|
|
*
|
2006-06-16 20:42:24 +02:00
|
|
|
* $PostgreSQL: pgsql/src/include/access/tupdesc.h,v 1.50 2006/06/16 18:42:23 tgl Exp $
|
1996-08-27 23:50:29 +02:00
|
|
|
*
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
1997-09-07 07:04:48 +02:00
|
|
|
#ifndef TUPDESC_H
|
1996-08-27 23:50:29 +02:00
|
|
|
#define TUPDESC_H
|
|
|
|
|
1999-07-16 01:04:24 +02:00
|
|
|
#include "access/attnum.h"
|
|
|
|
#include "catalog/pg_attribute.h"
|
1999-07-16 19:07:40 +02:00
|
|
|
#include "nodes/pg_list.h"
|
1996-08-27 23:50:29 +02:00
|
|
|
|
1997-08-19 06:46:15 +02:00
|
|
|
|
1997-09-07 07:04:48 +02:00
|
|
|
typedef struct attrDefault
|
|
|
|
{
|
1997-09-08 04:41:22 +02:00
|
|
|
AttrNumber adnum;
|
1999-10-04 01:55:40 +02:00
|
|
|
char *adbin; /* nodeToString representation of expr */
|
1997-09-08 22:59:27 +02:00
|
|
|
} AttrDefault;
|
1997-08-21 06:10:25 +02:00
|
|
|
|
1997-09-07 07:04:48 +02:00
|
|
|
typedef struct constrCheck
|
|
|
|
{
|
1997-09-08 04:41:22 +02:00
|
|
|
char *ccname;
|
1999-10-04 01:55:40 +02:00
|
|
|
char *ccbin; /* nodeToString representation of expr */
|
1997-09-08 23:56:23 +02:00
|
|
|
} ConstrCheck;
|
1997-08-21 06:10:25 +02:00
|
|
|
|
|
|
|
/* This structure contains constraints of a tuple */
|
1997-09-07 07:04:48 +02:00
|
|
|
typedef struct tupleConstr
|
|
|
|
{
|
1999-10-04 01:55:40 +02:00
|
|
|
AttrDefault *defval; /* array */
|
|
|
|
ConstrCheck *check; /* array */
|
1997-09-08 04:41:22 +02:00
|
|
|
uint16 num_defval;
|
|
|
|
uint16 num_check;
|
|
|
|
bool has_not_null;
|
1997-09-08 23:56:23 +02:00
|
|
|
} TupleConstr;
|
1997-08-21 06:10:25 +02:00
|
|
|
|
|
|
|
/*
|
2005-03-07 05:42:17 +01:00
|
|
|
* This struct is passed around within the backend to describe the structure
|
|
|
|
* of tuples. For tuples coming from on-disk relations, the information is
|
|
|
|
* collected from the pg_attribute, pg_attrdef, and pg_constraint catalogs.
|
|
|
|
* Transient row types (such as the result of a join query) have anonymous
|
|
|
|
* TupleDesc structs that generally omit any constraint info; therefore the
|
|
|
|
* structure is designed to let the constraints be omitted efficiently.
|
2004-04-01 23:28:47 +02:00
|
|
|
*
|
|
|
|
* Note that only user attributes, not system attributes, are mentioned in
|
|
|
|
* TupleDesc; with the exception that tdhasoid indicates if OID is present.
|
|
|
|
*
|
2005-03-07 05:42:17 +01:00
|
|
|
* If the tupdesc is known to correspond to a named rowtype (such as a table's
|
2004-08-29 07:07:03 +02:00
|
|
|
* rowtype) then tdtypeid identifies that type and tdtypmod is -1. Otherwise
|
2004-04-01 23:28:47 +02:00
|
|
|
* tdtypeid is RECORDOID, and tdtypmod can be either -1 for a fully anonymous
|
|
|
|
* row type, or a value >= 0 to allow the rowtype to be looked up in the
|
|
|
|
* typcache.c type cache.
|
2006-06-16 20:42:24 +02:00
|
|
|
*
|
|
|
|
* Tuple descriptors that live in caches (relcache or typcache, at present)
|
|
|
|
* are reference-counted: they can be deleted when their reference count goes
|
|
|
|
* to zero. Tuple descriptors created by the executor need no reference
|
|
|
|
* counting, however: they are simply created in the appropriate memory
|
|
|
|
* context and go away when the context is freed. We set the tdrefcount
|
|
|
|
* field of such a descriptor to -1, while reference-counted descriptors
|
|
|
|
* always have tdrefcount >= 0.
|
1997-08-21 06:10:25 +02:00
|
|
|
*/
|
1997-09-07 07:04:48 +02:00
|
|
|
typedef struct tupleDesc
|
|
|
|
{
|
2005-03-07 05:42:17 +01:00
|
|
|
int natts; /* number of attributes in the tuple */
|
1998-09-01 05:29:17 +02:00
|
|
|
Form_pg_attribute *attrs;
|
2005-03-07 05:42:17 +01:00
|
|
|
/* attrs[N] is a pointer to the description of Attribute Number N+1 */
|
|
|
|
TupleConstr *constr; /* constraints, or NULL if none */
|
2004-04-01 23:28:47 +02:00
|
|
|
Oid tdtypeid; /* composite type ID for tuple type */
|
|
|
|
int32 tdtypmod; /* typmod for tuple type */
|
2005-03-07 05:42:17 +01:00
|
|
|
bool tdhasoid; /* tuple has oid attribute in its header */
|
2006-06-16 20:42:24 +02:00
|
|
|
int tdrefcount; /* reference count, or -1 if not counting */
|
2001-11-05 18:46:40 +01:00
|
|
|
} *TupleDesc;
|
1996-08-27 23:50:29 +02:00
|
|
|
|
2002-07-20 07:16:59 +02:00
|
|
|
|
2002-09-02 03:05:06 +02:00
|
|
|
extern TupleDesc CreateTemplateTupleDesc(int natts, bool hasoid);
|
2002-07-20 07:16:59 +02:00
|
|
|
|
2002-09-02 03:05:06 +02:00
|
|
|
extern TupleDesc CreateTupleDesc(int natts, bool hasoid,
|
2002-09-04 22:31:48 +02:00
|
|
|
Form_pg_attribute *attrs);
|
1996-08-27 23:50:29 +02:00
|
|
|
|
|
|
|
extern TupleDesc CreateTupleDescCopy(TupleDesc tupdesc);
|
|
|
|
|
1997-08-22 05:55:39 +02:00
|
|
|
extern TupleDesc CreateTupleDescCopyConstr(TupleDesc tupdesc);
|
|
|
|
|
1997-09-08 04:41:22 +02:00
|
|
|
extern void FreeTupleDesc(TupleDesc tupdesc);
|
1997-08-22 05:55:39 +02:00
|
|
|
|
2006-06-16 20:42:24 +02:00
|
|
|
extern void IncrTupleDescRefCount(TupleDesc tupdesc);
|
|
|
|
extern void DecrTupleDescRefCount(TupleDesc tupdesc);
|
|
|
|
|
|
|
|
#define PinTupleDesc(tupdesc) \
|
|
|
|
do { \
|
|
|
|
if ((tupdesc)->tdrefcount >= 0) \
|
|
|
|
IncrTupleDescRefCount(tupdesc); \
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
#define ReleaseTupleDesc(tupdesc) \
|
|
|
|
do { \
|
|
|
|
if ((tupdesc)->tdrefcount >= 0) \
|
|
|
|
DecrTupleDescRefCount(tupdesc); \
|
|
|
|
} while (0)
|
|
|
|
|
2000-01-31 05:35:57 +01:00
|
|
|
extern bool equalTupleDescs(TupleDesc tupdesc1, TupleDesc tupdesc2);
|
|
|
|
|
2002-03-29 20:06:29 +01:00
|
|
|
extern void TupleDescInitEntry(TupleDesc desc,
|
1997-09-07 07:04:48 +02:00
|
|
|
AttrNumber attributeNumber,
|
2003-08-12 01:04:50 +02:00
|
|
|
const char *attributeName,
|
2000-05-22 04:34:23 +02:00
|
|
|
Oid oidtypeid,
|
1998-07-12 23:29:40 +02:00
|
|
|
int32 typmod,
|
2004-04-01 23:28:47 +02:00
|
|
|
int attdim);
|
1996-08-27 23:50:29 +02:00
|
|
|
|
2002-03-29 20:06:29 +01:00
|
|
|
extern TupleDesc BuildDescForRelation(List *schema);
|
2001-10-28 07:26:15 +01:00
|
|
|
|
2006-03-16 01:31:55 +01:00
|
|
|
extern TupleDesc BuildDescFromLists(List *names, List *types, List *typmods);
|
|
|
|
|
2001-11-05 18:46:40 +01:00
|
|
|
#endif /* TUPDESC_H */
|