3
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
4
<title>1.37.� determineidxnameunique( text, name )
6
<link rel="stylesheet" href="stylesheet.css" type="text/css">
7
<link rev="made" href="pgsql-docs@postgresql.org">
8
<meta name="generator" content="DocBook XSL Stylesheets V1.70.1">
9
<link rel="start" href="index.html" title="Slony-I HEAD_20060719 Documentation">
10
<link rel="up" href="schema.html" title="Chapter�1.�Schema schemadoc">
11
<link rel="prev" href="function.determineidxnameserial-text.html" title="1.36.� determineidxnameserial( text )
13
<link rel="next" href="function.disablenode-integer.html" title="1.38.� disablenode( integer )
15
<link rel="copyright" href="ln-legalnotice.html" title="Legal Notice">
17
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="section" lang="en">
18
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
19
<a name="function.determineidxnameunique-text-name"></a>1.37.� determineidxnameunique( text, name )
20
</h2></div></div></div>
22
<div class="segmentedlist">
23
<div class="title"><strong><span class="title">Function Properties</span></strong></div>
24
<div class="seglistitem">
26
<strong><span class="segtitle">Language: </span></strong>PLPGSQL</div>
28
<strong><span class="segtitle">Return Type: </span></strong>name</div>
33
FUNCTION determineIdxnameUnique (tab_fqname, indexname)
35
Given a tablename, tab_fqname, check that the unique index, indexname,
36
exists or return the primary key index name for the table. If there
37
is no unique index, it raises an exception.
39
<pre class="programlisting">declare
40
p_tab_fqname alias for $1;
41
v_tab_fqname_quoted text default '';
42
p_idx_name alias for $2;
45
v_tab_fqname_quoted := slon_quote_input(p_tab_fqname);
47
-- Ensure that the table exists
49
if (select PGC.relname
50
from "pg_catalog".pg_class PGC,
51
"pg_catalog".pg_namespace PGN
52
where slon_quote_brute(PGN.nspname) || '.' ||
53
slon_quote_brute(PGC.relname) = v_tab_fqname_quoted
54
and PGN.oid = PGC.relnamespace) is null then
55
raise exception 'Slony-I: table % not found', v_tab_fqname_quoted;
59
-- Lookup the tables primary key or the specified unique index
61
if p_idx_name isnull then
64
from "pg_catalog".pg_class PGC,
65
"pg_catalog".pg_namespace PGN,
66
"pg_catalog".pg_index PGX,
67
"pg_catalog".pg_class PGXC
68
where slon_quote_brute(PGN.nspname) || '.' ||
69
slon_quote_brute(PGC.relname) = v_tab_fqname_quoted
70
and PGN.oid = PGC.relnamespace
71
and PGX.indrelid = PGC.oid
72
and PGX.indexrelid = PGXC.oid
75
raise exception 'Slony-I: table % has no primary key',
81
from "pg_catalog".pg_class PGC,
82
"pg_catalog".pg_namespace PGN,
83
"pg_catalog".pg_index PGX,
84
"pg_catalog".pg_class PGXC
85
where slon_quote_brute(PGN.nspname) || '.' ||
86
slon_quote_brute(PGC.relname) = v_tab_fqname_quoted
87
and PGN.oid = PGC.relnamespace
88
and PGX.indrelid = PGC.oid
89
and PGX.indexrelid = PGXC.oid
91
and slon_quote_brute(PGXC.relname) = slon_quote_input(p_idx_name);
93
raise exception 'Slony-I: table % has no unique index %',
94
v_tab_fqname_quoted, p_idx_name;
99
-- Return the found index name
101
return v_idxrow.relname;