From b8415e908d27ba0a76a7725ce61d083e21bd3bdf Mon Sep 17 00:00:00 2001
From: Erik Wienhold <ewie@ewie.name>
Date: Thu, 16 Oct 2025 10:30:21 +0200
Subject: [PATCH v3] doc: Apply consistent formatting to sample SQL statements

Use uppercase SQL keywords consistently throughout the documentation to
ease reading.  Also add a single space between keywords/names and tuples
which is a common convention, such as after keyword VALUES.  Additional
whitespace is added in a couple of other places where it improves
readability.
---
 doc/src/sgml/advanced.sgml               |   4 +-
 doc/src/sgml/bloom.sgml                  |  12 +--
 doc/src/sgml/config.sgml                 |   6 +-
 doc/src/sgml/cube.sgml                   |   8 +-
 doc/src/sgml/datatype.sgml               |   6 +-
 doc/src/sgml/datetime.sgml               |   6 +-
 doc/src/sgml/dblink.sgml                 |  26 +++---
 doc/src/sgml/ddl.sgml                    |  28 +++----
 doc/src/sgml/dict-int.sgml               |   2 +-
 doc/src/sgml/dml.sgml                    |   2 +-
 doc/src/sgml/ecpg.sgml                   |   2 +-
 doc/src/sgml/event-trigger.sgml          |   2 +-
 doc/src/sgml/func/func-binarystring.sgml |   4 +-
 doc/src/sgml/func/func-matching.sgml     |   8 +-
 doc/src/sgml/func/func-srf.sgml          |   4 +-
 doc/src/sgml/hstore.sgml                 |   2 +-
 doc/src/sgml/indices.sgml                |   6 +-
 doc/src/sgml/logical-replication.sgml    |  36 ++++----
 doc/src/sgml/logicaldecoding.sgml        |  24 +++---
 doc/src/sgml/maintenance.sgml            |   4 +-
 doc/src/sgml/manage-ag.sgml              |   4 +-
 doc/src/sgml/monitoring.sgml             |   4 +-
 doc/src/sgml/pgcrypto.sgml               |   2 +-
 doc/src/sgml/pgstattuple.sgml            |   2 +-
 doc/src/sgml/pgsurgery.sgml              |  12 +--
 doc/src/sgml/planstats.sgml              |   2 +-
 doc/src/sgml/plperl.sgml                 |   4 +-
 doc/src/sgml/plpgsql.sgml                |  46 +++++------
 doc/src/sgml/plpython.sgml               |   2 +-
 doc/src/sgml/pltcl.sgml                  |   2 +-
 doc/src/sgml/queries.sgml                |   4 +-
 doc/src/sgml/ref/alter_table.sgml        |   2 +-
 doc/src/sgml/ref/alter_view.sgml         |   4 +-
 doc/src/sgml/ref/create_function.sgml    |   6 +-
 doc/src/sgml/ref/create_table.sgml       |  22 ++---
 doc/src/sgml/ref/pg_rewind.sgml          |   8 +-
 doc/src/sgml/ref/psql-ref.sgml           |  12 +--
 doc/src/sgml/ref/select.sgml             |   2 +-
 doc/src/sgml/ref/values.sgml             |   6 +-
 doc/src/sgml/rules.sgml                  |   2 +-
 doc/src/sgml/syntax.sgml                 |   4 +-
 doc/src/sgml/tablefunc.sgml              | 100 +++++++++++------------
 doc/src/sgml/tcn.sgml                    |  22 ++---
 doc/src/sgml/textsearch.sgml             |   6 +-
 44 files changed, 236 insertions(+), 236 deletions(-)

diff --git a/doc/src/sgml/advanced.sgml b/doc/src/sgml/advanced.sgml
index e15a3323dfb..82e82c13457 100644
--- a/doc/src/sgml/advanced.sgml
+++ b/doc/src/sgml/advanced.sgml
@@ -101,12 +101,12 @@ SELECT * FROM myview;
 
 <programlisting>
 CREATE TABLE cities (
-        name     varchar(80) primary key,
+        name     varchar(80) PRIMARY KEY,
         location point
 );
 
 CREATE TABLE weather (
-        city      varchar(80) references cities(name),
+        city      varchar(80) REFERENCES cities (name),
         temp_lo   int,
         temp_hi   int,
         prcp      real,
diff --git a/doc/src/sgml/bloom.sgml b/doc/src/sgml/bloom.sgml
index ec5d077679b..3f6d38f377b 100644
--- a/doc/src/sgml/bloom.sgml
+++ b/doc/src/sgml/bloom.sgml
@@ -101,12 +101,12 @@ CREATE INDEX bloomidx ON tbloom USING bloom (i1,i2,i3)
 <programlisting>
 =# CREATE TABLE tbloom AS
    SELECT
-     (random() * 1000000)::int as i1,
-     (random() * 1000000)::int as i2,
-     (random() * 1000000)::int as i3,
-     (random() * 1000000)::int as i4,
-     (random() * 1000000)::int as i5,
-     (random() * 1000000)::int as i6
+     (random() * 1000000)::int AS i1,
+     (random() * 1000000)::int AS i2,
+     (random() * 1000000)::int AS i3,
+     (random() * 1000000)::int AS i4,
+     (random() * 1000000)::int AS i5,
+     (random() * 1000000)::int AS i6
    FROM
   generate_series(1,10000000);
 SELECT 10000000
diff --git a/doc/src/sgml/config.sgml b/doc/src/sgml/config.sgml
index 06d1e4403b5..565812f7fcc 100644
--- a/doc/src/sgml/config.sgml
+++ b/doc/src/sgml/config.sgml
@@ -6393,9 +6393,9 @@ ANY <replaceable class="parameter">num_sync</replaceable> ( <replaceable class="
         contradict the constraints.  For example:
 
 <programlisting>
-CREATE TABLE parent(key integer, ...);
-CREATE TABLE child1000(check (key between 1000 and 1999)) INHERITS(parent);
-CREATE TABLE child2000(check (key between 2000 and 2999)) INHERITS(parent);
+CREATE TABLE parent (key integer, ...);
+CREATE TABLE child1000 (CHECK (key BETWEEN 1000 AND 1999)) INHERITS (parent);
+CREATE TABLE child2000 (CHECK (key BETWEEN 2000 AND 2999)) INHERITS (parent);
 ...
 SELECT * FROM parent WHERE key = 2400;
 </programlisting>
diff --git a/doc/src/sgml/cube.sgml b/doc/src/sgml/cube.sgml
index 0fb70807486..8cfcb6c7daa 100644
--- a/doc/src/sgml/cube.sgml
+++ b/doc/src/sgml/cube.sgml
@@ -249,7 +249,7 @@
    For example, the nearest neighbor of the 3-D point (0.5, 0.5, 0.5)
    could be found efficiently with:
 <programlisting>
-SELECT c FROM test ORDER BY c &lt;-&gt; cube(array[0.5,0.5,0.5]) LIMIT 1;
+SELECT c FROM test ORDER BY c &lt;-&gt; cube(ARRAY[0.5,0.5,0.5]) LIMIT 1;
 </programlisting>
   </para>
 
@@ -540,7 +540,7 @@ SELECT c FROM test ORDER BY c ~&gt; 3 DESC LIMIT 5;
    This union:
   </para>
 <programlisting>
-select cube_union('(0,5,2),(2,3,1)', '0');
+SELECT cube_union('(0,5,2),(2,3,1)', '0');
 cube_union
 -------------------
 (0, 0, 0),(2, 5, 2)
@@ -552,7 +552,7 @@ cube_union
    </para>
 
 <programlisting>
-select cube_inter('(0,-1),(1,1)', '(-2),(2)');
+SELECT cube_inter('(0,-1),(1,1)', '(-2),(2)');
 cube_inter
 -------------
 (0, 0),(1, 0)
@@ -579,7 +579,7 @@ cube_inter('(0,-1),(1,1)','(-2,0),(2,0)');
    </para>
 
 <programlisting>
-select cube_contains('(0,0),(1,1)', '0.5,0.5');
+SELECT cube_contains('(0,0),(1,1)', '0.5,0.5');
 cube_contains
 --------------
 t
diff --git a/doc/src/sgml/datatype.sgml b/doc/src/sgml/datatype.sgml
index b81d89e2608..ebae990392b 100644
--- a/doc/src/sgml/datatype.sgml
+++ b/doc/src/sgml/datatype.sgml
@@ -717,7 +717,7 @@ NUMERIC(3, 5)
 SELECT x,
   round(x::numeric) AS num_round,
   round(x::double precision) AS dbl_round
-FROM generate_series(-3.5, 3.5, 1) as x;
+FROM generate_series(-3.5, 3.5, 1) AS x;
   x   | num_round | dbl_round
 ------+-----------+-----------
  -3.5 |        -4 |        -4
@@ -1259,7 +1259,7 @@ SELECT '52093.89'::money::numeric::float8;
     semantically insignificant and disregarded when comparing two values
     of type <type>character</type>.  In collations where whitespace
     is significant, this behavior can produce unexpected results;
-    for example <command>SELECT 'a '::CHAR(2) collate "C" &lt;
+    for example <command>SELECT 'a '::CHAR(2) COLLATE "C" &lt;
     E'a\n'::CHAR(2)</command> returns true, even though <literal>C</literal>
     locale would consider a space to be greater than a newline.
     Trailing spaces are removed when converting a <type>character</type> value
@@ -4112,7 +4112,7 @@ SELECT macaddr8_set7bit('08:00:2b:01:02:03');
     <title>Using the Bit String Types</title>
 
 <programlisting>
-CREATE TABLE test (a BIT(3), b BIT VARYING(5));
+CREATE TABLE test (a bit(3), b bit varying(5));
 INSERT INTO test VALUES (B'101', B'00');
 INSERT INTO test VALUES (B'10', B'101');
 <computeroutput>
diff --git a/doc/src/sgml/datetime.sgml b/doc/src/sgml/datetime.sgml
index 3e24170acbf..5905f5fa550 100644
--- a/doc/src/sgml/datetime.sgml
+++ b/doc/src/sgml/datetime.sgml
@@ -942,17 +942,17 @@ $ <userinput>cal 9 1752</userinput>
    definition when you need it: do the arithmetic in time
    zone <literal>UTC+12</literal>.  For example,
 <programlisting>
-=&gt; SELECT extract(julian from '2021-06-23 7:00:00-04'::timestamptz at time zone 'UTC+12');
+=&gt; SELECT extract(julian FROM '2021-06-23 7:00:00-04'::timestamptz AT TIME ZONE 'UTC+12');
            extract
 ------------------------------
  2459388.95833333333333333333
 (1 row)
-=&gt; SELECT extract(julian from '2021-06-23 8:00:00-04'::timestamptz at time zone 'UTC+12');
+=&gt; SELECT extract(julian FROM '2021-06-23 8:00:00-04'::timestamptz AT TIME ZONE 'UTC+12');
                extract
 --------------------------------------
  2459389.0000000000000000000000000000
 (1 row)
-=&gt; SELECT extract(julian from date '2021-06-23');
+=&gt; SELECT extract(julian FROM date '2021-06-23');
  extract
 ---------
  2459389
diff --git a/doc/src/sgml/dblink.sgml b/doc/src/sgml/dblink.sgml
index 808c690985b..070795992f6 100644
--- a/doc/src/sgml/dblink.sgml
+++ b/doc/src/sgml/dblink.sgml
@@ -444,7 +444,7 @@ dblink(text sql [, bool fail_on_error]) returns setof record
      <listitem>
       <para>
        The SQL query that you wish to execute in the remote database,
-       for example <literal>select * from foo</literal>.
+       for example <literal>SELECT * FROM foo</literal>.
       </para>
      </listitem>
     </varlistentry>
@@ -478,7 +478,7 @@ dblink(text sql [, bool fail_on_error]) returns setof record
 <programlisting>
 SELECT *
     FROM dblink('dbname=mydb options=-csearch_path=',
-                'select proname, prosrc from pg_proc')
+                'SELECT proname, prosrc FROM pg_proc')
       AS t1(proname name, prosrc text)
     WHERE proname LIKE 'bytea%';
 </programlisting>
@@ -513,7 +513,7 @@ SELECT *
 CREATE VIEW myremote_pg_proc AS
   SELECT *
     FROM dblink('dbname=postgres options=-csearch_path=',
-                'select proname, prosrc from pg_proc')
+                'SELECT proname, prosrc FROM pg_proc')
     AS t1(proname name, prosrc text);
 
 SELECT * FROM myremote_pg_proc WHERE proname LIKE 'bytea%';
@@ -525,7 +525,7 @@ SELECT * FROM myremote_pg_proc WHERE proname LIKE 'bytea%';
 
 <screen>
 SELECT * FROM dblink('dbname=postgres options=-csearch_path=',
-                     'select proname, prosrc from pg_proc')
+                     'SELECT proname, prosrc FROM pg_proc')
   AS t1(proname name, prosrc text) WHERE proname LIKE 'bytea%';
   proname   |   prosrc
 ------------+------------
@@ -549,7 +549,7 @@ SELECT dblink_connect('dbname=postgres options=-csearch_path=');
  OK
 (1 row)
 
-SELECT * FROM dblink('select proname, prosrc from pg_proc')
+SELECT * FROM dblink('SELECT proname, prosrc FROM pg_proc')
   AS t1(proname name, prosrc text) WHERE proname LIKE 'bytea%';
   proname   |   prosrc
 ------------+------------
@@ -573,7 +573,7 @@ SELECT dblink_connect('myconn', 'dbname=regression options=-csearch_path=');
  OK
 (1 row)
 
-SELECT * FROM dblink('myconn', 'select proname, prosrc from pg_proc')
+SELECT * FROM dblink('myconn', 'SELECT proname, prosrc FROM pg_proc')
   AS t1(proname name, prosrc text) WHERE proname LIKE 'bytea%';
   proname   |   prosrc
 ------------+------------
@@ -793,7 +793,7 @@ dblink_open(text connname, text cursorname, text sql [, bool fail_on_error]) ret
      <listitem>
       <para>
        The <command>SELECT</command> statement that you wish to execute in the remote
-       database, for example <literal>select * from pg_class</literal>.
+       database, for example <literal>SELECT * FROM pg_class</literal>.
       </para>
      </listitem>
     </varlistentry>
@@ -848,7 +848,7 @@ SELECT dblink_connect('dbname=postgres options=-csearch_path=');
  OK
 (1 row)
 
-SELECT dblink_open('foo', 'select proname, prosrc from pg_proc');
+SELECT dblink_open('foo', 'SELECT proname, prosrc FROM pg_proc');
  dblink_open
 -------------
  OK
@@ -969,7 +969,7 @@ SELECT dblink_connect('dbname=postgres options=-csearch_path=');
  OK
 (1 row)
 
-SELECT dblink_open('foo', 'select proname, prosrc from pg_proc where proname like ''bytea%''');
+SELECT dblink_open('foo', 'SELECT proname, prosrc FROM pg_proc WHERE proname LIKE ''bytea%''');
  dblink_open
 -------------
  OK
@@ -1106,7 +1106,7 @@ SELECT dblink_connect('dbname=postgres options=-csearch_path=');
  OK
 (1 row)
 
-SELECT dblink_open('foo', 'select proname, prosrc from pg_proc');
+SELECT dblink_open('foo', 'SELECT proname, prosrc FROM pg_proc');
  dblink_open
 -------------
  OK
@@ -1301,7 +1301,7 @@ dblink_send_query(text connname, text sql) returns int
      <listitem>
       <para>
        The SQL statement that you wish to execute in the remote database,
-       for example <literal>select * from pg_class</literal>.
+       for example <literal>SELECT * FROM pg_class</literal>.
       </para>
      </listitem>
     </varlistentry>
@@ -1583,7 +1583,7 @@ contrib_regression=# SELECT dblink_connect('dtest1', 'dbname=contrib_regression'
 (1 row)
 
 contrib_regression=# SELECT * FROM
-contrib_regression-# dblink_send_query('dtest1', 'select * from foo where f1 &lt; 3') AS t1;
+contrib_regression-# dblink_send_query('dtest1', 'SELECT * FROM foo WHERE f1 &lt; 3') AS t1;
  t1
 ----
   1
@@ -1603,7 +1603,7 @@ contrib_regression=# SELECT * FROM dblink_get_result('dtest1') AS t1(f1 int, f2
 (0 rows)
 
 contrib_regression=# SELECT * FROM
-contrib_regression-# dblink_send_query('dtest1', 'select * from foo where f1 &lt; 3; select * from foo where f1 &gt; 6') AS t1;
+contrib_regression-# dblink_send_query('dtest1', 'SELECT * FROM foo WHERE f1 &lt; 3; SELECT * FROM foo WHERE f1 &gt; 6') AS t1;
  t1
 ----
   1
diff --git a/doc/src/sgml/ddl.sgml b/doc/src/sgml/ddl.sgml
index 65bc070d2e5..9c248d2ba35 100644
--- a/doc/src/sgml/ddl.sgml
+++ b/doc/src/sgml/ddl.sgml
@@ -2834,9 +2834,9 @@ GRANT UPDATE
 
 <programlisting>
 -- admin can view all rows and fields
-postgres=&gt; set role admin;
+postgres=&gt; SET ROLE admin;
 SET
-postgres=&gt; table passwd;
+postgres=&gt; TABLE passwd;
  user_name | pwhash | uid | gid | real_name |  home_phone  | extra_info | home_dir    |   shell
 -----------+--------+-----+-----+-----------+--------------+------------+-------------+-----------
  admin     | xxx    |   0 |   0 | Admin     | 111-222-3333 |            | /root       | /bin/dash
@@ -2845,11 +2845,11 @@ postgres=&gt; table passwd;
 (3 rows)
 
 -- Test what Alice is able to do
-postgres=&gt; set role alice;
+postgres=&gt; SET ROLE alice;
 SET
-postgres=&gt; table passwd;
+postgres=&gt; TABLE passwd;
 ERROR:  permission denied for table passwd
-postgres=&gt; select user_name,real_name,home_phone,extra_info,home_dir,shell from passwd;
+postgres=&gt; SELECT user_name, real_name, home_phone, extra_info, home_dir, shell FROM passwd;
  user_name | real_name |  home_phone  | extra_info | home_dir    |   shell
 -----------+-----------+--------------+------------+-------------+-----------
  admin     | Admin     | 111-222-3333 |            | /root       | /bin/dash
@@ -2857,21 +2857,21 @@ postgres=&gt; select user_name,real_name,home_phone,extra_info,home_dir,shell fr
  alice     | Alice     | 098-765-4321 |            | /home/alice | /bin/zsh
 (3 rows)
 
-postgres=&gt; update passwd set user_name = 'joe';
+postgres=&gt; UPDATE passwd SET user_name = 'joe';
 ERROR:  permission denied for table passwd
 -- Alice is allowed to change her own real_name, but no others
-postgres=&gt; update passwd set real_name = 'Alice Doe';
+postgres=&gt; UPDATE passwd SET real_name = 'Alice Doe';
 UPDATE 1
-postgres=&gt; update passwd set real_name = 'John Doe' where user_name = 'admin';
+postgres=&gt; UPDATE passwd SET real_name = 'John Doe' WHERE user_name = 'admin';
 UPDATE 0
-postgres=&gt; update passwd set shell = '/bin/xx';
+postgres=&gt; UPDATE passwd SET shell = '/bin/xx';
 ERROR:  new row violates WITH CHECK OPTION for "passwd"
-postgres=&gt; delete from passwd;
+postgres=&gt; DELETE FROM passwd;
 ERROR:  permission denied for table passwd
-postgres=&gt; insert into passwd (user_name) values ('xxx');
+postgres=&gt; INSERT INTO passwd (user_name) VALUES ('xxx');
 ERROR:  permission denied for table passwd
 -- Alice can change her own password; RLS silently prevents updating other rows
-postgres=&gt; update passwd set pwhash = 'abc';
+postgres=&gt; UPDATE passwd SET pwhash = 'abc';
 UPDATE 1
 </programlisting>
 
@@ -2904,7 +2904,7 @@ CREATE POLICY admin_local_only ON passwd AS RESTRICTIVE TO admin
  admin
 (1 row)
 
-=&gt; select inet_client_addr();
+=&gt; SELECT inet_client_addr();
  inet_client_addr
 ------------------
  127.0.0.1
@@ -2915,7 +2915,7 @@ CREATE POLICY admin_local_only ON passwd AS RESTRICTIVE TO admin
 -----------+--------+-----+-----+-----------+------------+------------+----------+-------
 (0 rows)
 
-=&gt; UPDATE passwd set pwhash = NULL;
+=&gt; UPDATE passwd SET pwhash = NULL;
 UPDATE 0
 </programlisting>
 
diff --git a/doc/src/sgml/dict-int.sgml b/doc/src/sgml/dict-int.sgml
index 8dd07b9bc12..b4ce5484823 100644
--- a/doc/src/sgml/dict-int.sgml
+++ b/doc/src/sgml/dict-int.sgml
@@ -80,7 +80,7 @@ ALTER TEXT SEARCH DICTIONARY
    To test the dictionary, you can try
 
 <programlisting>
-mydb# select ts_lexize('intdict', '12345678');
+mydb# SELECT ts_lexize('intdict', '12345678');
  ts_lexize
 -----------
  {123456}
diff --git a/doc/src/sgml/dml.sgml b/doc/src/sgml/dml.sgml
index 458aee788b7..61c64cf6c49 100644
--- a/doc/src/sgml/dml.sgml
+++ b/doc/src/sgml/dml.sgml
@@ -317,7 +317,7 @@ DELETE FROM products;
    column to provide unique identifiers, <literal>RETURNING</literal> can return
    the ID assigned to a new row:
 <programlisting>
-CREATE TABLE users (firstname text, lastname text, id serial primary key);
+CREATE TABLE users (firstname text, lastname text, id serial PRIMARY KEY);
 
 INSERT INTO users (firstname, lastname) VALUES ('Joe', 'Cool') RETURNING id;
 </programlisting>
diff --git a/doc/src/sgml/ecpg.sgml b/doc/src/sgml/ecpg.sgml
index e7a53f3c9d0..d3b25b24500 100644
--- a/doc/src/sgml/ecpg.sgml
+++ b/doc/src/sgml/ecpg.sgml
@@ -1991,7 +1991,7 @@ EXEC SQL EXECUTE IMMEDIATE :stmt;
     example:
 <programlisting>
 EXEC SQL BEGIN DECLARE SECTION;
-const char *stmt = "INSERT INTO test1 VALUES(?, ?);";
+const char *stmt = "INSERT INTO test1 VALUES (?, ?);";
 EXEC SQL END DECLARE SECTION;
 
 EXEC SQL PREPARE mystmt FROM :stmt;
diff --git a/doc/src/sgml/event-trigger.sgml b/doc/src/sgml/event-trigger.sgml
index 1bd9abb6676..c10627554bd 100644
--- a/doc/src/sgml/event-trigger.sgml
+++ b/doc/src/sgml/event-trigger.sgml
@@ -433,7 +433,7 @@ $$
 ---
 DECLARE
   table_oid oid := pg_event_trigger_table_rewrite_oid();
-  current_hour integer := extract('hour' from current_time);
+  current_hour integer := extract('hour' FROM current_time);
   pages integer;
   max_pages integer := 100;
 BEGIN
diff --git a/doc/src/sgml/func/func-binarystring.sgml b/doc/src/sgml/func/func-binarystring.sgml
index dd7037811af..446b54010b5 100644
--- a/doc/src/sgml/func/func-binarystring.sgml
+++ b/doc/src/sgml/func/func-binarystring.sgml
@@ -856,8 +856,8 @@
    significant byte first. Some examples:
 <programlisting>
 1234::smallint::bytea          <lineannotation>\x04d2</lineannotation>
-cast(1234 as bytea)            <lineannotation>\x000004d2</lineannotation>
-cast(-1234 as bytea)           <lineannotation>\xfffffb2e</lineannotation>
+cast(1234 AS bytea)            <lineannotation>\x000004d2</lineannotation>
+cast(-1234 AS bytea)           <lineannotation>\xfffffb2e</lineannotation>
 '\x8000'::bytea::smallint      <lineannotation>-32768</lineannotation>
 '\x8000'::bytea::integer       <lineannotation>32768</lineannotation>
 </programlisting>
diff --git a/doc/src/sgml/func/func-matching.sgml b/doc/src/sgml/func/func-matching.sgml
index ebe0b22c8f6..91a0b7ca0de 100644
--- a/doc/src/sgml/func/func-matching.sgml
+++ b/doc/src/sgml/func/func-matching.sgml
@@ -412,8 +412,8 @@ substring(<replaceable>string</replaceable>, <replaceable>pattern</replaceable>,
    <para>
     Some examples, with <literal>#&quot;</literal> delimiting the return string:
 <programlisting>
-substring('foobar' similar '%#"o_b#"%' escape '#')   <lineannotation>oob</lineannotation>
-substring('foobar' similar '#"o_b#"%' escape '#')    <lineannotation>NULL</lineannotation>
+substring('foobar' SIMILAR '%#"o_b#"%' ESCAPE '#')   <lineannotation>oob</lineannotation>
+substring('foobar' SIMILAR '#"o_b#"%' ESCAPE '#')    <lineannotation>NULL</lineannotation>
 </programlisting>
    </para>
   </sect2>
@@ -600,8 +600,8 @@ substring('foobar' similar '#"o_b#"%' escape '#')    <lineannotation>NULL</linea
    <para>
     Some examples:
 <programlisting>
-substring('foobar' from 'o.b')     <lineannotation>oob</lineannotation>
-substring('foobar' from 'o(.)b')   <lineannotation>o</lineannotation>
+substring('foobar' FROM 'o.b')     <lineannotation>oob</lineannotation>
+substring('foobar' FROM 'o(.)b')   <lineannotation>o</lineannotation>
 </programlisting>
    </para>
 
diff --git a/doc/src/sgml/func/func-srf.sgml b/doc/src/sgml/func/func-srf.sgml
index eafc961c9f9..34a45971aad 100644
--- a/doc/src/sgml/func/func-srf.sgml
+++ b/doc/src/sgml/func/func-srf.sgml
@@ -247,8 +247,8 @@ FROM (SELECT generate_subscripts(a, 1) AS s, a FROM arrays) foo;
 -- unnest a 2D array:
 CREATE OR REPLACE FUNCTION unnest2(anyarray)
 RETURNS SETOF anyelement AS $$
-select $1[i][j]
-   from generate_subscripts($1,1) g1(i),
+SELECT $1[i][j]
+   FROM generate_subscripts($1,1) g1(i),
         generate_subscripts($1,2) g2(j);
 $$ LANGUAGE sql IMMUTABLE;
 CREATE FUNCTION
diff --git a/doc/src/sgml/hstore.sgml b/doc/src/sgml/hstore.sgml
index 44325e0bba0..fb71bb2e30f 100644
--- a/doc/src/sgml/hstore.sgml
+++ b/doc/src/sgml/hstore.sgml
@@ -799,7 +799,7 @@ UPDATE tab SET h = h || hstore('c', '3');
    If multiple keys are to be added or changed in one operation,
    the concatenation approach is more efficient than subscripting:
 <programlisting>
-UPDATE tab SET h = h || hstore(array['q', 'w'], array['11', '12']);
+UPDATE tab SET h = h || hstore(ARRAY['q', 'w'], ARRAY['11', '12']);
 </programlisting>
   </para>
 
diff --git a/doc/src/sgml/indices.sgml b/doc/src/sgml/indices.sgml
index 9c4f76abf0d..6469f032f23 100644
--- a/doc/src/sgml/indices.sgml
+++ b/doc/src/sgml/indices.sgml
@@ -949,19 +949,19 @@ WHERE url = '/index.html' AND client_ip = inet '192.168.100.23';
     command to create the index would look like this:
 <programlisting>
 CREATE INDEX orders_unbilled_index ON orders (order_nr)
-    WHERE billed is not true;
+    WHERE billed IS NOT TRUE;
 </programlisting>
    </para>
 
    <para>
     A possible query to use this index would be:
 <programlisting>
-SELECT * FROM orders WHERE billed is not true AND order_nr &lt; 10000;
+SELECT * FROM orders WHERE billed IS NOT TRUE AND order_nr &lt; 10000;
 </programlisting>
     However, the index can also be used in queries that do not involve
     <structfield>order_nr</structfield> at all, e.g.:
 <programlisting>
-SELECT * FROM orders WHERE billed is not true AND amount &gt; 5000.00;
+SELECT * FROM orders WHERE billed IS NOT TRUE AND amount &gt; 5000.00;
 </programlisting>
     This is not as efficient as a partial index on the
     <structfield>amount</structfield> column would be, since the system has to
diff --git a/doc/src/sgml/logical-replication.sgml b/doc/src/sgml/logical-replication.sgml
index b01f5e998b2..25b27b24cee 100644
--- a/doc/src/sgml/logical-replication.sgml
+++ b/doc/src/sgml/logical-replication.sgml
@@ -365,17 +365,17 @@
     <para>
      Create some test tables on the publisher.
 <programlisting>
-/* pub # */ CREATE TABLE t1(a int, b text, PRIMARY KEY(a));
-/* pub # */ CREATE TABLE t2(c int, d text, PRIMARY KEY(c));
-/* pub # */ CREATE TABLE t3(e int, f text, PRIMARY KEY(e));
+/* pub # */ CREATE TABLE t1 (a int, b text, PRIMARY KEY (a));
+/* pub # */ CREATE TABLE t2 (c int, d text, PRIMARY KEY (c));
+/* pub # */ CREATE TABLE t3 (e int, f text, PRIMARY KEY (e));
 </programlisting></para>
 
     <para>
      Create the same tables on the subscriber.
 <programlisting>
-/* sub # */ CREATE TABLE t1(a int, b text, PRIMARY KEY(a));
-/* sub # */ CREATE TABLE t2(c int, d text, PRIMARY KEY(c));
-/* sub # */ CREATE TABLE t3(e int, f text, PRIMARY KEY(e));
+/* sub # */ CREATE TABLE t1 (a int, b text, PRIMARY KEY (a));
+/* sub # */ CREATE TABLE t2 (c int, d text, PRIMARY KEY (c));
+/* sub # */ CREATE TABLE t3 (e int, f text, PRIMARY KEY (e));
 </programlisting></para>
 
     <para>
@@ -1028,9 +1028,9 @@ HINT:  To initiate replication, you must manually create the replication slot, e
    <para>
     Create some tables to be used in the following examples.
 <programlisting>
-/* pub # */ CREATE TABLE t1(a int, b int, c text, PRIMARY KEY(a,c));
-/* pub # */ CREATE TABLE t2(d int, e int, f int, PRIMARY KEY(d));
-/* pub # */ CREATE TABLE t3(g int, h int, i int, PRIMARY KEY(g));
+/* pub # */ CREATE TABLE t1 (a int, b int, c text, PRIMARY KEY (a,c));
+/* pub # */ CREATE TABLE t2 (d int, e int, f int, PRIMARY KEY (d));
+/* pub # */ CREATE TABLE t3 (g int, h int, i int, PRIMARY KEY (g));
 </programlisting></para>
 
    <para>
@@ -1125,7 +1125,7 @@ Publications:
     definition as the one on the publisher, and also create the subscription
     <literal>s1</literal> that subscribes to the publication <literal>p1</literal>.
 <programlisting>
-/* sub # */ CREATE TABLE t1(a int, b int, c text, PRIMARY KEY(a,c));
+/* sub # */ CREATE TABLE t1 (a int, b int, c text, PRIMARY KEY (a,c));
 /* sub # */ CREATE SUBSCRIPTION s1
 /* sub - */ CONNECTION 'host=localhost dbname=test_pub application_name=s1'
 /* sub - */ PUBLICATION p1;
@@ -1269,12 +1269,12 @@ Publications:
    <para>
     Create a partitioned table on the publisher.
 <programlisting>
-/* pub # */ CREATE TABLE parent(a int PRIMARY KEY) PARTITION BY RANGE(a);
+/* pub # */ CREATE TABLE parent (a int PRIMARY KEY) PARTITION BY RANGE (a);
 /* pub # */ CREATE TABLE child PARTITION OF parent DEFAULT;
 </programlisting>
    Create the same tables on the subscriber.
 <programlisting>
-/* sub # */ CREATE TABLE parent(a int PRIMARY KEY) PARTITION BY RANGE(a);
+/* sub # */ CREATE TABLE parent (a int PRIMARY KEY) PARTITION BY RANGE (a);
 /* sub # */ CREATE TABLE child PARTITION OF parent DEFAULT;
 </programlisting></para>
 
@@ -1476,7 +1476,7 @@ Publications:
    <para>
     Create a table <literal>t1</literal> to be used in the following example.
 <programlisting>
-/* pub # */ CREATE TABLE t1(id int, a text, b text, c text, d text, e text, PRIMARY KEY(id));
+/* pub # */ CREATE TABLE t1 (id int, a text, b text, c text, d text, e text, PRIMARY KEY (id));
 </programlisting></para>
 
    <para>
@@ -1528,7 +1528,7 @@ Publications:
      <literal>s1</literal> that subscribes to the publication
      <literal>p1</literal>.
 <programlisting>
-/* sub # */ CREATE TABLE t1(id int, b text, a text, d text, PRIMARY KEY(id));
+/* sub # */ CREATE TABLE t1 (id int, b text, a text, d text, PRIMARY KEY (id));
 /* sub # */ CREATE SUBSCRIPTION s1
 /* sub - */ CONNECTION 'host=localhost dbname=test_pub application_name=s1'
 /* sub - */ PUBLICATION p1;
@@ -1537,9 +1537,9 @@ Publications:
     <para>
      On the publisher node, insert some rows to table <literal>t1</literal>.
 <programlisting>
-/* pub # */ INSERT INTO t1 VALUES(1, 'a-1', 'b-1', 'c-1', 'd-1', 'e-1');
-/* pub # */ INSERT INTO t1 VALUES(2, 'a-2', 'b-2', 'c-2', 'd-2', 'e-2');
-/* pub # */ INSERT INTO t1 VALUES(3, 'a-3', 'b-3', 'c-3', 'd-3', 'e-3');
+/* pub # */ INSERT INTO t1 VALUES (1, 'a-1', 'b-1', 'c-1', 'd-1', 'e-1');
+/* pub # */ INSERT INTO t1 VALUES (2, 'a-2', 'b-2', 'c-2', 'd-2', 'e-2');
+/* pub # */ INSERT INTO t1 VALUES (3, 'a-3', 'b-3', 'c-3', 'd-3', 'e-3');
 /* pub # */ SELECT * FROM t1 ORDER BY id;
  id |  a  |  b  |  c  |  d  |  e
 ----+-----+-----+-----+-----+-----
@@ -1594,7 +1594,7 @@ Publications:
 
 /* sub # */ CREATE TABLE tab_gen_to_gen (a int, b int GENERATED ALWAYS AS (a * 100) STORED);
 /* sub # */ CREATE SUBSCRIPTION sub1 CONNECTION 'dbname=test_pub' PUBLICATION pub1;
-/* sub # */ SELECT * from tab_gen_to_gen;
+/* sub # */ SELECT * FROM tab_gen_to_gen;
  a | b
 ---+----
  1 | 100
diff --git a/doc/src/sgml/logicaldecoding.sgml b/doc/src/sgml/logicaldecoding.sgml
index b803a819cf1..2a327ac0b92 100644
--- a/doc/src/sgml/logicaldecoding.sgml
+++ b/doc/src/sgml/logicaldecoding.sgml
@@ -73,7 +73,7 @@ postgres=# SELECT * FROM pg_logical_slot_get_changes('regression_slot', NULL, NU
 -----+-----+------
 (0 rows)
 
-postgres=# CREATE TABLE data(id serial primary key, data text);
+postgres=# CREATE TABLE data (id serial PRIMARY KEY, data text);
 CREATE TABLE
 
 postgres=# -- DDL isn't replicated, so all you'll see is the transaction
@@ -92,8 +92,8 @@ postgres=# SELECT * FROM pg_logical_slot_get_changes('regression_slot', NULL, NU
 (0 rows)
 
 postgres=# BEGIN;
-postgres=*# INSERT INTO data(data) VALUES('1');
-postgres=*# INSERT INTO data(data) VALUES('2');
+postgres=*# INSERT INTO data (data) VALUES ('1');
+postgres=*# INSERT INTO data (data) VALUES ('2');
 postgres=*# COMMIT;
 
 postgres=# SELECT * FROM pg_logical_slot_get_changes('regression_slot', NULL, NULL);
@@ -105,7 +105,7 @@ postgres=# SELECT * FROM pg_logical_slot_get_changes('regression_slot', NULL, NU
  0/0BA5A8A8 | 10298 | COMMIT 10298
 (4 rows)
 
-postgres=# INSERT INTO data(data) VALUES('3');
+postgres=# INSERT INTO data (data) VALUES ('3');
 
 postgres=# -- You can also peek ahead in the change stream without consuming changes
 postgres=# SELECT * FROM pg_logical_slot_peek_changes('regression_slot', NULL, NULL);
@@ -160,7 +160,7 @@ Example 1:
 $ pg_recvlogical -d postgres --slot=test --create-slot
 $ pg_recvlogical -d postgres --slot=test --start -f -
 <keycombo action="simul"><keycap>Control</keycap><keycap>Z</keycap></keycombo>
-$ psql -d postgres -c "INSERT INTO data(data) VALUES('4');"
+$ psql -d postgres -c "INSERT INTO data (data) VALUES ('4');"
 $ fg
 BEGIN 693
 table public.data: INSERT: id[integer]:4 data[text]:'4'
@@ -172,7 +172,7 @@ Example 2:
 $ pg_recvlogical -d postgres --slot=test --create-slot --enable-two-phase
 $ pg_recvlogical -d postgres --slot=test --start -f -
 <keycombo action="simul"><keycap>Control</keycap><keycap>Z</keycap></keycombo>
-$ psql -d postgres -c "BEGIN;INSERT INTO data(data) VALUES('5');PREPARE TRANSACTION 'test';"
+$ psql -d postgres -c "BEGIN; INSERT INTO data (data) VALUES ('5'); PREPARE TRANSACTION 'test';"
 $ fg
 BEGIN 694
 table public.data: INSERT: id[integer]:5 data[text]:'5'
@@ -196,7 +196,7 @@ $ pg_recvlogical -d postgres --slot=test --drop-slot
   </para>
 <programlisting>
 postgres=# BEGIN;
-postgres=*# INSERT INTO data(data) VALUES('5');
+postgres=*# INSERT INTO data (data) VALUES ('5');
 postgres=*# PREPARE TRANSACTION 'test_prepared1';
 
 postgres=# SELECT * FROM pg_logical_slot_get_changes('regression_slot', NULL, NULL);
@@ -208,7 +208,7 @@ postgres=# SELECT * FROM pg_logical_slot_get_changes('regression_slot', NULL, NU
 (3 rows)
 
 postgres=# COMMIT PREPARED 'test_prepared1';
-postgres=# select * from pg_logical_slot_get_changes('regression_slot', NULL, NULL);
+postgres=# SELECT * from pg_logical_slot_get_changes('regression_slot', NULL, NULL);
     lsn     | xid |                    data
 ------------+-----+--------------------------------------------
  0/0168A060 | 529 | COMMIT PREPARED 'test_prepared1', txid 529
@@ -216,9 +216,9 @@ postgres=# select * from pg_logical_slot_get_changes('regression_slot', NULL, NU
 
 postgres=#-- you can also rollback a prepared transaction
 postgres=# BEGIN;
-postgres=*# INSERT INTO data(data) VALUES('6');
+postgres=*# INSERT INTO data (data) VALUES ('6');
 postgres=*# PREPARE TRANSACTION 'test_prepared2';
-postgres=# select * from pg_logical_slot_get_changes('regression_slot', NULL, NULL);
+postgres=# SELECT * from pg_logical_slot_get_changes('regression_slot', NULL, NULL);
     lsn     | xid |                          data
 ------------+-----+---------------------------------------------------------
  0/0168A180 | 530 | BEGIN 530
@@ -227,7 +227,7 @@ postgres=# select * from pg_logical_slot_get_changes('regression_slot', NULL, NU
 (3 rows)
 
 postgres=# ROLLBACK PREPARED 'test_prepared2';
-postgres=# select * from pg_logical_slot_get_changes('regression_slot', NULL, NULL);
+postgres=# SELECT * from pg_logical_slot_get_changes('regression_slot', NULL, NULL);
     lsn     | xid |                     data
 ------------+-----+----------------------------------------------
  0/0168A4B8 | 530 | ROLLBACK PREPARED 'test_prepared2', txid 530
@@ -830,7 +830,7 @@ typedef void (*LogicalOutputPluginInit) (struct OutputPluginCallbacks *cb);
      provided catalog tables using
 <programlisting>
 ALTER TABLE user_catalog_table SET (user_catalog_table = true);
-CREATE TABLE another_catalog_table(data text) WITH (user_catalog_table = true);
+CREATE TABLE another_catalog_table (data text) WITH (user_catalog_table = true);
 </programlisting>
      Note that access to user catalog tables or regular system catalog tables
      in the output plugins has to be done via the <literal>systable_*</literal>
diff --git a/doc/src/sgml/maintenance.sgml b/doc/src/sgml/maintenance.sgml
index dc59c88319e..120bac8875f 100644
--- a/doc/src/sgml/maintenance.sgml
+++ b/doc/src/sgml/maintenance.sgml
@@ -614,8 +614,8 @@
     examine this information is to execute queries such as:
 
 <programlisting>
-SELECT c.oid::regclass as table_name,
-       greatest(age(c.relfrozenxid),age(t.relfrozenxid)) as age
+SELECT c.oid::regclass AS table_name,
+       greatest(age(c.relfrozenxid), age(t.relfrozenxid)) AS age
 FROM pg_class c
 LEFT JOIN pg_class t ON c.reltoastrelid = t.oid
 WHERE c.relkind IN ('r', 'm');
diff --git a/doc/src/sgml/manage-ag.sgml b/doc/src/sgml/manage-ag.sgml
index fe4cb4410cd..bb9efb97ceb 100644
--- a/doc/src/sgml/manage-ag.sgml
+++ b/doc/src/sgml/manage-ag.sgml
@@ -464,7 +464,7 @@ CREATE TABLESPACE fastspace LOCATION '/ssd1/postgresql/data';
    parameter to the relevant command. For example, the following creates
    a table in the tablespace <literal>space1</literal>:
 <programlisting>
-CREATE TABLE foo(i int) TABLESPACE space1;
+CREATE TABLE foo (i int) TABLESPACE space1;
 </programlisting>
   </para>
 
@@ -472,7 +472,7 @@ CREATE TABLE foo(i int) TABLESPACE space1;
    Alternatively, use the <xref linkend="guc-default-tablespace"/> parameter:
 <programlisting>
 SET default_tablespace = space1;
-CREATE TABLE foo(i int);
+CREATE TABLE foo (i int);
 </programlisting>
    When <varname>default_tablespace</varname> is set to anything but an empty
    string, it supplies an implicit <literal>TABLESPACE</literal> clause for
diff --git a/doc/src/sgml/monitoring.sgml b/doc/src/sgml/monitoring.sgml
index f3bf527d5b4..fc64df43e3f 100644
--- a/doc/src/sgml/monitoring.sgml
+++ b/doc/src/sgml/monitoring.sgml
@@ -1137,7 +1137,7 @@ postgres   27093  0.0  0.0  30096  2752 ?        Ss   11:34   0:00 postgres: ser
      Here are examples of how wait events can be viewed:
 
 <programlisting>
-SELECT pid, wait_event_type, wait_event FROM pg_stat_activity WHERE wait_event is NOT NULL;
+SELECT pid, wait_event_type, wait_event FROM pg_stat_activity WHERE wait_event IS NOT NULL;
  pid  | wait_event_type | wait_event
 ------+-----------------+------------
  2540 | Lock            | relation
@@ -1150,7 +1150,7 @@ SELECT a.pid, a.wait_event, w.description
   FROM pg_stat_activity a JOIN
        pg_wait_events w ON (a.wait_event_type = w.type AND
                             a.wait_event = w.name)
-  WHERE a.wait_event is NOT NULL and a.state = 'active';
+  WHERE a.wait_event IS NOT NULL AND a.state = 'active';
 -[ RECORD 1 ]------------------------------------------------------&zwsp;------------
 pid         | 686674
 wait_event  | WALInitSync
diff --git a/doc/src/sgml/pgcrypto.sgml b/doc/src/sgml/pgcrypto.sgml
index bc5c74ad017..6fc2069ad3e 100644
--- a/doc/src/sgml/pgcrypto.sgml
+++ b/doc/src/sgml/pgcrypto.sgml
@@ -57,7 +57,7 @@ digest(data bytea, type text) returns bytea
     If you want the digest as a hexadecimal string, use
     <function>encode()</function> on the result.  For example:
 <programlisting>
-CREATE OR REPLACE FUNCTION sha1(bytea) returns text AS $$
+CREATE OR REPLACE FUNCTION sha1(bytea) RETURNS text AS $$
     SELECT encode(digest($1, 'sha1'), 'hex')
 $$ LANGUAGE SQL STRICT IMMUTABLE;
 </programlisting>
diff --git a/doc/src/sgml/pgstattuple.sgml b/doc/src/sgml/pgstattuple.sgml
index c747a5818ab..54d8f90245e 100644
--- a/doc/src/sgml/pgstattuple.sgml
+++ b/doc/src/sgml/pgstattuple.sgml
@@ -377,7 +377,7 @@ pending_tuples | 0
       <function>pgstathashindex</function> returns a record showing information
       about a HASH index.  For example:
 <programlisting>
-test=&gt; select * from pgstathashindex('con_hash_index');
+test=&gt; SELECT * FROM pgstathashindex('con_hash_index');
 -[ RECORD 1 ]--+-----------------
 version        | 4
 bucket_pages   | 33081
diff --git a/doc/src/sgml/pgsurgery.sgml b/doc/src/sgml/pgsurgery.sgml
index 29bccd7f36d..68186122a22 100644
--- a/doc/src/sgml/pgsurgery.sgml
+++ b/doc/src/sgml/pgsurgery.sgml
@@ -34,17 +34,17 @@
       intended use of this function is to forcibly remove tuples that are not
       otherwise accessible. For example:
 <programlisting>
-test=&gt; select * from t1 where ctid = '(0, 1)';
+test=&gt; SELECT * FROM t1 WHERE ctid = '(0, 1)';
 ERROR:  could not access status of transaction 4007513275
 DETAIL:  Could not open file "pg_xact/0EED": No such file or directory.
 
-test=# select heap_force_kill('t1'::regclass, ARRAY['(0, 1)']::tid[]);
+test=# SELECT heap_force_kill('t1'::regclass, ARRAY['(0, 1)']::tid[]);
  heap_force_kill
 -----------------
 
 (1 row)
 
-test=# select * from t1 where ctid = '(0, 1)';
+test=# SELECT * FROM t1 WHERE ctid = '(0, 1)';
 (0 rows)
 
 </programlisting>
@@ -70,19 +70,19 @@ test=&gt; vacuum t1;
 ERROR:  found xmin 507 from before relfrozenxid 515
 CONTEXT:  while scanning block 0 of relation "public.t1"
 
-test=# select ctid from t1 where xmin = 507;
+test=# SELECT ctid FROM t1 WHERE xmin = 507;
  ctid
 -------
  (0,3)
 (1 row)
 
-test=# select heap_force_freeze('t1'::regclass, ARRAY['(0, 3)']::tid[]);
+test=# SELECT heap_force_freeze('t1'::regclass, ARRAY['(0, 3)']::tid[]);
  heap_force_freeze
 -------------------
 
 (1 row)
 
-test=# select ctid from t1 where xmin = 2;
+test=# SELECT ctid FROM t1 WHERE xmin = 2;
  ctid
 -------
  (0,3)
diff --git a/doc/src/sgml/planstats.sgml b/doc/src/sgml/planstats.sgml
index 068b804a18d..e57867ba617 100644
--- a/doc/src/sgml/planstats.sgml
+++ b/doc/src/sgml/planstats.sgml
@@ -635,7 +635,7 @@ EXPLAIN (ANALYZE, TIMING OFF, BUFFERS OFF) SELECT * FROM t WHERE a = 1 AND b = 1
     <function>pg_mcv_list_items</function> set-returning function.
 
 <programlisting>
-SELECT m.* FROM pg_statistic_ext join pg_statistic_ext_data on (oid = stxoid),
+SELECT m.* FROM pg_statistic_ext JOIN pg_statistic_ext_data ON (oid = stxoid),
                 pg_mcv_list_items(stxdmcv) m WHERE stxname = 'stts2';
  index |  values  | nulls | frequency | base_frequency
 -------+----------+-------+-----------+----------------
diff --git a/doc/src/sgml/plperl.sgml b/doc/src/sgml/plperl.sgml
index 8007261d022..84753f3375d 100644
--- a/doc/src/sgml/plperl.sgml
+++ b/doc/src/sgml/plperl.sgml
@@ -229,7 +229,7 @@ $$ LANGUAGE plperl;
    references to Perl arrays.  Here is an example:
 
 <programlisting>
-CREATE OR REPLACE function returns_array()
+CREATE OR REPLACE FUNCTION returns_array()
 RETURNS text[][] AS $$
     return [['a&quot;b','c,d'],['e\\f','g']];
 $$ LANGUAGE plperl;
@@ -588,7 +588,7 @@ CREATE OR REPLACE FUNCTION lotsa_md5 (INTEGER) RETURNS SETOF foo_type AS $$
     return;
 $$ LANGUAGE plperlu;
 
-SELECT * from lotsa_md5(500);
+SELECT * FROM lotsa_md5(500);
 </programlisting>
     </para>
 
diff --git a/doc/src/sgml/plpgsql.sgml b/doc/src/sgml/plpgsql.sgml
index e937491e6b8..688e15fc72f 100644
--- a/doc/src/sgml/plpgsql.sgml
+++ b/doc/src/sgml/plpgsql.sgml
@@ -1023,7 +1023,7 @@ IF count(*) &gt; 0 FROM my_table THEN ...
 tax := subtotal * 0.06;
 my_record.user_id := 20;
 my_array[j] := 20;
-my_array[1:3] := array[1,2,3];
+my_array[1:3] := ARRAY[1,2,3];
 complex_array[n].realpart = 12.3;
 </programlisting>
     </para>
@@ -1037,8 +1037,8 @@ complex_array[n].realpart = 12.3;
      within a <application>PL/pgSQL</application> function just by writing
      the command.  For example, you could create and fill a table by writing
 <programlisting>
-CREATE TABLE mytable (id int primary key, data text);
-INSERT INTO mytable VALUES (1,'one'), (2,'two');
+CREATE TABLE mytable (id int PRIMARY KEY, data text);
+INSERT INTO mytable VALUES (1, 'one'), (2, 'two');
 </programlisting>
     </para>
 
@@ -2861,7 +2861,7 @@ WHEN SQLSTATE '22012' THEN ...
      As an example, consider this fragment:
 
 <programlisting>
-INSERT INTO mytab(firstname, lastname) VALUES('Tom', 'Jones');
+INSERT INTO mytab(firstname, lastname) VALUES ('Tom', 'Jones');
 BEGIN
     UPDATE mytab SET firstname = 'Joe' WHERE lastname = 'Jones';
     x := x + 1;
@@ -2905,7 +2905,7 @@ END;
 <programlisting>
 CREATE TABLE db (a INT PRIMARY KEY, b TEXT);
 
-CREATE FUNCTION merge_db(key INT, data TEXT) RETURNS VOID AS
+CREATE FUNCTION merge_db(key INT, data TEXT) RETURNS void AS
 $$
 BEGIN
     LOOP
@@ -4466,20 +4466,20 @@ CREATE OR REPLACE FUNCTION update_emp_view() RETURNS TRIGGER AS $$
             IF NOT FOUND THEN RETURN NULL; END IF;
 
             OLD.last_updated = now();
-            INSERT INTO emp_audit VALUES('D', current_user, OLD.*);
+            INSERT INTO emp_audit VALUES ('D', current_user, OLD.*);
             RETURN OLD;
         ELSIF (TG_OP = 'UPDATE') THEN
             UPDATE emp SET salary = NEW.salary WHERE empname = OLD.empname;
             IF NOT FOUND THEN RETURN NULL; END IF;
 
             NEW.last_updated = now();
-            INSERT INTO emp_audit VALUES('U', current_user, NEW.*);
+            INSERT INTO emp_audit VALUES ('U', current_user, NEW.*);
             RETURN NEW;
         ELSIF (TG_OP = 'INSERT') THEN
-            INSERT INTO emp VALUES(NEW.empname, NEW.salary);
+            INSERT INTO emp VALUES (NEW.empname, NEW.salary);
 
             NEW.last_updated = now();
-            INSERT INTO emp_audit VALUES('I', current_user, NEW.*);
+            INSERT INTO emp_audit VALUES ('I', current_user, NEW.*);
             RETURN NEW;
         END IF;
     END;
@@ -4634,10 +4634,10 @@ CREATE TRIGGER maint_sales_summary_bytime
 AFTER INSERT OR UPDATE OR DELETE ON sales_fact
     FOR EACH ROW EXECUTE FUNCTION maint_sales_summary_bytime();
 
-INSERT INTO sales_fact VALUES(1,1,1,10,3,15);
-INSERT INTO sales_fact VALUES(1,2,1,20,5,35);
-INSERT INTO sales_fact VALUES(2,2,1,40,15,135);
-INSERT INTO sales_fact VALUES(2,3,1,10,1,13);
+INSERT INTO sales_fact VALUES (1, 1, 1, 10,  3,  15);
+INSERT INTO sales_fact VALUES (1, 2, 1, 20,  5,  35);
+INSERT INTO sales_fact VALUES (2, 2, 1, 40, 15, 135);
+INSERT INTO sales_fact VALUES (2, 3, 1, 10,  1,  13);
 SELECT * FROM sales_summary_bytime;
 DELETE FROM sales_fact WHERE product_key = 1;
 SELECT * FROM sales_summary_bytime;
@@ -5226,12 +5226,12 @@ CREATE FUNCTION foo() RETURNS integer AS '
       For string literals inside the function body, for example:
 <programlisting>
 a_output := ''Blah'';
-SELECT * FROM users WHERE f_name=''foobar'';
+SELECT * FROM users WHERE f_name = ''foobar'';
 </programlisting>
       In the dollar-quoting approach, you'd just write:
 <programlisting>
 a_output := 'Blah';
-SELECT * FROM users WHERE f_name='foobar';
+SELECT * FROM users WHERE f_name = 'foobar';
 </programlisting>
       which is exactly what the <application>PL/pgSQL</application> parser would see
       in either case.
@@ -5294,24 +5294,24 @@ a_output := a_output || $$ AND name LIKE 'foobar'$$
       <xref linkend="plpgsql-porting-ex2"/>.
       For example:
 <programlisting>
-a_output := a_output || '' if v_'' ||
-    referrer_keys.kind || '' like ''''''''''
+a_output := a_output || '' IF v_'' ||
+    referrer_keys.kind || '' LIKE ''''''''''
     || referrer_keys.key_string || ''''''''''
-    then return ''''''  || referrer_keys.referrer_type
-    || ''''''; end if;'';
+    THEN RETURN '''''' || referrer_keys.referrer_type
+    || ''''''; END IF;'';
 </programlisting>
       The value of <literal>a_output</literal> would then be:
 <programlisting>
-if v_... like ''...'' then return ''...''; end if;
+IF v_... LIKE ''...'' THEN RETURN ''...''; END IF;
 </programlisting>
      </para>
      <para>
       In the dollar-quoting approach, this becomes:
 <programlisting>
-a_output := a_output || $$ if v_$$ || referrer_keys.kind || $$ like '$$
+a_output := a_output || $$ IF v_$$ || referrer_keys.kind || $$ LIKE '$$
     || referrer_keys.key_string || $$'
-    then return '$$  || referrer_keys.referrer_type
-    || $$'; end if;$$;
+    THEN RETURN '$$ || referrer_keys.referrer_type
+    || $$'; END IF;$$;
 </programlisting>
       where we assume we only need to put single quote marks into
       <literal>a_output</literal>, because it will be re-quoted before use.
diff --git a/doc/src/sgml/plpython.sgml b/doc/src/sgml/plpython.sgml
index 27c4467ba7d..16b4e41af18 100644
--- a/doc/src/sgml/plpython.sgml
+++ b/doc/src/sgml/plpython.sgml
@@ -1130,7 +1130,7 @@ $$ LANGUAGE plpython3u;
 <programlisting>
 CREATE FUNCTION try_adding_joe() RETURNS text AS $$
     try:
-        plpy.execute("INSERT INTO users(username) VALUES ('joe')")
+        plpy.execute("INSERT INTO users (username) VALUES ('joe')")
     except plpy.SPIError:
         return "something went wrong"
     else:
diff --git a/doc/src/sgml/pltcl.sgml b/doc/src/sgml/pltcl.sgml
index 5a8e4c9d37e..9fd008a99d7 100644
--- a/doc/src/sgml/pltcl.sgml
+++ b/doc/src/sgml/pltcl.sgml
@@ -180,7 +180,7 @@ $$ LANGUAGE pltcl;
      column names.  Here is an example:
 
 <programlisting>
-CREATE FUNCTION square_cube(in int, out squared int, out cubed int) AS $$
+CREATE FUNCTION square_cube(IN int, OUT squared int, OUT cubed int) AS $$
     return [list squared [expr {$1 * $1}] cubed [expr {$1 * $1 * $1}]]
 $$ LANGUAGE pltcl;
 </programlisting>
diff --git a/doc/src/sgml/queries.sgml b/doc/src/sgml/queries.sgml
index 2736868fb06..3adc5c6557f 100644
--- a/doc/src/sgml/queries.sgml
+++ b/doc/src/sgml/queries.sgml
@@ -2232,7 +2232,7 @@ WITH RECURSIVE included_parts(sub_part, part, quantity) AS (
     FROM included_parts pr, parts p
     WHERE p.part = pr.sub_part
 )
-SELECT sub_part, SUM(quantity) as total_quantity
+SELECT sub_part, sum(quantity) AS total_quantity
 FROM included_parts
 GROUP BY sub_part
 </programlisting>
@@ -2603,7 +2603,7 @@ WHERE w2.key = 123;
    undesirable is
 <programlisting>
 WITH w AS (
-    SELECT key, very_expensive_function(val) as f FROM some_table
+    SELECT key, very_expensive_function(val) AS f FROM some_table
 )
 SELECT * FROM w AS w1 JOIN w AS w2 ON w1.f = w2.f;
 </programlisting>
diff --git a/doc/src/sgml/ref/alter_table.sgml b/doc/src/sgml/ref/alter_table.sgml
index bea9f90138b..9d23ad5a0fb 100644
--- a/doc/src/sgml/ref/alter_table.sgml
+++ b/doc/src/sgml/ref/alter_table.sgml
@@ -1642,7 +1642,7 @@ ALTER TABLE measurements
 <programlisting>
 ALTER TABLE transactions
   ADD COLUMN status varchar(30) DEFAULT 'old',
-  ALTER COLUMN status SET default 'current';
+  ALTER COLUMN status SET DEFAULT 'current';
 </programlisting>
    Existing rows will be filled with <literal>old</literal>, but then
    the default for subsequent commands will be <literal>current</literal>.
diff --git a/doc/src/sgml/ref/alter_view.sgml b/doc/src/sgml/ref/alter_view.sgml
index afbb3d02c7b..7c67c708308 100644
--- a/doc/src/sgml/ref/alter_view.sgml
+++ b/doc/src/sgml/ref/alter_view.sgml
@@ -205,8 +205,8 @@ ALTER VIEW foo RENAME TO bar;
 CREATE TABLE base_table (id int, ts timestamptz);
 CREATE VIEW a_view AS SELECT * FROM base_table;
 ALTER VIEW a_view ALTER COLUMN ts SET DEFAULT now();
-INSERT INTO base_table(id) VALUES(1);  -- ts will receive a NULL
-INSERT INTO a_view(id) VALUES(2);  -- ts will receive the current time
+INSERT INTO base_table (id) VALUES (1);  -- ts will receive a NULL
+INSERT INTO a_view (id) VALUES (2);  -- ts will receive the current time
 </programlisting></para>
  </refsect1>
 
diff --git a/doc/src/sgml/ref/create_function.sgml b/doc/src/sgml/ref/create_function.sgml
index 0d240484cd3..e748e842353 100644
--- a/doc/src/sgml/ref/create_function.sgml
+++ b/doc/src/sgml/ref/create_function.sgml
@@ -649,7 +649,7 @@ END
     parameters.  Thus for example these declarations conflict:
 <programlisting>
 CREATE FUNCTION foo(int) ...
-CREATE FUNCTION foo(int, out text) ...
+CREATE FUNCTION foo(int, OUT text) ...
 </programlisting>
    </para>
 
@@ -709,7 +709,7 @@ CREATE FUNCTION foo(int, int default 42) ...
    Add two integers using an SQL function:
 <programlisting>
 CREATE FUNCTION add(integer, integer) RETURNS integer
-    AS 'select $1 + $2;'
+    AS 'SELECT $1 + $2;'
     LANGUAGE SQL
     IMMUTABLE
     RETURNS NULL ON NULL INPUT;
@@ -740,7 +740,7 @@ $$ LANGUAGE plpgsql;
   <para>
    Return a record containing multiple output parameters:
 <programlisting>
-CREATE FUNCTION dup(in int, out f1 int, out f2 text)
+CREATE FUNCTION dup(IN int, OUT f1 int, OUT f2 text)
     AS $$ SELECT $1, CAST($1 AS text) || ' is text' $$
     LANGUAGE SQL;
 
diff --git a/doc/src/sgml/ref/create_table.sgml b/doc/src/sgml/ref/create_table.sgml
index a157a244e4e..f20d565d06f 100644
--- a/doc/src/sgml/ref/create_table.sgml
+++ b/doc/src/sgml/ref/create_table.sgml
@@ -2088,7 +2088,7 @@ CREATE TABLE films (
     date_prod   date,
     kind        varchar(10),
     len         interval hour to minute,
-    CONSTRAINT production UNIQUE(date_prod)
+    CONSTRAINT production UNIQUE (date_prod)
 );
 </programlisting>
   </para>
@@ -2128,7 +2128,7 @@ CREATE TABLE films (
     date_prod   date,
     kind        varchar(10),
     len         interval hour to minute,
-    CONSTRAINT code_title PRIMARY KEY(code,title)
+    CONSTRAINT code_title PRIMARY KEY (code, title)
 );
 </programlisting>
   </para>
@@ -2143,7 +2143,7 @@ CREATE TABLE films (
 CREATE TABLE distributors (
     did     integer,
     name    varchar(40),
-    PRIMARY KEY(did)
+    PRIMARY KEY (did)
 );
 
 CREATE TABLE distributors (
@@ -2199,7 +2199,7 @@ CREATE TABLE distributors (
 CREATE TABLE distributors (
     did     integer,
     name    varchar(40),
-    UNIQUE(name)
+    UNIQUE (name)
 );
 </programlisting>
   </para>
@@ -2212,7 +2212,7 @@ CREATE TABLE distributors (
 CREATE TABLE distributors (
     did     integer,
     name    varchar(40),
-    UNIQUE(name) WITH (fillfactor=70)
+    UNIQUE (name) WITH (fillfactor=70)
 )
 WITH (fillfactor=70);
 </programlisting>
@@ -2257,7 +2257,7 @@ CREATE TABLE employees OF employee_type (
    Create a range partitioned table:
 <programlisting>
 CREATE TABLE measurement (
-    logdate         date not null,
+    logdate         date NOT NULL,
     peaktemp        int,
     unitsales       int
 ) PARTITION BY RANGE (logdate);
@@ -2267,7 +2267,7 @@ CREATE TABLE measurement (
    Create a range partitioned table with multiple columns in the partition key:
 <programlisting>
 CREATE TABLE measurement_year_month (
-    logdate         date not null,
+    logdate         date NOT NULL,
     peaktemp        int,
     unitsales       int
 ) PARTITION BY RANGE (EXTRACT(YEAR FROM logdate), EXTRACT(MONTH FROM logdate));
@@ -2277,8 +2277,8 @@ CREATE TABLE measurement_year_month (
    Create a list partitioned table:
 <programlisting>
 CREATE TABLE cities (
-    city_id      bigserial not null,
-    name         text not null,
+    city_id      bigserial NOT NULL,
+    name         text NOT NULL,
     population   bigint
 ) PARTITION BY LIST (left(lower(name), 1));
 </programlisting></para>
@@ -2287,8 +2287,8 @@ CREATE TABLE cities (
    Create a hash partitioned table:
 <programlisting>
 CREATE TABLE orders (
-    order_id     bigint not null,
-    cust_id      bigint not null,
+    order_id     bigint NOT NULL,
+    cust_id      bigint NOT NULL,
     status       text
 ) PARTITION BY HASH (order_id);
 </programlisting></para>
diff --git a/doc/src/sgml/ref/pg_rewind.sgml b/doc/src/sgml/ref/pg_rewind.sgml
index 928e78cda33..5b155cfa12a 100644
--- a/doc/src/sgml/ref/pg_rewind.sgml
+++ b/doc/src/sgml/ref/pg_rewind.sgml
@@ -372,10 +372,10 @@ PostgreSQL documentation
    a role, named <literal>rewind_user</literal> here:
 <programlisting>
 CREATE USER rewind_user LOGIN;
-GRANT EXECUTE ON function pg_catalog.pg_ls_dir(text, boolean, boolean) TO rewind_user;
-GRANT EXECUTE ON function pg_catalog.pg_stat_file(text, boolean) TO rewind_user;
-GRANT EXECUTE ON function pg_catalog.pg_read_binary_file(text) TO rewind_user;
-GRANT EXECUTE ON function pg_catalog.pg_read_binary_file(text, bigint, bigint, boolean) TO rewind_user;
+GRANT EXECUTE ON FUNCTION pg_catalog.pg_ls_dir(text, boolean, boolean) TO rewind_user;
+GRANT EXECUTE ON FUNCTION pg_catalog.pg_stat_file(text, boolean) TO rewind_user;
+GRANT EXECUTE ON FUNCTION pg_catalog.pg_read_binary_file(text) TO rewind_user;
+GRANT EXECUTE ON FUNCTION pg_catalog.pg_read_binary_file(text, bigint, bigint, boolean) TO rewind_user;
 </programlisting>
   </para>
 
diff --git a/doc/src/sgml/ref/psql-ref.sgml b/doc/src/sgml/ref/psql-ref.sgml
index 84683f62b1c..0f89ac82094 100644
--- a/doc/src/sgml/ref/psql-ref.sgml
+++ b/doc/src/sgml/ref/psql-ref.sgml
@@ -2531,7 +2531,7 @@ Tue Oct 26 21:40:57 CEST 1999
          statement to be executed.  For example, to create an index on each
          column of <structname>my_table</structname>:
 <programlisting>
-=&gt; <userinput>SELECT format('create index on my_table(%I)', attname)</userinput>
+=&gt; <userinput>SELECT format('CREATE INDEX ON my_table (%I)', attname)</userinput>
 -&gt; <userinput>FROM pg_attribute</userinput>
 -&gt; <userinput>WHERE attrelid = 'my_table'::regclass AND attnum &gt; 0</userinput>
 -&gt; <userinput>ORDER BY attnum</userinput>
@@ -4003,7 +4003,7 @@ SELECT 1 \bind \sendpipeline
         server as soon as it reaches the command-ending semicolon, even if
         more input remains on the current line.  Thus for example entering
 <programlisting>
-select 1; select 2; select 3;
+SELECT 1; SELECT 2; SELECT 3;
 </programlisting>
         will result in the three SQL commands being individually sent to
         the server, with each one's results being displayed before
@@ -4012,7 +4012,7 @@ select 1; select 2; select 3;
         command before it and the one after are effectively combined and
         sent to the server in one request.  So for example
 <programlisting>
-select 1\; select 2\; select 3;
+SELECT 1\; SELECT 2\; SELECT 3;
 </programlisting>
         results in sending the three SQL commands to the server in a single
         request, when the non-backslashed semicolon is reached.
@@ -5561,7 +5561,7 @@ PSQL_EDITOR_LINENUMBER_ARG='--line '
   input. Notice the changing prompt:
 <programlisting>
 testdb=&gt; <userinput>CREATE TABLE my_table (</userinput>
-testdb(&gt; <userinput> first integer not null default 0,</userinput>
+testdb(&gt; <userinput> first integer NOT NULL DEFAULT 0,</userinput>
 testdb(&gt; <userinput> second text)</userinput>
 testdb-&gt; <userinput>;</userinput>
 CREATE TABLE
@@ -5750,8 +5750,8 @@ testdb=&gt; <userinput>\crosstabview first second</userinput>
 This second example shows a multiplication table with rows sorted in reverse
 numerical order and columns with an independent, ascending numerical order.
 <programlisting>
-testdb=&gt; <userinput>SELECT t1.first as "A", t2.first+100 AS "B", t1.first*(t2.first+100) as "AxB",</userinput>
-testdb-&gt; <userinput>row_number() over(order by t2.first) AS ord</userinput>
+testdb=&gt; <userinput>SELECT t1.first AS "A", t2.first+100 AS "B", t1.first*(t2.first+100) AS "AxB",</userinput>
+testdb-&gt; <userinput>row_number() OVER (ORDER BY t2.first) AS ord</userinput>
 testdb-&gt; <userinput>FROM my_table t1 CROSS JOIN my_table t2 ORDER BY 1 DESC</userinput>
 testdb-&gt; <userinput>\crosstabview "A" "B" "AxB" ord</userinput>
  A | 101 | 102 | 103 | 104
diff --git a/doc/src/sgml/ref/select.sgml b/doc/src/sgml/ref/select.sgml
index 5a3bcff7607..fd441ef4487 100644
--- a/doc/src/sgml/ref/select.sgml
+++ b/doc/src/sgml/ref/select.sgml
@@ -1927,7 +1927,7 @@ SELECT * FROM unnest(ARRAY['a','b','c','d','e','f']) WITH ORDINALITY;
 
 <programlisting>
 WITH t AS (
-    SELECT random() as x FROM generate_series(1, 3)
+    SELECT random() AS x FROM generate_series(1, 3)
   )
 SELECT * FROM t
 UNION ALL
diff --git a/doc/src/sgml/ref/values.sgml b/doc/src/sgml/ref/values.sgml
index 4bf7bfdffee..49131dd884b 100644
--- a/doc/src/sgml/ref/values.sgml
+++ b/doc/src/sgml/ref/values.sgml
@@ -190,11 +190,11 @@ INSERT INTO films VALUES
 
 <programlisting>
 SELECT f.*
-  FROM films f, (VALUES('MGM', 'Horror'), ('UA', 'Sci-Fi')) AS t (studio, kind)
+  FROM films f, (VALUES ('MGM', 'Horror'), ('UA', 'Sci-Fi')) AS t (studio, kind)
   WHERE f.studio = t.studio AND f.kind = t.kind;
 
 UPDATE employees SET salary = salary * v.increase
-  FROM (VALUES(1, 200000, 1.2), (2, 400000, 1.4)) AS v (depno, target, increase)
+  FROM (VALUES (1, 200000, 1.2), (2, 400000, 1.4)) AS v (depno, target, increase)
   WHERE employees.depno = v.depno AND employees.sales &gt;= v.target;
 </programlisting>
 
@@ -216,7 +216,7 @@ UPDATE employees SET salary = salary * v.increase
 
 <programlisting>
 SELECT * FROM machines
-WHERE ip_address IN (VALUES('192.168.0.1'::inet), ('192.168.0.10'), ('192.168.1.43'));
+WHERE ip_address IN (VALUES ('192.168.0.1'::inet), ('192.168.0.10'), ('192.168.1.43'));
 </programlisting></para>
 
   <tip>
diff --git a/doc/src/sgml/rules.sgml b/doc/src/sgml/rules.sgml
index 282dcd722d4..50ac9bd4bdb 100644
--- a/doc/src/sgml/rules.sgml
+++ b/doc/src/sgml/rules.sgml
@@ -968,7 +968,7 @@ CREATE MATERIALIZED VIEW sales_summary AS
   SELECT
       seller_no,
       invoice_date,
-      sum(invoice_amt)::numeric(13,2) as sales_amt
+      sum(invoice_amt)::numeric(13,2) AS sales_amt
     FROM invoice
     WHERE invoice_date &lt; CURRENT_DATE
     GROUP BY
diff --git a/doc/src/sgml/syntax.sgml b/doc/src/sgml/syntax.sgml
index 237d7306fe8..3ed61aadff4 100644
--- a/doc/src/sgml/syntax.sgml
+++ b/doc/src/sgml/syntax.sgml
@@ -2331,7 +2331,7 @@ SELECT ARRAY[[1,2],[3,4]];
     an array of the proper kind, not only a sub-<literal>ARRAY</literal> construct.
     For example:
 <programlisting>
-CREATE TABLE arr(f1 int[], f2 int[]);
+CREATE TABLE arr (f1 int[], f2 int[]);
 
 INSERT INTO arr VALUES (ARRAY[[1,2],[3,4]], ARRAY[[5,6],[7,8]]);
 
@@ -2457,7 +2457,7 @@ SELECT ROW(t.f1, t.f2, 42) FROM t;
     created with <command>CREATE TYPE AS</command>.  An explicit cast might be needed
     to avoid ambiguity.  For example:
 <programlisting>
-CREATE TABLE mytable(f1 int, f2 float, f3 text);
+CREATE TABLE mytable (f1 int, f2 float, f3 text);
 
 CREATE FUNCTION getf1(mytable) RETURNS int AS 'SELECT $1.f1' LANGUAGE SQL;
 
diff --git a/doc/src/sgml/tablefunc.sgml b/doc/src/sgml/tablefunc.sgml
index e10fe7009d1..68fc806ce4d 100644
--- a/doc/src/sgml/tablefunc.sgml
+++ b/doc/src/sgml/tablefunc.sgml
@@ -281,22 +281,22 @@ SELECT * FROM crosstab('...') AS ct(row_name text, category_1 text, category_2 t
    <para>
     Here is a complete example:
 <programlisting>
-CREATE TABLE ct(id SERIAL, rowid TEXT, attribute TEXT, value TEXT);
-INSERT INTO ct(rowid, attribute, value) VALUES('test1','att1','val1');
-INSERT INTO ct(rowid, attribute, value) VALUES('test1','att2','val2');
-INSERT INTO ct(rowid, attribute, value) VALUES('test1','att3','val3');
-INSERT INTO ct(rowid, attribute, value) VALUES('test1','att4','val4');
-INSERT INTO ct(rowid, attribute, value) VALUES('test2','att1','val5');
-INSERT INTO ct(rowid, attribute, value) VALUES('test2','att2','val6');
-INSERT INTO ct(rowid, attribute, value) VALUES('test2','att3','val7');
-INSERT INTO ct(rowid, attribute, value) VALUES('test2','att4','val8');
+CREATE TABLE ct (id SERIAL, rowid TEXT, attribute TEXT, value TEXT);
+INSERT INTO ct (rowid, attribute, value) VALUES ('test1', 'att1', 'val1');
+INSERT INTO ct (rowid, attribute, value) VALUES ('test1', 'att2', 'val2');
+INSERT INTO ct (rowid, attribute, value) VALUES ('test1', 'att3', 'val3');
+INSERT INTO ct (rowid, attribute, value) VALUES ('test1', 'att4', 'val4');
+INSERT INTO ct (rowid, attribute, value) VALUES ('test2', 'att1', 'val5');
+INSERT INTO ct (rowid, attribute, value) VALUES ('test2', 'att2', 'val6');
+INSERT INTO ct (rowid, attribute, value) VALUES ('test2', 'att3', 'val7');
+INSERT INTO ct (rowid, attribute, value) VALUES ('test2', 'att4', 'val8');
 
 SELECT *
 FROM crosstab(
-  'select rowid, attribute, value
-   from ct
-   where attribute = ''att2'' or attribute = ''att3''
-   order by 1,2')
+  'SELECT rowid, attribute, value
+   FROM ct
+   WHERE attribute = ''att2'' OR attribute = ''att3''
+   ORDER BY 1,2')
 AS ct(row_name text, category_1 text, category_2 text, category_3 text);
 
  row_name | category_1 | category_2 | category_3
@@ -371,10 +371,10 @@ CREATE TYPE tablefunc_crosstab_N AS (
 <programlisting>
 SELECT *
 FROM crosstab3(
-  'select rowid, attribute, value
-   from ct
-   where attribute = ''att2'' or attribute = ''att3''
-   order by 1,2');
+  'SELECT rowid, attribute, value
+   FROM ct
+   WHERE attribute = ''att2'' OR attribute = ''att3''
+   ORDER BY 1,2');
 </programlisting>
     </para>
 
@@ -407,7 +407,7 @@ CREATE TYPE my_crosstab_float8_5_cols AS (
 );
 
 CREATE OR REPLACE FUNCTION crosstab_float8_5_cols(text)
-    RETURNS setof my_crosstab_float8_5_cols
+    RETURNS SETOF my_crosstab_float8_5_cols
     AS '$libdir/tablefunc','crosstab' LANGUAGE C STABLE STRICT;
 </programlisting>
       </para>
@@ -426,7 +426,7 @@ CREATE OR REPLACE FUNCTION crosstab_float8_5_cols(
     OUT my_category_3 float8,
     OUT my_category_4 float8,
     OUT my_category_5 float8)
-  RETURNS setof record
+  RETURNS SETOF record
   AS '$libdir/tablefunc','crosstab' LANGUAGE C STABLE STRICT;
 </programlisting>
       </para>
@@ -572,18 +572,18 @@ row_name   extra   cat1   cat2   cat3   cat4
    <para>
     Here are two complete examples:
 <programlisting>
-create table sales(year int, month int, qty int);
-insert into sales values(2007, 1, 1000);
-insert into sales values(2007, 2, 1500);
-insert into sales values(2007, 7, 500);
-insert into sales values(2007, 11, 1500);
-insert into sales values(2007, 12, 2000);
-insert into sales values(2008, 1, 1000);
-
-select * from crosstab(
-  'select year, month, qty from sales order by 1',
-  'select m from generate_series(1,12) m'
-) as (
+CREATE TABLE sales (year int, month int, qty int);
+INSERT INTO sales VALUES (2007,  1, 1000);
+INSERT INTO sales VALUES (2007,  2, 1500);
+INSERT INTO sales VALUES (2007,  7,  500);
+INSERT INTO sales VALUES (2007, 11, 1500);
+INSERT INTO sales VALUES (2007, 12, 2000);
+INSERT INTO sales VALUES (2008,  1, 1000);
+
+SELECT * FROM crosstab(
+  'SELECT year, month, qty FROM sales ORDER BY 1',
+  'SELECT m FROM generate_series(1, 12) m'
+) AS (
   year int,
   "Jan" int,
   "Feb" int,
@@ -606,14 +606,14 @@ select * from crosstab(
 </programlisting>
 
 <programlisting>
-CREATE TABLE cth(rowid text, rowdt timestamp, attribute text, val text);
-INSERT INTO cth VALUES('test1','01 March 2003','temperature','42');
-INSERT INTO cth VALUES('test1','01 March 2003','test_result','PASS');
-INSERT INTO cth VALUES('test1','01 March 2003','volts','2.6987');
-INSERT INTO cth VALUES('test2','02 March 2003','temperature','53');
-INSERT INTO cth VALUES('test2','02 March 2003','test_result','FAIL');
-INSERT INTO cth VALUES('test2','02 March 2003','test_startdate','01 March 2003');
-INSERT INTO cth VALUES('test2','02 March 2003','volts','3.1234');
+CREATE TABLE cth (rowid text, rowdt timestamp, attribute text, val text);
+INSERT INTO cth VALUES ('test1', '01 March 2003', 'temperature',    '42');
+INSERT INTO cth VALUES ('test1', '01 March 2003', 'test_result',    'PASS');
+INSERT INTO cth VALUES ('test1', '01 March 2003', 'volts',          '2.6987');
+INSERT INTO cth VALUES ('test2', '02 March 2003', 'temperature',    '53');
+INSERT INTO cth VALUES ('test2', '02 March 2003', 'test_result',    'FAIL');
+INSERT INTO cth VALUES ('test2', '02 March 2003', 'test_startdate', '01 March 2003');
+INSERT INTO cth VALUES ('test2', '02 March 2003', 'volts',          '3.1234');
 
 SELECT * FROM crosstab
 (
@@ -784,17 +784,17 @@ SELECT * FROM connectby('connectby_tree', 'keyid', 'parent_keyid', 'pos', 'row2'
     <para>
      Here is an example:
 <programlisting>
-CREATE TABLE connectby_tree(keyid text, parent_keyid text, pos int);
-
-INSERT INTO connectby_tree VALUES('row1',NULL, 0);
-INSERT INTO connectby_tree VALUES('row2','row1', 0);
-INSERT INTO connectby_tree VALUES('row3','row1', 0);
-INSERT INTO connectby_tree VALUES('row4','row2', 1);
-INSERT INTO connectby_tree VALUES('row5','row2', 0);
-INSERT INTO connectby_tree VALUES('row6','row4', 0);
-INSERT INTO connectby_tree VALUES('row7','row3', 0);
-INSERT INTO connectby_tree VALUES('row8','row6', 0);
-INSERT INTO connectby_tree VALUES('row9','row5', 0);
+CREATE TABLE connectby_tree (keyid text, parent_keyid text, pos int);
+
+INSERT INTO connectby_tree VALUES ('row1', NULL,   0);
+INSERT INTO connectby_tree VALUES ('row2', 'row1', 0);
+INSERT INTO connectby_tree VALUES ('row3', 'row1', 0);
+INSERT INTO connectby_tree VALUES ('row4', 'row2', 1);
+INSERT INTO connectby_tree VALUES ('row5', 'row2', 0);
+INSERT INTO connectby_tree VALUES ('row6', 'row4', 0);
+INSERT INTO connectby_tree VALUES ('row7', 'row3', 0);
+INSERT INTO connectby_tree VALUES ('row8', 'row6', 0);
+INSERT INTO connectby_tree VALUES ('row9', 'row5', 0);
 
 -- with branch, without orderby_fld (order of results is not guaranteed)
 SELECT * FROM connectby('connectby_tree', 'keyid', 'parent_keyid', 'row2', 0, '~')
diff --git a/doc/src/sgml/tcn.sgml b/doc/src/sgml/tcn.sgml
index 32a1025cc6b..98278fbee37 100644
--- a/doc/src/sgml/tcn.sgml
+++ b/doc/src/sgml/tcn.sgml
@@ -43,32 +43,32 @@
   A brief example of using the extension follows.
 
 <programlisting>
-test=# create table tcndata
+test=# CREATE TABLE tcndata
 test-#   (
-test(#     a int not null,
-test(#     b date not null,
+test(#     a int NOT NULL,
+test(#     b date NOT NULL,
 test(#     c text,
-test(#     primary key (a, b)
+test(#     PRIMARY KEY (a, b)
 test(#   );
 CREATE TABLE
-test=# create trigger tcndata_tcn_trigger
-test-#   after insert or update or delete on tcndata
-test-#   for each row execute function triggered_change_notification();
+test=# CREATE TRIGGER tcndata_tcn_trigger
+test-#   AFTER INSERT OR UPDATE OR DELETE ON tcndata
+test-#   FOR EACH ROW EXECUTE FUNCTION triggered_change_notification();
 CREATE TRIGGER
-test=# listen tcn;
+test=# LISTEN tcn;
 LISTEN
-test=# insert into tcndata values (1, date '2012-12-22', 'one'),
+test=# INSERT INTO tcndata VALUES (1, date '2012-12-22', 'one'),
 test-#                            (1, date '2012-12-23', 'another'),
 test-#                            (2, date '2012-12-23', 'two');
 INSERT 0 3
 Asynchronous notification "tcn" with payload ""tcndata",I,"a"='1',"b"='2012-12-22'" received from server process with PID 22770.
 Asynchronous notification "tcn" with payload ""tcndata",I,"a"='1',"b"='2012-12-23'" received from server process with PID 22770.
 Asynchronous notification "tcn" with payload ""tcndata",I,"a"='2',"b"='2012-12-23'" received from server process with PID 22770.
-test=# update tcndata set c = 'uno' where a = 1;
+test=# UPDATE tcndata SET c = 'uno' WHERE a = 1;
 UPDATE 2
 Asynchronous notification "tcn" with payload ""tcndata",U,"a"='1',"b"='2012-12-22'" received from server process with PID 22770.
 Asynchronous notification "tcn" with payload ""tcndata",U,"a"='1',"b"='2012-12-23'" received from server process with PID 22770.
-test=# delete from tcndata where a = 1 and b = date '2012-12-22';
+test=# DELETE FROM tcndata WHERE a = 1 AND b = date '2012-12-22';
 DELETE 1
 Asynchronous notification "tcn" with payload ""tcndata",D,"a"='1',"b"='2012-12-22'" received from server process with PID 22770.
 </programlisting>
diff --git a/doc/src/sgml/textsearch.sgml b/doc/src/sgml/textsearch.sgml
index 89928ed1829..d20484cb232 100644
--- a/doc/src/sgml/textsearch.sgml
+++ b/doc/src/sgml/textsearch.sgml
@@ -1974,12 +1974,12 @@ SELECT title, body FROM messages WHERE tsv @@ to_tsquery('title &amp; body');
 
 <programlisting>
 CREATE FUNCTION messages_trigger() RETURNS trigger AS $$
-begin
+BEGIN
   new.tsv :=
      setweight(to_tsvector('pg_catalog.english', coalesce(new.title,'')), 'A') ||
      setweight(to_tsvector('pg_catalog.english', coalesce(new.body,'')), 'D');
-  return new;
-end
+  RETURN new;
+END
 $$ LANGUAGE plpgsql;
 
 CREATE TRIGGER tsvectorupdate BEFORE INSERT OR UPDATE
-- 
2.51.1

