1
0
mirror of https://github.com/postgres/postgres.git synced 2025-10-15 05:46:52 +03:00

Add transforms feature

This provides a mechanism for specifying conversions between SQL data
types and procedural languages.  As examples, there are transforms
for hstore and ltree for PL/Perl and PL/Python.

reviews by Pavel Stěhule and Andres Freund
This commit is contained in:
Peter Eisentraut
2015-04-26 10:33:14 -04:00
parent f320cbb615
commit cac7658205
101 changed files with 6034 additions and 2811 deletions

View File

@@ -24,12 +24,14 @@
#include "catalog/pg_amproc.h"
#include "catalog/pg_collation.h"
#include "catalog/pg_constraint.h"
#include "catalog/pg_language.h"
#include "catalog/pg_namespace.h"
#include "catalog/pg_opclass.h"
#include "catalog/pg_operator.h"
#include "catalog/pg_proc.h"
#include "catalog/pg_range.h"
#include "catalog/pg_statistic.h"
#include "catalog/pg_transform.h"
#include "catalog/pg_type.h"
#include "miscadmin.h"
#include "nodes/makefuncs.h"
@@ -977,6 +979,30 @@ get_constraint_name(Oid conoid)
return NULL;
}
/* ---------- LANGUAGE CACHE ---------- */
char *
get_language_name(Oid langoid, bool missing_ok)
{
HeapTuple tp;
tp = SearchSysCache1(LANGOID, ObjectIdGetDatum(langoid));
if (HeapTupleIsValid(tp))
{
Form_pg_language lantup = (Form_pg_language) GETSTRUCT(tp);
char *result;
result = pstrdup(NameStr(lantup->lanname));
ReleaseSysCache(tp);
return result;
}
if (!missing_ok)
elog(ERROR, "cache lookup failed for language %u",
langoid);
return NULL;
}
/* ---------- OPCLASS CACHE ---------- */
/*
@@ -1743,6 +1769,51 @@ get_rel_tablespace(Oid relid)
}
/* ---------- TRANSFORM CACHE ---------- */
Oid
get_transform_fromsql(Oid typid, Oid langid, List *trftypes)
{
HeapTuple tup;
if (!list_member_oid(trftypes, typid))
return InvalidOid;
tup = SearchSysCache2(TRFTYPELANG, typid, langid);
if (HeapTupleIsValid(tup))
{
Oid funcid;
funcid = ((Form_pg_transform) GETSTRUCT(tup))->trffromsql;
ReleaseSysCache(tup);
return funcid;
}
else
return InvalidOid;
}
Oid
get_transform_tosql(Oid typid, Oid langid, List *trftypes)
{
HeapTuple tup;
if (!list_member_oid(trftypes, typid))
return InvalidOid;
tup = SearchSysCache2(TRFTYPELANG, typid, langid);
if (HeapTupleIsValid(tup))
{
Oid funcid;
funcid = ((Form_pg_transform) GETSTRUCT(tup))->trftosql;
ReleaseSysCache(tup);
return funcid;
}
else
return InvalidOid;
}
/* ---------- TYPE CACHE ---------- */
/*

View File

@@ -56,6 +56,7 @@
#include "catalog/pg_shseclabel.h"
#include "catalog/pg_statistic.h"
#include "catalog/pg_tablespace.h"
#include "catalog/pg_transform.h"
#include "catalog/pg_ts_config.h"
#include "catalog/pg_ts_config_map.h"
#include "catalog/pg_ts_dict.h"
@@ -653,6 +654,28 @@ static const struct cachedesc cacheinfo[] = {
},
4
},
{TransformRelationId, /* TRFOID */
TransformOidIndexId,
1,
{
ObjectIdAttributeNumber,
0,
0,
0,
},
16
},
{TransformRelationId, /* TRFTYPELANG */
TransformTypeLangIndexId,
2,
{
Anum_pg_transform_trftype,
Anum_pg_transform_trflang,
0,
0,
},
16
},
{TSConfigMapRelationId, /* TSCONFIGMAP */
TSConfigMapIndexId,
3,