Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
Postgres FD Implementation
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Abuhujair Javed
Postgres FD Implementation
Commits
e33eeb24
Commit
e33eeb24
authored
Sep 23, 2009
by
Tom Lane
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improve example for DO, per Petr Jelinek.
parent
c2bb0378
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
14 additions
and
6 deletions
+14
-6
doc/src/sgml/ref/do.sgml
doc/src/sgml/ref/do.sgml
+14
-6
No files found.
doc/src/sgml/ref/do.sgml
View file @
e33eeb24
<!--
<!--
$PostgreSQL: pgsql/doc/src/sgml/ref/do.sgml,v 1.
1 2009/09/22 23:43:37
tgl Exp $
$PostgreSQL: pgsql/doc/src/sgml/ref/do.sgml,v 1.
2 2009/09/23 15:41:51
tgl Exp $
PostgreSQL documentation
PostgreSQL documentation
-->
-->
...
@@ -42,6 +42,11 @@ DO <replaceable class="PARAMETER">code</replaceable> [ LANGUAGE <replaceable cla
...
@@ -42,6 +42,11 @@ DO <replaceable class="PARAMETER">code</replaceable> [ LANGUAGE <replaceable cla
with no parameters, returning <type>void</>. It is parsed and
with no parameters, returning <type>void</>. It is parsed and
executed a single time.
executed a single time.
</para>
</para>
<para>
The optional <literal>LANGUAGE</> clause can be written either
before or after the code block.
</para>
</refsect1>
</refsect1>
<refsect1>
<refsect1>
...
@@ -91,17 +96,20 @@ DO <replaceable class="PARAMETER">code</replaceable> [ LANGUAGE <replaceable cla
...
@@ -91,17 +96,20 @@ DO <replaceable class="PARAMETER">code</replaceable> [ LANGUAGE <replaceable cla
<refsect1 id="sql-do-examples">
<refsect1 id="sql-do-examples">
<title id="sql-do-examples-title">Examples</title>
<title id="sql-do-examples-title">Examples</title>
<para>
<para>
Execute a simple PL/pgsql loop without needing to create a function:
Grant all privileges on all views in schema <literal>public</> to
role <literal>webuser</>:
<programlisting>
<programlisting>
DO $$
DO $$DECLARE r record;
DECLARE r record;
BEGIN
BEGIN
FOR r IN SELECT rtrim(roomno) AS roomno, comment FROM Room ORDER BY roomno
FOR r IN SELECT table_schema, table_name FROM information_schema.tables
WHERE table_type = 'VIEW' AND table_schema = 'public'
LOOP
LOOP
RAISE NOTICE '%, %', r.roomno, r.comment
;
EXECUTE 'GRANT ALL ON ' || quote_ident(r.table_schema) || '.' || quote_ident(r.table_name) || ' TO webuser'
;
END LOOP;
END LOOP;
END$$;
END$$;
</programlisting>
</programlisting>
This example assumes that <varname>default_do_language</> has its
default value, namely <literal>plpgsql</>.
</para>
</para>
</refsect1>
</refsect1>
<refsect1>
<refsect1>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment