source: trunk/docs/contents/pg/module.rst @ 814

Last change on this file since 814 was 814, checked in by cito, 4 years ago

Add typecasting of dates, times, timestamps, intervals

So far, PyGreSQL has returned these types only as strings (in various
formats depending on the DateStyle? setting) and left it to the user
to parse and interpret the strings. These types are now properly cast
into the corresponding detetime types of Python, and this works with
any setting of DatesStyle?, even if you change DateStyle? in the middle
of a database session.

To implement this, a fast method for getting the datestyle (cached and
without roundtrip to the database) has been added. Also, the typecast
mechanism has been extended so that typecast functions can optionally
also take the connection as argument.

The date and time typecast functions have been implemented in Python
using the new typecast registry and added to both pg and pgdb. Some
duplication of code in the two modules was unavoidable, since we don't
want the modules to be dependent of each other or install additional
helper modules. One day we might want to change this, put everything
in one package and factor out some of the functionality.

File size: 28.2 KB
Line 
1Module functions and constants
2==============================
3
4.. py:currentmodule:: pg
5
6The :mod:`pg` module defines a few functions that allow to connect
7to a database and to define "default variables" that override
8the environment variables used by PostgreSQL.
9
10These "default variables" were designed to allow you to handle general
11connection parameters without heavy code in your programs. You can prompt the
12user for a value, put it in the default variable, and forget it, without
13having to modify your environment. The support for default variables can be
14disabled by setting the ``-DNO_DEF_VAR`` option in the Python setup file.
15Methods relative to this are specified by the tag [DV].
16
17All variables are set to ``None`` at module initialization, specifying that
18standard environment variables should be used.
19
20connect -- Open a PostgreSQL connection
21---------------------------------------
22
23.. function:: connect([dbname], [host], [port], [opt], [user], [passwd])
24
25    Open a :mod:`pg` connection
26
27    :param dbname: name of connected database (*None* = :data:`defbase`)
28    :type str: str or None
29    :param host: name of the server host (*None* = :data:`defhost`)
30    :type host:  str or None
31    :param port: port used by the database server (-1 = :data:`defport`)
32    :type port: int
33    :param opt: connection options (*None* = :data:`defopt`)
34    :type opt: str or None
35    :param user: PostgreSQL user (*None* = :data:`defuser`)
36    :type user: str or None
37    :param passwd: password for user (*None* = :data:`defpasswd`)
38    :type passwd: str or None
39    :returns: If successful, the :class:`Connection` handling the connection
40    :rtype: :class:`Connection`
41    :raises TypeError: bad argument type, or too many arguments
42    :raises SyntaxError: duplicate argument definition
43    :raises pg.InternalError: some error occurred during pg connection definition
44    :raises Exception: (all exceptions relative to object allocation)
45
46This function opens a connection to a specified database on a given
47PostgreSQL server. You can use keywords here, as described in the
48Python tutorial. The names of the keywords are the name of the
49parameters given in the syntax line. For a precise description
50of the parameters, please refer to the PostgreSQL user manual.
51
52Example::
53
54    import pg
55
56    con1 = pg.connect('testdb', 'myhost', 5432, None, None, 'bob', None)
57    con2 = pg.connect(dbname='testdb', host='localhost', user='bob')
58
59get/set_defhost -- default server host [DV]
60-------------------------------------------
61
62.. function:: get_defhost(host)
63
64    Get the default host
65
66    :returns: the current default host specification
67    :rtype: str or None
68    :raises TypeError: too many arguments
69
70This method returns the current default host specification,
71or ``None`` if the environment variables should be used.
72Environment variables won't be looked up.
73
74.. function:: set_defhost(host)
75
76    Set the default host
77
78    :param host: the new default host specification
79    :type host: str or None
80    :returns: the previous default host specification
81    :rtype: str or None
82    :raises TypeError: bad argument type, or too many arguments
83
84This methods sets the default host value for new connections.
85If ``None`` is supplied as parameter, environment variables will
86be used in future connections. It returns the previous setting
87for default host.
88
89get/set_defport -- default server port [DV]
90-------------------------------------------
91
92.. function:: get_defport()
93
94    Get the default port
95
96    :returns: the current default port specification
97    :rtype: int
98    :raises TypeError: too many arguments
99
100This method returns the current default port specification,
101or ``None`` if the environment variables should be used.
102Environment variables won't be looked up.
103
104.. function::  set_defport(port)
105
106    Set the default port
107
108    :param port: the new default port
109    :type port: int
110    :returns: previous default port specification
111    :rtype: int or None
112
113This methods sets the default port value for new connections. If -1 is
114supplied as parameter, environment variables will be used in future
115connections. It returns the previous setting for default port.
116
117get/set_defopt --  default connection options [DV]
118--------------------------------------------------
119
120.. function:: get_defopt()
121
122    Get the default connection options
123
124    :returns: the current default options specification
125    :rtype: str or None
126    :raises TypeError: too many arguments
127
128This method returns the current default connection options specification,
129or ``None`` if the environment variables should be used. Environment variables
130won't be looked up.
131
132.. function:: set_defopt(options)
133
134    Set the default connection options
135
136    :param options: the new default connection options
137    :type options: str or None
138    :returns: previous default options specification
139    :rtype: str or None
140    :raises TypeError: bad argument type, or too many arguments
141
142This methods sets the default connection options value for new connections.
143If ``None`` is supplied as parameter, environment variables will be used in
144future connections. It returns the previous setting for default options.
145
146get/set_defbase -- default database name [DV]
147---------------------------------------------
148
149.. function:: get_defbase()
150
151    Get the default database name
152
153    :returns: the current default database name specification
154    :rtype: str or None
155    :raises TypeError: too many arguments
156
157This method returns the current default database name specification, or
158``None`` if the environment variables should be used. Environment variables
159won't be looked up.
160
161.. function:: set_defbase(base)
162
163    Set the default database name
164
165    :param base: the new default base name
166    :type base: str or None
167    :returns: the previous default database name specification
168    :rtype: str or None
169    :raises TypeError: bad argument type, or too many arguments
170
171This method sets the default database name value for new connections. If
172``None`` is supplied as parameter, environment variables will be used in
173future connections. It returns the previous setting for default host.
174
175get/set_defuser -- default database user [DV]
176---------------------------------------------
177
178.. function:: get_defuser()
179
180    Get the default database user
181
182    :returns: the current default database user specification
183    :rtype: str or None
184    :raises TypeError: too many arguments
185
186This method returns the current default database user specification, or
187``None`` if the environment variables should be used. Environment variables
188won't be looked up.
189
190.. function:: set_defuser(user)
191
192    Set the default database user
193
194    :param user: the new default database user
195    :type base: str or None
196    :returns: the previous default database user specification
197    :rtype: str or None
198    :raises TypeError: bad argument type, or too many arguments
199
200This method sets the default database user name for new connections. If
201``None`` is supplied as parameter, environment variables will be used in
202future connections. It returns the previous setting for default host.
203
204get/set_defpasswd -- default database password [DV]
205---------------------------------------------------
206
207.. function:: get_defpasswd()
208
209    Get the default database password
210
211    :returns: the current default database password specification
212    :rtype: str or None
213    :raises TypeError: too many arguments
214
215This method returns the current default database password specification, or
216``None`` if the environment variables should be used. Environment variables
217won't be looked up.
218
219.. function:: set_defpasswd(passwd)
220
221    Set the default database password
222
223    :param passwd: the new default database password
224    :type base: str or None
225    :returns: the previous default database password specification
226    :rtype: str or None
227    :raises TypeError: bad argument type, or too many arguments
228
229This method sets the default database password for new connections. If
230``None`` is supplied as parameter, environment variables will be used in
231future connections. It returns the previous setting for default host.
232
233escape_string -- escape a string for use within SQL
234---------------------------------------------------
235
236.. function:: escape_string(string)
237
238    Escape a string for use within SQL
239
240    :param str string: the string that is to be escaped
241    :returns: the escaped string
242    :rtype: str
243    :raises TypeError: bad argument type, or too many arguments
244
245This function escapes a string for use within an SQL command.
246This is useful when inserting data values as literal constants
247in SQL commands. Certain characters (such as quotes and backslashes)
248must be escaped to prevent them from being interpreted specially
249by the SQL parser. :func:`escape_string` performs this operation.
250Note that there is also a :class:`Connection` method with the same name
251which takes connection properties into account.
252
253.. note::
254
255    It is especially important to do proper escaping when
256    handling strings that were received from an untrustworthy source.
257    Otherwise there is a security risk: you are vulnerable to "SQL injection"
258    attacks wherein unwanted SQL commands are fed to your database.
259
260Example::
261
262    name = input("Name? ")
263    phone = con.query("select phone from employees where name='%s'"
264        % escape_string(name)).getresult()
265
266escape_bytea -- escape binary data for use within SQL
267-----------------------------------------------------
268
269.. function:: escape_bytea(datastring)
270
271    escape binary data for use within SQL as type ``bytea``
272
273    :param str datastring: string containing the binary data that is to be escaped
274    :returns: the escaped string
275    :rtype: str
276    :raises TypeError: bad argument type, or too many arguments
277
278Escapes binary data for use within an SQL command with the type ``bytea``.
279As with :func:`escape_string`, this is only used when inserting data directly
280into an SQL command string.
281
282Note that there is also a :class:`Connection` method with the same name
283which takes connection properties into account.
284
285Example::
286
287    picture = open('garfield.gif', 'rb').read()
288    con.query("update pictures set img='%s' where name='Garfield'"
289        % escape_bytea(picture))
290
291unescape_bytea -- unescape data that has been retrieved as text
292---------------------------------------------------------------
293
294.. function:: unescape_bytea(string)
295
296    Unescape ``bytea`` data that has been retrieved as text
297
298    :param str datastring: the ``bytea`` data string that has been retrieved as text
299    :returns: byte string containing the binary data
300    :rtype: bytes
301    :raises TypeError: bad argument type, or too many arguments
302
303Converts an escaped string representation of binary data stored as ``bytea``
304into the raw byte string representing the binary data  -- this is the reverse
305of :func:`escape_bytea`.  Since the :class:`Query` results will already
306return unescaped byte strings, you normally don't have to use this method.
307
308Note that there is also a :class:`DB` method with the same name
309which does exactly the same.
310
311get/set_namedresult -- conversion to named tuples
312-------------------------------------------------
313
314.. function:: get_namedresult()
315
316    Get the function that converts to named tuples
317
318This returns the function used by PyGreSQL to construct the result of the
319:meth:`Query.namedresult` method.
320
321.. versionadded:: 4.1
322
323.. function:: set_namedresult(func)
324
325    Set a function that will convert to named tuples
326
327    :param func: the function to be used to convert results to named tuples
328
329You can use this if you want to create different kinds of named tuples
330returned by the :meth:`Query.namedresult` method.  If you set this function
331to *None*, then it will become equal to :meth:`Query.getresult`.
332
333.. versionadded:: 4.1
334
335get/set_decimal -- decimal type to be used for numeric values
336-------------------------------------------------------------
337
338.. function:: get_decimal()
339
340    Get the decimal type to be used for numeric values
341
342    :returns: the Python class used for PostgreSQL numeric values
343    :rtype: class
344
345This function returns the Python class that is used by PyGreSQL to hold
346PostgreSQL numeric values. The default class is :class:`decimal.Decimal`
347if available, otherwise the :class:`float` type is used.
348
349.. function:: set_decimal(cls)
350
351    Set a decimal type to be used for numeric values
352
353    :param class cls: the Python class to be used for PostgreSQL numeric values
354
355This function can be used to specify the Python class that shall
356be used by PyGreSQL to hold PostgreSQL numeric values.
357The default class is :class:`decimal.Decimal` if available,
358otherwise the :class:`float` type is used.
359
360get/set_decimal_point -- decimal mark used for monetary values
361--------------------------------------------------------------
362
363.. function:: get_decimal_point()
364
365    Get the decimal mark used for monetary values
366
367    :returns: string with one character representing the decimal mark
368    :rtype: str
369
370This function returns the decimal mark used by PyGreSQL to interpret
371PostgreSQL monetary values when converting them to decimal numbers.
372The default setting is ``'.'`` as a decimal point. This setting is not
373adapted automatically to the locale used by PostGreSQL, but you can use
374:func:`set_decimal()` to set a different decimal mark manually.  A return
375value of ``None`` means monetary values are not interpreted as decimal
376numbers, but returned as strings including the formatting and currency.
377
378.. versionadded:: 4.1.1
379
380.. function:: set_decimal_point(string)
381
382    Specify which decimal mark is used for interpreting monetary values
383
384    :param str string: string with one character representing the decimal mark
385
386This function can be used to specify the decimal mark used by PyGreSQL
387to interpret PostgreSQL monetary values. The default value is '.' as
388a decimal point. This value is not adapted automatically to the locale
389used by PostGreSQL, so if you are dealing with a database set to a
390locale that uses a ``','`` instead of ``'.'`` as the decimal point,
391then you need to call ``set_decimal(',')`` to have PyGreSQL interpret
392monetary values correctly. If you don't want money values to be converted
393to decimal numbers, then you can call ``set_decimal(None)``, which will
394cause PyGreSQL to return monetary values as strings including their
395formatting and currency.
396
397.. versionadded:: 4.1.1
398
399get/set_bool -- whether boolean values are returned as bool objects
400-------------------------------------------------------------------
401
402.. function:: get_bool()
403
404    Check whether boolean values are returned as bool objects
405
406    :returns: whether or not bool objects will be returned
407    :rtype: bool
408
409This function checks whether PyGreSQL returns PostgreSQL boolean
410values converted to Python bool objects, or as ``'f'`` and ``'t'``
411strings which are the values used internally by PostgreSQL.  By default,
412conversion to bool objects is activated, but you can disable this with
413the :func:`set_bool` function.
414
415.. versionadded:: 4.2
416
417.. function:: set_bool(on)
418
419    Set whether boolean values are returned as bool objects
420
421    :param on: whether or not bool objects shall be returned
422
423This function can be used to specify whether PyGreSQL shall return
424PostgreSQL boolean values converted to Python bool objects, or as
425``'f'`` and ``'t'`` strings which are the values used internally by
426PostgreSQL.  By default, conversion to bool objects is activated,
427but you can disable this by calling ``set_bool(True)``.
428
429.. versionadded:: 4.2
430
431.. versionchanged:: 5.0
432    Boolean values had been returned as string by default in earlier versions.
433
434get/set_array -- whether arrays are returned as list objects
435------------------------------------------------------------
436
437.. function:: get_array()
438
439    Check whether arrays are returned as list objects
440
441    :returns: whether or not list objects will be returned
442    :rtype: bool
443
444This function checks whether PyGreSQL returns PostgreSQL arrays converted
445to Python list objects, or simply as text in the internal special output
446syntax of PostgreSQL.  By default, conversion to list objects is activated,
447but you can disable this with the :func:`set_array` function.
448
449.. versionadded:: 5.0
450
451.. function:: set_array(on)
452
453    Set whether arrays are returned as list objects
454
455    :param on: whether or not list objects shall be returned
456
457This function can be used to specify whether PyGreSQL shall return PostgreSQL
458arrays converted to Python list objects, or simply as text in the internal
459special output syntax of PostgreSQL.  By default, conversion to list objects
460is activated, but you can disable this by calling ``set_array(False)``.
461
462.. versionadded:: 5.0
463
464.. versionchanged:: 5.0
465    Arrays had been always returned as text strings only in earlier versions.
466
467get/set_bytea_escaped -- whether bytea data is returned escaped
468---------------------------------------------------------------
469
470.. function:: get_bytea_escaped()
471
472    Check whether bytea values are returned as escaped strings
473
474    :returns: whether or not bytea objects will be returned escaped
475    :rtype: bool
476
477This function checks whether PyGreSQL returns PostgreSQL ``bytea`` values in
478escaped form or in unescaped from as byte strings.  By default, bytea values
479will be returned unescaped as byte strings, but you can change this with the
480:func:`set_bytea_escaped` function.
481
482.. versionadded:: 5.0
483
484.. function:: set_bytea_escaped(on)
485
486    Set whether bytea values are returned as escaped strings
487
488    :param on: whether or not bytea objects shall be returned escaped
489
490This function can be used to specify whether PyGreSQL shall return
491PostgreSQL ``bytea`` values in escaped form or in unescaped from as byte
492strings.  By default, bytea values will be returned unescaped as byte
493strings, but you can change this by calling ``set_bytea_escaped(True)``.
494
495.. versionadded:: 5.0
496
497.. versionchanged:: 5.0
498    Bytea data had been returned in escaped form by default in earlier versions.
499
500get/set_jsondecode -- decoding JSON format
501------------------------------------------
502
503.. function:: get_jsondecode()
504
505    Get the function that deserializes JSON formatted strings
506
507This returns the function used by PyGreSQL to construct Python objects
508from JSON formatted strings.
509
510.. function:: set_jsondecode(func)
511
512    Set a function that will deserialize JSON formatted strings
513
514    :param func: the function to be used for deserializing JSON strings
515
516You can use this if you do not want to deserialize JSON strings coming
517in from the database, or if want to use a different function than the
518standard function :func:`json.loads` or if you want to use it with parameters
519different from the default ones.  If you set this function to *None*, then
520the automatic deserialization of JSON strings will be deactivated.
521
522.. versionadded:: 5.0
523
524.. versionchanged:: 5.0
525    JSON data had been always returned as text strings in earlier versions.
526
527get/set_cast_hook -- fallback typecast function
528-----------------------------------------------
529
530.. function:: get_cast_hook()
531
532    Get the function that handles all external typecasting
533
534This returns the callback function used by PyGreSQL to provide plug-in
535Python typecast functions.
536
537.. function:: set_cast_hook(func)
538
539    Set a function that will handle all external typecasting
540
541    :param func: the function to be used as a callback
542
543If you set this function to *None*, then only the typecast functions
544implemented in the C extension module are enabled.  You normally would
545not want to change this.  Instead, you can use :func:`get_typecast` and
546:func:`set_typecast` to add or change the plug-in Python typecast functions.
547
548.. versionadded:: 5.0
549
550get/set_datestyle -- assume a fixed date style
551----------------------------------------------
552
553.. function:: get_datestyle()
554
555    Get the assumed date style for typecasting
556
557This returns the PostgreSQL date style that is silently assumed when
558typecasting dates or *None* if no fixed date style is assumed, in which case
559the date style is requested from the database when necessary (this is the
560default).  Note that this method will *not* get the date style that is
561currently set in the session or in the database.  You can get the current
562setting with the methods :meth:`DB.get_parameter` and
563:meth:`Connection.parameter`.  You can also get the date format corresponding
564to the current date style by calling :meth:`Connection.date_format`.
565
566.. versionadded:: 5.0
567
568.. function:: set_datestyle(datestyle)
569
570    Set a fixed date style that shall be assumed when typecasting
571
572    :param str datestyle: the date style that shall be assumed,
573      or *None* if no fixed dat style shall be assumed
574
575PyGreSQL is able to automatically pick up the right date style for typecasting
576date values from the database, even if you change it for the current session
577with a ``SET DateStyle`` command.  This is happens very effectively without
578an additional database request being involved.  If you still want to have
579PyGreSQL always assume a fixed date style instead, then you can set one with
580this function.  Note that calling this function will *not* alter the date
581style of the database or the current session.  You can do that by calling
582the method :meth:`DB.set_parameter` instead.
583
584.. versionadded:: 5.0
585
586get/set_typecast -- custom typecasting
587--------------------------------------
588
589PyGreSQL uses typecast functions to cast the raw data coming from the
590database to Python objects suitable for the particular database type.
591These functions take a single string argument that represents the data
592to be casted and must return the casted value.
593
594PyGreSQL provides through its C extension module basic typecast functions
595for the common database types, but if you want to add more typecast functions,
596you can set these using the following functions.
597
598.. method:: get_typecast(typ)
599
600    Get the global cast function for the given database type
601
602    :param str typ: PostgreSQL type name
603    :returns: the typecast function for the specified type
604    :rtype: function or None
605
606.. versionadded:: 5.0
607
608.. method:: set_typecast(typ, cast)
609
610    Set a global typecast function for the given database type(s)
611
612    :param typ: PostgreSQL type name or list of type names
613    :type typ: str or list
614    :param cast: the typecast function to be set for the specified type(s)
615    :type typ: str or int
616
617The typecast function must take one string object as argument and return a
618Python object into which the PostgreSQL type shall be casted.  If the function
619takes another parameter named *connection*, then the current database
620connection will also be passed to the typecast function.  This may sometimes
621be necessary to look up certain database settings.
622
623.. versionadded:: 5.0
624
625Note that database connections cache types and their cast functions using
626connection specific :class:`DbTypes` objects.  You can also get, set and
627reset typecast functions on the connection level using the methods
628:meth:`DbTypes.get_typecast`, :meth:`DbTypes.set_typecast` and
629:meth:`DbTypes.reset_typecast` of the :attr:`DB.dbtypes` object.  This will
630not affect other connections or future connections.  In order to be sure
631a global change is picked up by a running connection, you must reopen it or
632call :meth:`DbTypes.reset_typecast` on the :attr:`DB.dbtypes` object.
633
634Also note that the typecasting for all of the basic types happens already
635in the C extension module.  The typecast functions that can be set with
636the above methods are only called for the types that are not already
637supported by the C extension module.
638
639cast_array/record -- fast parsers for arrays and records
640--------------------------------------------------------
641
642PosgreSQL returns arrays and records (composite types) using a special output
643syntax with several quirks that cannot easily and quickly be parsed in Python.
644Therefore the C extension module provides two fast parsers that allow quickly
645turning these text representations into Python objects: Arrays will be
646converted to Python lists, and records to Python tuples.  These fast parsers
647are used automatically by PyGreSQL in order to return arrays and records from
648database queries as lists and tuples, so you normally don't need to call them
649directly.  You may only need them for typecasting arrays of data types that
650are not supported by default in PostgreSQL.
651
652.. function::  cast_array(string, [cast], [delim])
653
654    Cast a string representing a PostgreSQL array to a Python list
655
656    :param str string: the string with the text representation of the array
657    :param cast: a typecast function for the elements of the array
658    :type cast: callable or None
659    :param delim: delimiter character between adjacent elements
660    :type str: byte string with a single character
661    :returns: a list representing the PostgreSQL array in Python
662    :rtype: list
663    :raises TypeError: invalid argument types
664    :raises ValueError: error in the syntax of the given array
665
666This function takes a *string* containing the text representation of a
667PostgreSQL array (which may look like ``'{{1,2}{3,4}}'`` for a two-dimensional
668array), a typecast function *cast* that is called for every element, and
669an optional delimiter character *delim* (usually a comma), and returns a
670Python list representing the array (which may be nested like
671``[[1, 2], [3, 4]]`` in this example).  The cast function must take a single
672argument which will be the text representation of the element and must output
673the corresponding Python object that shall be put into the list.  If you don't
674pass a cast function or set it to *None*, then unprocessed text strings will
675be returned as elements of the array.  If you don't pass a delimiter character,
676then a comma will be used by default.
677
678.. versionadded:: 5.0
679
680.. function::  cast_record(string, [cast], [delim])
681
682    Cast a string representing a PostgreSQL record to a Python list
683
684    :param str string: the string with the text representation of the record
685    :param cast: typecast function(s) for the elements of the record
686    :type cast: callable, list or tuple of callables, or None
687    :param delim: delimiter character between adjacent elements
688    :type str: byte string with a single character
689    :returns: a tuple representing the PostgreSQL record in Python
690    :rtype: tuple
691    :raises TypeError: invalid argument types
692    :raises ValueError: error in the syntax of the given array
693
694This function takes a *string* containing the text representation of a
695PostgreSQL record (which may look like ``'(1,a,2,b)'`` for a record composed
696of four fields), a typecast function *cast* that is called for every element,
697or a list or tuple of such functions corresponding to the individual fields
698of the record, and an optional delimiter character *delim* (usually a comma),
699and returns a Python tuple representing the record (which may be inhomogeneous
700like ``(1, 'a', 2, 'b')`` in this example).  The cast function(s) must take a
701single argument which will be the text representation of the element and must
702output the corresponding Python object that shall be put into the tuple.  If
703you don't pass cast function(s) or pass *None* instead, then unprocessed text
704strings will be returned as elements of the tuple.  If you don't pass a
705delimiter character, then a comma will be used by default.
706
707.. versionadded:: 5.0
708
709Note that besides using parentheses instead of braces, there are other subtle
710differences in escaping special characters and NULL values between the syntax
711used for arrays and the one used for composite types, which these functions
712take into account.
713
714Type helpers
715------------
716
717The module provides the following type helper functions.  You can wrap
718parameters with these functions when passing them to :meth:`DB.query_formatted`
719in order to give PyGreSQL a hint about the type of the parameters.
720
721.. function:: Bytea(bytes)
722
723    A wrapper for holding a bytea value
724
725.. versionadded:: 5.0
726
727.. function:: Json(obj)
728
729    A wrapper for holding an object serializable to JSON
730
731.. versionadded:: 5.0
732
733.. function:: Literal(sql)
734
735    A wrapper for holding a literal SQL string
736
737.. versionadded:: 5.0
738
739Module constants
740----------------
741
742Some constants are defined in the module dictionary.
743They are intended to be used as parameters for methods calls.
744You should refer to the libpq description in the PostgreSQL user manual
745for more information about them. These constants are:
746
747.. data:: version
748.. data:: __version__
749
750    constants that give the current version
751
752.. data:: INV_READ
753.. data:: INV_WRITE
754
755    large objects access modes,
756    used by :meth:`Connection.locreate` and :meth:`LargeObject.open`
757
758.. data:: SEEK_SET
759.. data:: SEEK_CUR
760.. data:: SEEK_END
761
762    positional flags, used by :meth:`LargeObject.seek`
763
764.. data:: TRANS_IDLE
765.. data:: TRANS_ACTIVE
766.. data:: TRANS_INTRANS
767.. data:: TRANS_INERROR
768.. data:: TRANS_UNKNOWN
769
770    transaction states, used by :meth:`Connection.transaction`
Note: See TracBrowser for help on using the repository browser.