On Thu, Nov 24, 2022 at 10:44 AM David G. Johnston <
david.g.johns...@gmail.com> wrote:

> On Thu, Nov 24, 2022 at 7:33 AM Kirk Wolak <wol...@gmail.com> wrote:
>
>> On Thu, Nov 24, 2022 at 5:33 AM Laurenz Albe <laurenz.a...@cybertec.at>
>> wrote:
>>
>>> On Thu, 2022-11-24 at 02:41 -0500, Kirk Wolak wrote:
>>> > Alright, as I have the documentation build working, and a slightly
>>> better stylesheet,
>>> > the comments on the last block were not aligned.
>>> > They are fixed now.
>>> >...
>>>
>> I dislike having CREATE SEQUENCE in the table examples.  Keep those
> focused on only the syntax of the call expression.  That requires removing
> the nextval calls too and not showing the error path.  I'd be fine with not
> showing examples of code that would produce an error.  (if we are going to
> show the error path I'd suggest we show the actual error message produced)
>

David, let me see how that looks.  From an approach standpoint, I am
hearing:
1) Keep the example near the definition minimal [just this function]
2) It's okay to create an extra "row" [each function is in a <row>], right
after the last function, with a detailed example, like you put below!
3) It's okay in the example area to introduce a few ideas [I really like
this: RETURNING, etc]
What I LIKE about this... It reminds me of the PHP manual online, where
they have TONS of user posted examples (ours will be more moderated, but
this opens us up to better and better and even alternative examples).

Let me play with this.  I think I want to try a progression of the examples.

I used role="example_code", for the paragraph style, and I think it looks
better de-dented to the same level as the functions.
But I have NO IDEA where that css detail would be stored for make..

#docContent table.table p.func_signature, p.example_code {}

At the bottom of the page I would add an extended example of how these
> sequences can be used in practice.
>
> CREATE TABLE seq_example ( id bigint PRIMARY KEY GENERATED BY DEFAULT AS
> IDENTITY ) -- implicit sequence named seq_example_seq is created (or
> whatever is generated...)
> INSERT INTO seq_example RETURNING id; -- 1
> SELECT currval('seq_example_seq'::regclass); -- 1
> SELECT setval('seq_example_seq', 10);
> INSERT INTO seq_example (id)
>   VALUES (nextval('seq_example_seq')) -- works as-is due to choosing BY
> DEFAULT for the identity
>   RETURNING id; -- 11
> SELECT lastval(); -- 11
>
> I would remove the casting of the sequence name from the table examples
> and just keep one in the main usage example.  I agree that having both to
> make the reader stop and think is a good idea.
>
> David J.
>

I also tested, and cleaned up the results from your example.  Sorry it took
me so long, I am very new.  Laurenz helped me out with:
make STYLE=website

Let me know what you think now...
(and I removed all but the single embedded SQL.   Even when it is trivial,
I would prefer to put one in there.)

Here is a screen shot: (is it preferred to use a link to screencast?)
https://app.screencast.com/hDW9ma2aPsdQy
[image: image.png]
diff --git a/doc/src/sgml/func.sgml b/doc/src/sgml/func.sgml
index 82fba48d5f..bd17d247e2 100644
--- a/doc/src/sgml/func.sgml
+++ b/doc/src/sgml/func.sgml
@@ -17625,6 +17625,11 @@ $.* ? (@ like_regex "^\\d+$")
         command.
       </para>
        <para>
+<programlisting>
+SELECT nextval('myseq'::regclass);    <lineannotation>-- returns 
1</lineannotation>
+</programlisting>
+      </para>
+       <para>
         This function requires <literal>USAGE</literal>
         or <literal>UPDATE</literal> privilege on the sequence.
        </para></entry>
@@ -17657,11 +17662,11 @@ $.* ? (@ like_regex "^\\d+$")
         Furthermore, the value reported by <function>currval</function> is not
         changed in this case.  For example,
 <programlisting>
-SELECT setval('myseq', 42);           <lineannotation>Next 
<function>nextval</function> will return 43</lineannotation>
-SELECT setval('myseq', 42, true);     <lineannotation>Same as 
above</lineannotation>
-SELECT setval('myseq', 42, false);    <lineannotation>Next 
<function>nextval</function> will return 42</lineannotation>
+SELECT setval('myseq', 42);           <lineannotation>-- The next 
<function>nextval</function>('myseq') will return 43</lineannotation>
+SELECT setval('myseq', 42, true);     <lineannotation>-- Same as 
above</lineannotation>
+SELECT setval('myseq', 42, false);    <lineannotation>-- The next 
<function>nextval</function>('myseq') will return 42</lineannotation>
 </programlisting>
-        The result returned by <function>setval</function> is just the value 
of its
+        The result returned by <function>setval</function> is the value of its
         second argument.
        </para>
        <para>
@@ -17686,6 +17691,9 @@ SELECT setval('myseq', 42, false);    
<lineannotation>Next <function>nextval</fu
         returning a session-local value, it gives a predictable answer whether
         or not other sessions have executed <function>nextval</function> since
         the current session did.
+<programlisting>
+SELECT currval('myseq'::regclass);
+</programlisting>
        </para>
        <para>
         This function requires <literal>USAGE</literal>
@@ -17707,15 +17715,36 @@ SELECT setval('myseq', 42, false);    
<lineannotation>Next <function>nextval</fu
         identical to <function>currval</function>, except that instead
         of taking the sequence name as an argument it refers to whichever
         sequence <function>nextval</function> was most recently applied to
-        in the current session. It is an error to call
-        <function>lastval</function> if <function>nextval</function>
-        has not yet been called in the current session.
+        in the current session. (An error is reported if 
<function>nextval</function> has
+        never been called in this session.) 
+<programlisting>
+SELECT lastval();
+</programlisting>
        </para>
        <para>
         This function requires <literal>USAGE</literal>
         or <literal>SELECT</literal> privilege on the last used sequence.
        </para></entry>
       </row>
+      <row>
+       <entry role="func_table_entry"><para role="example_code">
+       Examples</para>
+<programlisting>
+CREATE TABLE seq_example ( id bigint PRIMARY KEY GENERATED BY DEFAULT AS 
IDENTITY );
+<lineannotation>-- implicit sequence named seq_example_id_seq is created (\ds 
in psql will show sequences)</lineannotation>
+
+INSERT INTO seq_example RETURNING id;           <lineannotation>-- 
1</lineannotation>
+SELECT currval('seq_example_id_seq'::regclass); <lineannotation>-- 
1</lineannotation>
+
+SELECT setval('seq_example_id_seq', 10);
+INSERT INTO seq_example (id)
+  VALUES (nextval('seq_example_id_seq'))        <lineannotation>-- works as-is 
due to choosing BY DEFAULT for the identity</lineannotation>
+  RETURNING id;                                 <lineannotation>-- 
11</lineannotation>
+  
+SELECT lastval();                               <lineannotation>-- 
11</lineannotation>
+</programlisting>
+      </entry>
+      </row>
      </tbody>
     </tgroup>
    </table>

Reply via email to