summaryrefslogtreecommitdiff
path: root/src/backend/utils/cache/lsyscache.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2003-04-08 23:20:04 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2003-04-08 23:20:04 +0000
commit730840c9b649a48604083270d48792915ca89233 (patch)
treecf3ccc25e61cdfc07061ebec63393d77b3a2f643 /src/backend/utils/cache/lsyscache.c
parent6fb5115850be766c42177cebf672c68c7d8e3ddd (diff)
First phase of work on array improvements. ARRAY[x,y,z] constructor
expressions, ARRAY(sub-SELECT) expressions, some array functions. Polymorphic functions using ANYARRAY/ANYELEMENT argument and return types. Some regression tests in place, documentation is lacking. Joe Conway, with some kibitzing from Tom Lane.
Diffstat (limited to 'src/backend/utils/cache/lsyscache.c')
-rw-r--r--src/backend/utils/cache/lsyscache.c83
1 files changed, 82 insertions, 1 deletions
diff --git a/src/backend/utils/cache/lsyscache.c b/src/backend/utils/cache/lsyscache.c
index 277793905e0..26d06c440fe 100644
--- a/src/backend/utils/cache/lsyscache.c
+++ b/src/backend/utils/cache/lsyscache.c
@@ -7,7 +7,7 @@
* Portions Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/utils/cache/lsyscache.c,v 1.91 2003/03/23 05:14:36 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/utils/cache/lsyscache.c,v 1.92 2003/04/08 23:20:02 tgl Exp $
*
* NOTES
* Eventually, the index information should go through here, too.
@@ -1266,6 +1266,87 @@ get_typ_typrelid(Oid typid)
}
/*
+ * get_element_type
+ *
+ * Given the type OID, get the typelem (InvalidOid if not an array type).
+ *
+ * NB: this only considers varlena arrays to be true arrays; InvalidOid is
+ * returned if the input is a fixed-length array type.
+ */
+Oid
+get_element_type(Oid typid)
+{
+ HeapTuple tp;
+
+ tp = SearchSysCache(TYPEOID,
+ ObjectIdGetDatum(typid),
+ 0, 0, 0);
+ if (HeapTupleIsValid(tp))
+ {
+ Form_pg_type typtup = (Form_pg_type) GETSTRUCT(tp);
+ Oid result;
+
+ if (typtup->typlen == -1)
+ result = typtup->typelem;
+ else
+ result = InvalidOid;
+ ReleaseSysCache(tp);
+ return result;
+ }
+ else
+ return InvalidOid;
+}
+
+/*
+ * get_array_type
+ *
+ * Given the type OID, get the corresponding array type.
+ * Returns InvalidOid if no array type can be found.
+ *
+ * NB: this only considers varlena arrays to be true arrays.
+ */
+Oid
+get_array_type(Oid typid)
+{
+ HeapTuple tp;
+
+ tp = SearchSysCache(TYPEOID,
+ ObjectIdGetDatum(typid),
+ 0, 0, 0);
+ if (HeapTupleIsValid(tp))
+ {
+ Form_pg_type typtup = (Form_pg_type) GETSTRUCT(tp);
+ char *array_typename;
+ Oid namespaceId;
+
+ array_typename = makeArrayTypeName(NameStr(typtup->typname));
+ namespaceId = typtup->typnamespace;
+ ReleaseSysCache(tp);
+
+ tp = SearchSysCache(TYPENAMENSP,
+ PointerGetDatum(array_typename),
+ ObjectIdGetDatum(namespaceId),
+ 0, 0);
+
+ pfree(array_typename);
+
+ if (HeapTupleIsValid(tp))
+ {
+ Oid result;
+
+ typtup = (Form_pg_type) GETSTRUCT(tp);
+ if (typtup->typlen == -1 && typtup->typelem == typid)
+ result = HeapTupleGetOid(tp);
+ else
+ result = InvalidOid;
+ ReleaseSysCache(tp);
+ return result;
+ }
+ }
+ return InvalidOid;
+}
+
+/*
* getTypeInputInfo
*
* Get info needed for converting values of a type to internal form