]> git.ipfire.org Git - thirdparty/psycopg.git/commitdiff
fix: confusing named parameters in example query
authorJules Sagot--Gentil <jules.sagot@julhost.xyz>
Sat, 29 Jan 2022 17:25:45 +0000 (18:25 +0100)
committerDaniele Varrazzo <daniele.varrazzo@gmail.com>
Sat, 29 Jan 2022 19:22:47 +0000 (19:22 +0000)
In the named parameters example query, the name of the parameters are
Python built in data types: int and str.

This is confusing because it looks like we are casting values passed
as arguments instead of passing named arguments.

docs/basic/params.rst

index fbd8ff5cb7e312db89c5087b5f8373b148fd493c..5033e9a91d676424e09ff32efc31b099378d977a 100644 (file)
@@ -30,7 +30,7 @@ example the Python function call:
 .. code:: python
 
     cur.execute("""
-        INSERT INTO some_table (an_int, a_date, a_string)
+        INSERT INTO some_table (id, created_at, last_name)
         VALUES (%s, %s, %s);
         """,
         (10, datetime.date(2020, 11, 18), "O'Reilly"))
@@ -39,7 +39,7 @@ is *roughly* equivalent to the SQL command:
 
 .. code-block:: sql
 
-    INSERT INTO some_table (an_int, a_date, a_string)
+    INSERT INTO some_table (id, created_at, last_name)
     VALUES (10, '2020-11-18', 'O''Reilly');
 
 Note that the parameters will not be really merged to the query: query and the
@@ -52,10 +52,10 @@ to specify the values in any order and to repeat the same value in several
 places in the query::
 
     cur.execute("""
-        INSERT INTO some_table (an_int, a_date, another_date, a_string)
-        VALUES (%(int)s, %(date)s, %(date)s, %(str)s);
+        INSERT INTO some_table (id, created_at, updated_at, last_name)
+        VALUES (%(id)s, %(created)s, %(created)s, %(name)s);
         """,
-        {'int': 10, 'str': "O'Reilly", 'date': datetime.date(2020, 11, 18)})
+        {'id': 10, 'name': "O'Reilly", 'created': datetime.date(2020, 11, 18)})
 
 Using characters ``%``, ``(``, ``)`` in the argument names is not supported.