CAST(c.conname AS sql_identifier) AS constraint_name,
CAST(current_database() AS sql_identifier) AS specific_catalog,
CAST(np.nspname AS sql_identifier) AS specific_schema,
- CAST(p.proname || '_' || CAST(p.oid AS text) AS sql_identifier) AS specific_name
+ CAST(nameconcatoid(p.proname, p.oid) AS sql_identifier) AS specific_name
FROM pg_namespace nc, pg_constraint c, pg_depend d, pg_proc p, pg_namespace np
WHERE nc.oid = c.connamespace
AND c.contype = 'c'
CREATE VIEW parameters AS
SELECT CAST(current_database() AS sql_identifier) AS specific_catalog,
CAST(n_nspname AS sql_identifier) AS specific_schema,
- CAST(proname || '_' || CAST(p_oid AS text) AS sql_identifier) AS specific_name,
+ CAST(nameconcatoid(proname, p_oid) AS sql_identifier) AS specific_name,
CAST((ss.x).n AS cardinal_number) AS ordinal_position,
CAST(
CASE WHEN proargmodes IS NULL THEN 'IN'
CAST(grantee.rolname AS sql_identifier) AS grantee,
CAST(current_database() AS sql_identifier) AS specific_catalog,
CAST(n.nspname AS sql_identifier) AS specific_schema,
- CAST(p.proname || '_' || CAST(p.oid AS text) AS sql_identifier) AS specific_name,
+ CAST(nameconcatoid(p.proname, p.oid) AS sql_identifier) AS specific_name,
CAST(current_database() AS sql_identifier) AS routine_catalog,
CAST(n.nspname AS sql_identifier) AS routine_schema,
CAST(p.proname AS sql_identifier) AS routine_name,
CREATE VIEW routines AS
SELECT CAST(current_database() AS sql_identifier) AS specific_catalog,
CAST(n.nspname AS sql_identifier) AS specific_schema,
- CAST(p.proname || '_' || CAST(p.oid AS text) AS sql_identifier) AS specific_name,
+ CAST(nameconcatoid(p.proname, p.oid) AS sql_identifier) AS specific_name,
CAST(current_database() AS sql_identifier) AS routine_catalog,
CAST(n.nspname AS sql_identifier) AS routine_schema,
CAST(p.proname AS sql_identifier) AS routine_name,
CAST(t.typname AS sql_identifier) AS udt_name,
CAST(current_database() AS sql_identifier) AS specific_catalog,
CAST(np.nspname AS sql_identifier) AS specific_schema,
- CAST(p.proname || '_' || CAST(p.oid AS text) AS sql_identifier) AS specific_name,
+ CAST(nameconcatoid(p.proname, p.oid) AS sql_identifier) AS specific_name,
CAST(l.lanname AS sql_identifier) AS group_name,
CAST('FROM SQL' AS character_data) AS transform_type
FROM pg_type t JOIN pg_transform x ON t.oid = x.trftype
CAST(t.typname AS sql_identifier) AS udt_name,
CAST(current_database() AS sql_identifier) AS specific_catalog,
CAST(np.nspname AS sql_identifier) AS specific_schema,
- CAST(p.proname || '_' || CAST(p.oid AS text) AS sql_identifier) AS specific_name,
+ CAST(nameconcatoid(p.proname, p.oid) AS sql_identifier) AS specific_name,
CAST(l.lanname AS sql_identifier) AS group_name,
CAST('TO SQL' AS character_data) AS transform_type
FROM pg_type t JOIN pg_transform x ON t.oid = x.trftype
CAST(v.relname AS sql_identifier) AS table_name,
CAST(current_database() AS sql_identifier) AS specific_catalog,
CAST(np.nspname AS sql_identifier) AS specific_schema,
- CAST(p.proname || '_' || CAST(p.oid AS text) AS sql_identifier) AS specific_name
+ CAST(nameconcatoid(p.proname, p.oid) AS sql_identifier) AS specific_name
FROM pg_namespace nv, pg_class v, pg_depend dv,
pg_depend dp, pg_proc p, pg_namespace np
UNION ALL
/* parameters */
- SELECT pronamespace, CAST(proname || '_' || CAST(oid AS text) AS sql_identifier),
+ SELECT pronamespace,
+ CAST(nameconcatoid(proname, oid) AS sql_identifier),
'ROUTINE'::text, (ss.x).n, (ss.x).x, 0
FROM (SELECT p.pronamespace, p.proname, p.oid,
_pg_expandarray(coalesce(p.proallargtypes, p.proargtypes::oid[])) AS x
UNION ALL
/* result types */
- SELECT p.pronamespace, CAST(p.proname || '_' || CAST(p.oid AS text) AS sql_identifier),
+ SELECT p.pronamespace,
+ CAST(nameconcatoid(p.proname, p.oid) AS sql_identifier),
'ROUTINE'::text, 0, p.prorettype, 0
FROM pg_proc p
PG_RETURN_POINTER(array);
}
+
+/*
+ * SQL-function nameconcatoid(name, oid) returns name
+ *
+ * This is used in the information_schema to produce specific_name columns,
+ * which are supposed to be unique per schema. We achieve that (in an ugly
+ * way) by appending the object's OID. The result is the same as
+ * ($1::text || '_' || $2::text)::name
+ * except that, if it would not fit in NAMEDATALEN, we make it do so by
+ * truncating the name input (not the oid).
+ */
+Datum
+nameconcatoid(PG_FUNCTION_ARGS)
+{
+ Name nam = PG_GETARG_NAME(0);
+ Oid oid = PG_GETARG_OID(1);
+ Name result;
+ char suffix[20];
+ int suflen;
+ int namlen;
+
+ suflen = snprintf(suffix, sizeof(suffix), "_%u", oid);
+ namlen = strlen(NameStr(*nam));
+
+ /* Truncate oversize input by truncating name part, not suffix */
+ if (namlen + suflen >= NAMEDATALEN)
+ namlen = pg_mbcliplen(NameStr(*nam), namlen, NAMEDATALEN - 1 - suflen);
+
+ /* We use palloc0 here to ensure result is zero-padded */
+ result = (Name) palloc0(NAMEDATALEN);
+ memcpy(NameStr(*result), NameStr(*nam), namlen);
+ memcpy(NameStr(*result) + namlen, suffix, suflen);
+
+ PG_RETURN_NAME(result);
+}