提交 5d6672e2 编写于 作者: M mkiyama 提交者: David Yozie

GPDB DOCS - DO command - anonymous blocks (#1977)

* GPDB DOCS - DO command - anonymous blocks

* GPDB DOCS - updates to support DO command.

* mention anonymous blocks in Admin Guide

* GPDB DOCS updates for DO command review

* GPDB DOCS fix typos in DO command

* GPDB DOCs Added cursor limitatation toPL/Python topic.

* GPDB DOCS - update CREATE LANGUAGE and pg_language for DO and 8.3 merge.
上级 02871bd6
......@@ -129,6 +129,7 @@
<topicref href="ref_guide/sql_commands/DEALLOCATE.xml"/>
<topicref href="ref_guide/sql_commands/DECLARE.xml"/>
<topicref href="ref_guide/sql_commands/DELETE.xml"/>
<topicref href="ref_guide/sql_commands/DO.xml"/>
<topicref href="ref_guide/sql_commands/DROP_AGGREGATE.xml"/>
<topicref href="ref_guide/sql_commands/DROP_CAST.xml"/>
<topicref href="ref_guide/sql_commands/DROP_CONVERSION.xml"/>
......@@ -236,7 +237,7 @@
<topicref href="ref_guide/system_catalogs/pg_database.xml"/>
<topicref href="ref_guide/system_catalogs/pg_depend.xml"/>
<topicref href="ref_guide/system_catalogs/pg_description.xml"/>
<topicref href="ref_guide/system_catalogs/pg_enum.xml"/>
<topicref href="ref_guide/system_catalogs/pg_enum.xml"/>
<topicref href="ref_guide/system_catalogs/pg_exttable.xml"/>
<topicref href="ref_guide/system_catalogs/pg_filespace.xml"/>
<topicref href="ref_guide/system_catalogs/pg_filespace_entry.xml"/>
......
......@@ -118,6 +118,11 @@ SELECT foo();
<p>In Greenplum Database, the shared library files for user-created functions must
reside in the same library path location on every host in the Greenplum Database
array (masters, segments, and mirrors).</p>
<p>You can also create and execute anonymous code blocks that are written in a Greenplum
Database procedural language such as PL/pgSQL. The anonymous blocks run as transient
anonymous functions. For information about creating and executing anonymous blocks,
see the <xref href="../../../ref_guide/sql_commands/DO.xml#topic1"
><codeph>DO</codeph></xref> command.</p>
</body>
</topic>
<topic id="topic29" xml:lang="en">
......
......@@ -403,6 +403,12 @@
<codeblock conref="sql_commands/DROP_AGGREGATE.xml#topic1/sql_command_synopsis"/>
<p otherprops="op-html">See <xref href="sql_commands/DROP_AGGREGATE.xml"/> for more
information.</p>
<section>
<title>DO</title>
</section>
<p conref="sql_commands/DO.xml#topic1/sql_command_desc"/>
<codeblock conref="sql_commands/DO.xml#topic1/sql_command_synopsis"/>
<p otherprops="op-html">See <xref href="sql_commands/DO.xml"/> for more information.</p>
<section id="ae1904821">
<title>DROP CAST</title>
</section>
......
......@@ -32,6 +32,9 @@
<p>PL/Python is a loadable procedural language. With the Greenplum Database PL/Python
extension, you can write a Greenplum Database user-defined functions in Python that take
advantage of Python features and modules to quickly build robust database applications. </p>
<p>You can run PL/Python code blocks as anonymous code blocks. See the <codeph><xref
href="../sql_commands/DO.xml#topic1">DO</xref></codeph> command in the <cite>Greenplum
Database Reference Guide</cite>.</p>
<p>The Greenplum Database PL/Python extension is installed by default with Greenplum Database.
Greenplum Database installs a version of Python and PL/Python. This is location of the
Python installation that Greenplum Database uses:</p>
......@@ -43,6 +46,8 @@
<ul id="ul_qhg_33m_zt">
<li>Greenplum Database does not support PL/Python triggers.</li>
<li>PL/Python is available only as a Greenplum Database untrusted language.</li>
<li>Updatable cursors (<codeph>UPDATE...WHERE CURRENT OF</codeph> and
<codeph>DELETE...WHERE CURRENT OF</codeph>) are not supported.</li>
</ul>
</body>
</topic>
......@@ -59,9 +64,10 @@
<body>
<p>For each database that requires its use, register the PL/Python language with the SQL
command <codeph>CREATE LANGUAGE</codeph> or the Greenplum Database utility
<codeph>createlang</codeph>. Because PL/Python is an untrusted language, only superusers can register PL/Python with a
database. For example, running this command as the <codeph>gpadmin</codeph> system user
registers PL/Python with the database named <codeph>testdb</codeph>:</p>
<codeph>createlang</codeph>. Because PL/Python is an untrusted language, only superusers
can register PL/Python with a database. For example, running this command as the
<codeph>gpadmin</codeph> system user registers PL/Python with the database named
<codeph>testdb</codeph>:</p>
<codeblock>$ createlang plpythonu -d testdb</codeblock>
<p>PL/Python is registered as an untrusted language.</p>
</body>
......@@ -71,10 +77,10 @@
<body>
<p>For a database that no longer requires the PL/Python language, remove support for
PL/Python with the SQL command <codeph>DROP LANGUAGE</codeph> or the Greenplum Database
<codeph>droplang</codeph> utility. Because PL/Python is an untrusted language, only superusers can remove support for the PL/Python
language from a database. For example, running this command as the
<codeph>gpadmin</codeph> system user removes support for PL/Python from the database
named <codeph>testdb</codeph>:</p>
<codeph>droplang</codeph> utility. Because PL/Python is an untrusted language, only
superusers can remove support for the PL/Python language from a database. For example,
running this command as the <codeph>gpadmin</codeph> system user removes support for
PL/Python from the database named <codeph>testdb</codeph>:</p>
<codeblock>$ droplang plpythonu -d testdb</codeblock>
<p>When you remove support for PL/Python, the PL/Python user-defined functions that you
created in the database will no longer work. </p>
......@@ -567,6 +573,18 @@ $$ language plpythonu;</codeblock>
<codeblock>SELECT mypytest(2) ;</codeblock>
<p>This command deletes the UDF from the database.</p>
<codeblock>DROP FUNCTION mypytest(integer) ;</codeblock>
<p>This example executes the PL/Python function in the previous example as an anonymous block
with the <codeph>DO</codeph> command. In the example, the anonymous block retrieves the
input value from a temporary table.</p>
<codeblock>CREATE TEMP TABLE mytemp AS VALUES (2) DISTRIBUTED RANDOMLY;
DO $$
temprow = plpy.execute("SELECT * FROM mytemp", 1)
myval = temprow[0]["column1"]
rv = plpy.execute("SELECT * FROM sales ORDER BY id", 5)
region = rv[myval]["region"]
plpy.notice("region is %s" % region)
$$ language plpythonu;</codeblock>
</body>
</topic>
<topic id="topic12" xml:lang="en">
......
......@@ -38,6 +38,9 @@
the creating functions and function attributes, see the <codeph><xref
href="../sql_commands/CREATE_FUNCTION.xml#topic1"/></codeph> command in the
<cite>Greenplum Database Reference Guide</cite>.</p>
<p>You can run PL/SQL code blocks as anonymous code blocks. See the <codeph><xref
href="../sql_commands/DO.xml#topic1"/></codeph> command in the <cite>Greenplum Database
Reference Guide</cite>.</p>
</body>
<topic id="topic3" xml:lang="en">
<title>Greenplum Database SQL Limitations</title>
......@@ -142,10 +145,10 @@ $$ LANGUAGE plpgsql;</codeblock>
<topic id="topic7" xml:lang="en">
<title>Example: Aliases for Function Parameters</title>
<body>
<p>Parameters passed to functions are named with the identifiers such asa
<codeph>$1</codeph>, <codeph>$2</codeph>. Optionally, aliases can be declared for
<codeph>$n</codeph> parameter names for increased readability. Either the alias or the
numeric identifier can then be used to refer to the parameter value.</p>
<p>Parameters passed to functions are named with identifiers such as <codeph>$1</codeph>,
<codeph>$2</codeph>. Optionally, aliases can be declared for <codeph>$n</codeph>
parameter names for increased readability. Either the alias or the numeric identifier can
then be used to refer to the parameter value.</p>
<p>There are two ways to create an alias. The preferred way is to give a name to the
parameter in the <codeph>CREATE FUNCTION</codeph> command, for example:</p>
<codeblock>CREATE FUNCTION sales_tax(subtotal real) RETURNS real AS $$
......@@ -234,6 +237,25 @@ $$ LANGUAGE plpgsql VOLATILE;</codeblock>
inside a PL/pgSQL function, use the SQL command <codeph>CREATE TABLE AS</codeph>.</note>
</body>
</topic>
<topic id="topic_isw_3sx_cz">
<title>Example: Anonymous Block</title>
<body>
<p>This example executes the function in the previous example as an anonymous block with the
<codeph>DO</codeph> command. In the example, the anonymous block retrieves the input
value from a temporary
table.<codeblock>CREATE TEMP TABLE list AS VALUES ('test1') DISTRIBUTED RANDOMLY;
DO $$
DECLARE
    t1_row table1%ROWTYPE;
calc_int table1.f3%TYPE;
BEGIN
    SELECT * INTO t1_row FROM table1, list WHERE table1.f1 = list.column1 ;
calc_int = (t1_row.f2 * t1_row.f3)::integer ;
    RAISE NOTICE 'calculated value is %', calc_int ;
END $$ LANGUAGE plpgsql ;</codeblock></p>
</body>
</topic>
</topic>
<topic id="topic10" xml:lang="en">
<title id="pt214450">References</title>
......
......@@ -205,14 +205,14 @@ NEXT 10 ROWS ONLY; </codeblock><p>Greenplum
<topic id="topic8" xml:lang="en">
<title id="ik264019">Greenplum and PostgreSQL Compatibility</title>
<body>
<p>Greenplum Database is based on PostgreSQL 8.2 with a few features added in from the 8.3
release. To support the distributed nature and typical workload of a Greenplum Database
system, some SQL commands have been added or modified, and there are a few PostgreSQL
features that are not supported. Greenplum has also added features not found in PostgreSQL,
such as physical data distribution, parallel query optimization, external tables, resource
queues for workload management and enhanced table partitioning. For full SQL syntax and
references, see the <xref href="sql_commands/sql_ref.xml#topic1" type="topic" format="dita"
/>.</p>
<p>Greenplum Database is based on PostgreSQL 8.3 with additional features from newer
PostgreSQL releases. To support the distributed nature and typical workload of a Greenplum
Database system, some SQL commands have been added or modified, and there are a few
PostgreSQL features that are not supported. Greenplum has also added features not found in
PostgreSQL, such as physical data distribution, parallel query optimization, external
tables, resource queues for workload management and enhanced table partitioning. For full
SQL syntax and references, see the <xref href="sql_commands/sql_ref.xml#topic1" type="topic"
format="dita"/>.</p>
<table id="ik213423">
<title>SQL Support in Greenplum Database</title>
<tgroup cols="3">
......@@ -251,7 +251,7 @@ NEXT 10 ROWS ONLY; </codeblock><p>Greenplum
<entry colname="col1"><codeph>ALTER FILESPACE</codeph></entry>
<entry colname="col2">YES</entry>
<entry colname="col3">Greenplum Database parallel tablespace feature - not in
PostgreSQL 8.2.15.</entry>
PostgreSQL 8.3.</entry>
</row>
<row>
<entry colname="col1"><codeph>ALTER FUNCTION</codeph></entry>
......@@ -284,6 +284,11 @@ NEXT 10 ROWS ONLY; </codeblock><p>Greenplum
<entry colname="col2"><b>NO</b></entry>
<entry colname="col3"/>
</row>
<row>
<entry colname="col1"><codeph>ALTER PROTOCOL</codeph></entry>
<entry colname="col2">YES</entry>
<entry colname="col3"/>
</row>
<row>
<entry colname="col1"><codeph>ALTER RESOURCE QUEUE</codeph></entry>
<entry colname="col2">YES</entry>
......@@ -423,7 +428,7 @@ NEXT 10 ROWS ONLY; </codeblock><p>Greenplum
<entry colname="col1"><codeph>CREATE EXTERNAL TABLE</codeph></entry>
<entry colname="col2">YES</entry>
<entry colname="col3">Greenplum Database parallel ETL feature - not in PostgreSQL
8.2.15.</entry>
8.3.</entry>
</row>
<row>
<entry colname="col1"><codeph>CREATE FUNCTION</codeph></entry>
......@@ -473,11 +478,16 @@ NEXT 10 ROWS ONLY; </codeblock><p>Greenplum
<entry colname="col2"><b>NO</b></entry>
<entry colname="col3"/>
</row>
<row>
<entry colname="col1"><codeph>CREATE PROTOCOL</codeph></entry>
<entry colname="col2">YES</entry>
<entry colname="col3"/>
</row>
<row>
<entry colname="col1"><codeph>CREATE RESOURCE QUEUE</codeph></entry>
<entry colname="col2">YES</entry>
<entry colname="col3">Greenplum Database workload management feature - not in
PostgreSQL 8.2.15.</entry>
PostgreSQL 8.3.</entry>
</row>
<row>
<entry colname="col1"><codeph>CREATE ROLE</codeph></entry>
......@@ -564,8 +574,9 @@ NEXT 10 ROWS ONLY; </codeblock><p>Greenplum
<entry colname="col1"><codeph>DECLARE</codeph></entry>
<entry colname="col2">YES</entry>
<entry colname="col3"><b>Unsupported Clauses /
Options:</b><p><codeph>SCROLL</codeph></p><p><b>Limitations:</b></p><p>Cursors
cannot be backward-scrolled. Forward scrolling is supported. </p><p>PL/pgSQL does
Options:</b><p><codeph>SCROLL</codeph></p><p><codeph>FOR UPDATE [ OF column [,
...] ]</codeph></p><p><b>Limitations:</b></p><p>Cursors cannot be
backward-scrolled. Forward scrolling is supported.</p><p>PL/pgSQL does
not have support for updatable cursors. </p></entry>
</row>
<row>
......@@ -575,6 +586,11 @@ NEXT 10 ROWS ONLY; </codeblock><p>Greenplum
Options:</b><p><codeph>RETURNING</codeph></p><p><b>Limitations:</b></p><p><codeph>WHERE
CURRENT OF</codeph> clause is not supported in PL/pgSQL.</p></entry>
</row>
<row>
<entry colname="col1"><codeph>DO</codeph></entry>
<entry colname="col2">YES</entry>
<entry colname="col3">PostgreSQL 9.0 feature</entry>
</row>
<row>
<entry colname="col1"><codeph>DROP AGGREGATE</codeph></entry>
<entry colname="col2">YES</entry>
......@@ -604,13 +620,13 @@ NEXT 10 ROWS ONLY; </codeblock><p>Greenplum
<entry colname="col1"><codeph>DROP EXTERNAL TABLE</codeph></entry>
<entry colname="col2">YES</entry>
<entry colname="col3">Greenplum Database parallel ETL feature - not in PostgreSQL
8.2.15.</entry>
8.3.</entry>
</row>
<row>
<entry colname="col1"><codeph>DROP FILESPACE</codeph></entry>
<entry colname="col2">YES</entry>
<entry colname="col3">Greenplum Database parallel tablespace feature - not in
PostgreSQL 8.2.15.</entry>
PostgreSQL 8.3.</entry>
</row>
<row>
<entry colname="col1"><codeph>DROP FUNCTION</codeph></entry>
......@@ -648,11 +664,16 @@ NEXT 10 ROWS ONLY; </codeblock><p>Greenplum
<entry colname="col2"><b otherprops="red">NO</b></entry>
<entry colname="col3"/>
</row>
<row>
<entry colname="col1"><codeph>DROP PROTOCOL</codeph></entry>
<entry colname="col2">YES</entry>
<entry colname="col3"/>
</row>
<row>
<entry colname="col1"><codeph>DROP RESOURCE QUEUE</codeph></entry>
<entry colname="col2">YES</entry>
<entry colname="col3">Greenplum Database workload management feature - not in
PostgreSQL 8.2.15.</entry>
PostgreSQL 8.3.</entry>
</row>
<row>
<entry colname="col1"><codeph>DROP ROLE</codeph></entry>
......
......@@ -63,6 +63,7 @@
<topicref href="sql_commands/DEALLOCATE.xml"/>
<topicref href="sql_commands/DECLARE.xml"/>
<topicref href="sql_commands/DELETE.xml"/>
<topicref href="sql_commands/DO.xml"/>
<topicref href="sql_commands/DROP_AGGREGATE.xml"/>
<topicref href="sql_commands/DROP_CAST.xml"/>
<topicref href="sql_commands/DROP_CONVERSION.xml"/>
......@@ -168,7 +169,7 @@
<topicref href="system_catalogs/pg_database.xml"/>
<topicref href="system_catalogs/pg_depend.xml"/>
<topicref href="system_catalogs/pg_description.xml"/>
<topicref href="system_catalogs/pg_enum.xml"/>
<topicref href="system_catalogs/pg_enum.xml"/>
<topicref href="system_catalogs/pg_exttable.xml"/>
<topicref href="system_catalogs/pg_filespace.xml"/>
<topicref href="system_catalogs/pg_filespace_entry.xml"/>
......
......@@ -10,14 +10,13 @@
<codeblock id="sql_command_synopsis">CREATE [PROCEDURAL] LANGUAGE <varname>name</varname>
CREATE [TRUSTED] [PROCEDURAL] LANGUAGE <varname>name</varname>
       HANDLER <varname>call_handler</varname> [VALIDATOR <varname>valfunction</varname>]</codeblock>
       HANDLER <varname>call_handler</varname> [ INLINE <varname>inline_handler</varname> ] [VALIDATOR <varname>valfunction</varname>]</codeblock>
</section>
<section id="section3">
<title>Description</title>
<p><codeph>CREATE LANGUAGE</codeph> registers a new procedural language with a Greenplum
database. Subsequently, functions and trigger procedures can be defined in this new
language. The PL/pgSQL language is already registered in all databases by
default.</p>
language. </p>
<p>Superusers can register a new language with a Greenplum database. A database owner
can also register within that database any language listed in the
<codeph>pg_pltemplate</codeph> catalog in which the
......@@ -44,11 +43,11 @@ CREATE [TRUSTED] [PROCEDURAL] LANGUAGE <varname>name</varname>
<p>The PL/Perl, PL/Java, and PL/R libraries require the correct versions of Perl, Java,
and R to be installed, respectively. </p>
<p>On RHEL and SUSE platforms, download the appropriate extensions from <xref
href="https://network.pivotal.io" scope="external" format="html"
>Pivotal Network</xref>, then install the extensions using the Greenplum Package
Manager (<codeph>gppkg</codeph>) utility to ensure that all dependencies are
installed as well as the extensions. See the Greenplum Database Utility Guide for
details about <codeph>gppkg</codeph>. </p>
href="https://network.pivotal.io" scope="external" format="html">Pivotal
Network</xref>, then install the extensions using the Greenplum Package Manager
(<codeph>gppkg</codeph>) utility to ensure that all dependencies are installed
as well as the extensions. See the Greenplum Database Utility Guide for details
about <codeph>gppkg</codeph>. </p>
<p>There are two forms of the <codeph>CREATE LANGUAGE</codeph> command. In the first
form, the user specifies the name of the desired language and the Greenplum Database
server uses the <codeph>pg_pltemplate</codeph> system catalog to determine the
......@@ -66,11 +65,11 @@ CREATE [TRUSTED] [PROCEDURAL] LANGUAGE <varname>name</varname>
<plentry>
<pt>TRUSTED</pt>
<pd>Ignored if the server has an entry for the specified language name in
<varname>pg_pltemplate</varname>. Specifies that the call handler for
the language is safe and does not offer an unprivileged user any
functionality to bypass access restrictions. If this key word is omitted
when registering the language, only users with the superuser privilege can
use this language to create new functions.</pd>
<codeph>pg_pltemplate</codeph>. Specifies that the call handler for the
language is safe and does not offer an unprivileged user any functionality
to bypass access restrictions. If this key word is omitted when registering
the language, only users with the superuser privilege can use this language
to create new functions.</pd>
</plentry>
<plentry>
<pt>PROCEDURAL</pt>
......@@ -99,29 +98,35 @@ CREATE [TRUSTED] [PROCEDURAL] LANGUAGE <varname>name</varname>
<codeph>language_handler</codeph> type, a placeholder type that is
simply used to identify the function as a call handler.</pd>
</plentry>
<plentry>
<pt>INLINE <varname>inline_handler</varname></pt>
<pd>The name of a previously registered function that is called to execute an
anonymous code block in this language that is created with the <codeph><xref
href="DO.xml#topic1"/></codeph> command. If an
<codeph>inline_handler</codeph> function is not specified, the language
does not support anonymous code blocks. The handler function must take one
argument of type <codeph>internal</codeph>, which is the <codeph><xref
href="DO.xml#topic1"/></codeph> command internal representation. The
function typically return <codeph>void</codeph>. The return value of the
handler is ignored. </pd>
</plentry>
<plentry>
<pt>VALIDATOR <varname>valfunction</varname></pt>
<pd>Ignored if the server has an entry for the specified language name in
<codeph>pg_pltemplate</codeph>. <varname>valfunction</varname> is the
name of a previously registered function that will be called when a new
function in the language is created, to validate the new function. If no
validator function is specified, then a new function will not be checked
when it is created. The validator function must take one argument of type
<codeph>oid</codeph>, which will be the OID of the to-be-created
function, and will typically return <codeph>void</codeph>. </pd>
<pd>A validator function would typically inspect the function body for
syntactical correctness, but it can also look at other properties of the
function, for example if the language cannot handle certain argument types.
To signal an error, the validator function should use the
<codeph>ereport()</codeph> function. The return value of the function is
ignored.</pd>
<codeph>pg_pltemplate</codeph>. The name of a previously registered
function that will be called to execute the procedural language functions.
The call handler for a procedural language must be written in a compiled
language such as C with version 1 call convention and registered with
Greenplum Database as a function taking no arguments and returning the
<codeph>language_handler</codeph> type, a placeholder type that is
simply used to identify the function as a call handler.</pd>
</plentry>
</parml>
</section>
<section id="section5">
<title>Notes</title>
<p>The PL/pgSQL and PL/Python language extensions are installed by default in Greenplum
Database.</p>
<p>The PL/pgSQL language is already registered in all databases by default. The
PL/Python language extension is installed but not registered.</p>
<p>The system catalog <codeph>pg_language</codeph> records information about the
currently installed languages.</p>
<p>To create functions in a procedural language, a user must have the
......@@ -160,7 +165,8 @@ CREATE LANGUAGE plsample
<p><codeph><xref href="ALTER_LANGUAGE.xml#topic1" type="topic" format="dita"/></codeph>,
<codeph><xref href="CREATE_FUNCTION.xml#topic1" type="topic" format="dita"
/></codeph>, <codeph><xref href="./DROP_LANGUAGE.xml#topic1" type="topic"
format="dita"/></codeph></p>
format="dita"/></codeph>
<codeph><xref href="DO.xml#topic1"/></codeph></p>
</section>
</body>
</topic>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE topic
PUBLIC "-//OASIS//DTD DITA Composite//EN" "ditabase.dtd">
<topic id="topic1">
<title id="af20941">DO</title>
<body>
<p id="sql_command_desc">Executes an anonymous code block as a transient anonymous function.</p>
<section id="section2">
<title>Synopsis</title>
<codeblock id="sql_command_synopsis">DO [ LANGUAGE <varname>lang_name</varname> ] <varname>code</varname></codeblock>
</section>
<section id="section3">
<title>Description</title>
<p><codeph>DO</codeph> executes an anonymous code block, or in other words a transient
anonymous function in a procedural language.</p>
<p>The code block is treated as though it were the body of a function with no parameters,
returning void. It is parsed and executed a single time.</p>
<p>The optional <codeph>LANGUAGE</codeph> clause can appear either before or after the code
block.</p>
<p> Anonymous blocks are procedural language structures that provide the capability to create
and execute procedural code on the fly without persistently storing the code as database
objects in the system catalogs. The concept of anonymous blocks is similar to UNIX shell
scripts, which enable several manually entered commands to be grouped and executed as one
step. As the name implies, anonymous blocks do not have a name, and for this reason they
cannot be referenced from other objects. Although built dynamically, anonymous blocks can be
easily stored as scripts in the operating system files for repetitive execution. </p>
<p>Anonymous blocks are standard procedural language blocks. They carry the syntax and obey
the rules that apply to the procedural language, including declaration and scope of
variables, execution, exception handling, and language usage. </p>
<p>The compilation and execution of anonymous blocks are combined in one step, while a
user-defined function needs to be re-defined before use each time its definition
changes.</p>
</section>
<section id="section4">
<title>Parameters</title>
<parml>
<plentry>
<pt>
<varname>code</varname>
</pt>
<pd>The procedural language code to be executed. This must be specified as a string
literal, just as with the <codeph>CREATE FUNCTION</codeph> command. Use of a
dollar-quoted literal is recommended. Optional keywords have no effect. These procedural
languages are supported: PL/pgSQL (<codeph>plpgsql</codeph>), PL/Python
(<codeph>plpythonu</codeph>), and PL/Perl (<codeph>plperl</codeph> and
<codeph>plperlu</codeph>).</pd>
</plentry>
<plentry>
<pt>
<varname>lang_name</varname>
</pt>
<pd>The name of the procedural language that the code is written in. The default is
<codeph>plpgsql</codeph>. The language must be installed on the Greenplum Database
system and registered in the database.</pd>
</plentry>
</parml>
</section>
<section id="section5">
<title>Notes</title>
<p>The PL/pgSQL language is installed on the Greenplum Database system and is registered in a
user created database. The PL/Python language is installed by default. Other languages are
not installed or registered. The system catalog <codeph>pg_language</codeph> contains
information about the registered languages in a database.</p>
<p>The user must have <codeph>USAGE</codeph> privilege for the procedural language, or must be
a superuser if the language is untrusted. This is the same privilege requirement as for
creating a function in the language.</p>
</section>
<section>
<title>Examples</title>
<p>This PL/pgSQL example grants all privileges on all views in schema <i>public</i> to role
<codeph>webuser</codeph>:</p>
<codeblock>DO $$DECLARE r record;
BEGIN
FOR r IN SELECT table_schema, table_name FROM information_schema.tables
WHERE table_type = 'VIEW' AND table_schema = 'public'
LOOP
EXECUTE 'GRANT ALL ON ' || quote_ident(r.table_schema) || '.' || quote_ident(r.table_name) || ' TO webuser';
END LOOP;
END$$;</codeblock>
<p>This PL/pgSQL example determines if a Greenplum Database user is a superuser. In the
example, the anonymous block retrieves the input value from a temporary
table.<codeblock>CREATE TEMP TABLE list AS VALUES ('gpadmin') DISTRIBUTED RANDOMLY;
DO $$
DECLARE
name TEXT := 'gpadmin' ;
superuser TEXT := '' ;
  t1_row pg_authid%ROWTYPE;
BEGIN
  SELECT * INTO t1_row FROM pg_authid, list
WHERE pg_authid.rolname = name ;
IF t1_row.rolsuper = 'f' THEN
superuser := 'not ';
END IF ;
  RAISE NOTICE 'user % is %a superuser', t1_row.rolname, superuser ;
END $$ LANGUAGE plpgsql ;</codeblock></p>
</section>
<note type="note">The example PL/pgSQL uses <codeph>SELECT</codeph> with the
<codeph>INTO</codeph> clause. It is different from the SQL command <codeph>SELECT
INTO</codeph>.</note>
<section id="section6">
<title>Compatibility</title>
<p>There is no <codeph>DO</codeph> statement in the SQL standard.</p>
</section>
<section id="section7">
<title>See Also</title>
<p>
<codeph>CREATE LANGUAGE</codeph>
<xref href="../extensions/pl_sql.xml#topic1"/></p>
</section>
</body>
</topic>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE topic
PUBLIC "-//OASIS//DTD DITA Composite//EN" "ditabase.dtd">
<topic id="topic1" xml:lang="en"><title id="gs143896">pg_language</title><body><p>The <codeph>pg_language</codeph> system catalog table registers languages
in which you can write functions or stored procedures. It is populated
by <codeph>CREATE LANGUAGE</codeph>.</p><table id="gs143898"><title>pg_catalog.pg_language</title><tgroup cols="4"><colspec colnum="1" colname="col1" colwidth="131pt"/><colspec colnum="2" colname="col2" colwidth="86pt"/><colspec colnum="3" colname="col3" colwidth="85pt"/><colspec colnum="4" colname="col4" colwidth="147pt"/><thead><row><entry colname="col1">column</entry><entry colname="col2">type</entry><entry colname="col3">references</entry><entry colname="col4">description</entry></row></thead><tbody><row><entry colname="col1"><codeph>lanname</codeph></entry><entry colname="col2">name</entry><entry colname="col3"/><entry colname="col4">Name of the language.</entry></row><row><entry colname="col1"><codeph>lanispl </codeph></entry><entry colname="col2">boolean</entry><entry colname="col3"/><entry colname="col4">This is false for internal languages (such as
SQL) and true for user-defined languages. Currently, <codeph>pg_dump</codeph>
still uses this to determine which languages need to be dumped, but this
may be replaced by a different mechanism in the future.</entry></row><row><entry colname="col1"><codeph>lanpltrusted </codeph></entry><entry colname="col2">boolean</entry><entry colname="col3"/><entry colname="col4">True if this is a trusted language, which means
that it is believed not to grant access to anything outside the normal
SQL execution environment. Only superusers may create functions in untrusted
languages.</entry></row><row><entry colname="col1"><codeph>lanplcallfoid</codeph></entry><entry colname="col2">oid</entry><entry colname="col3">pg_proc.oid</entry><entry colname="col4">For noninternal languages this references the
language handler, which is a special function that is responsible for
executing all functions that are written in the particular language.</entry></row><row><entry colname="col1"><codeph>lanvalidator</codeph></entry><entry colname="col2">oid</entry><entry colname="col3">pg_proc.oid</entry><entry colname="col4">This references a language validator function
that is responsible for checking the syntax and validity of new functions
when they are created. Zero if no validator is provided.</entry></row><row><entry colname="col1"><codeph>lanacl </codeph></entry><entry colname="col2">aclitem[]</entry><entry colname="col3"/><entry colname="col4">Access privileges for the language.</entry></row></tbody></tgroup></table></body></topic>
\ No newline at end of file
<topic id="topic1" xml:lang="en">
<title id="gs143896">pg_language</title>
<body>
<p>The <codeph>pg_language</codeph> system catalog table registers languages in which you can
write functions or stored procedures. It is populated by <codeph>CREATE LANGUAGE</codeph>.</p>
<table id="gs143898">
<title>pg_catalog.pg_language</title>
<tgroup cols="4">
<colspec colnum="1" colname="col1" colwidth="131pt"/>
<colspec colnum="2" colname="col2" colwidth="86pt"/>
<colspec colnum="3" colname="col3" colwidth="85pt"/>
<colspec colnum="4" colname="col4" colwidth="147pt"/>
<thead>
<row>
<entry colname="col1">column</entry>
<entry colname="col2">type</entry>
<entry colname="col3">references</entry>
<entry colname="col4">description</entry>
</row>
</thead>
<tbody>
<row>
<entry colname="col1"><codeph>lanname</codeph></entry>
<entry colname="col2">name</entry>
<entry colname="col3"/>
<entry colname="col4">Name of the language.</entry>
</row>
<row>
<entry colname="col1"><codeph>lanowner</codeph>
</entry>
<entry colname="col2">oid</entry>
<entry colname="col3">pg_authid.oid</entry>
<entry colname="col4">Owner of the language.</entry>
</row>
<row>
<entry colname="col1"><codeph>lanispl </codeph></entry>
<entry colname="col2">boolean</entry>
<entry colname="col3"/>
<entry colname="col4">This is false for internal languages (such as SQL) and true for
user-defined languages. Currently, <codeph>pg_dump</codeph> still uses this to
determine which languages need to be dumped, but this may be replaced by a different
mechanism in the future.</entry>
</row>
<row>
<entry colname="col1"><codeph>lanpltrusted </codeph></entry>
<entry colname="col2">boolean</entry>
<entry colname="col3"/>
<entry colname="col4">True if this is a trusted language, which means that it is
believed not to grant access to anything outside the normal SQL execution environment.
Only superusers may create functions in untrusted languages.</entry>
</row>
<row>
<entry colname="col1"><codeph>lanplcallfoid</codeph></entry>
<entry colname="col2">oid</entry>
<entry colname="col3">pg_proc.oid</entry>
<entry colname="col4">For noninternal languages this references the language handler,
which is a special function that is responsible for executing all functions that are
written in the particular language.</entry>
</row>
<row>
<entry colname="col1"><codeph>laninline</codeph></entry>
<entry colname="col2">oid</entry>
<entry colname="col3">pg_proc.oid</entry>
<entry colname="col4">This references a function that is responsible for executing
inline anonymous code blocks (see the <codeph><xref
href="../sql_commands/DO.xml#topic1"/></codeph> command). Zero if anonymous blocks
are not supported.</entry>
</row>
<row>
<entry colname="col1"><codeph>lanvalidator</codeph></entry>
<entry colname="col2">oid</entry>
<entry colname="col3">pg_proc.oid</entry>
<entry colname="col4">This references a language validator function that is responsible
for checking the syntax and validity of new functions when they are created. Zero if
no validator is provided.</entry>
</row>
<row>
<entry colname="col1"><codeph>lanacl </codeph></entry>
<entry colname="col2">aclitem[]</entry>
<entry colname="col3"/>
<entry colname="col4">Access privileges for the language.</entry>
</row>
</tbody>
</tgroup>
</table>
</body>
</topic>
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册