pg
— The Classic PyGreSQL Interface¶
Contents¶
- Introduction
- Module functions and constants
- connect – Open a PostgreSQL connection
- get_pqlib_version – get the version of libpq
- get/set_defhost – default server host
- get/set_defport – default server port
- get/set_defopt – default connection options
- get/set_defbase – default database name
- get/set_defuser – default database user
- get/set_defpasswd – default database password
- escape_string – escape a string for use within SQL
- escape_bytea – escape binary data for use within SQL
- unescape_bytea – unescape data that has been retrieved as text
- get/set_decimal – decimal type to be used for numeric values
- get/set_decimal_point – decimal mark used for monetary values
- get/set_bool – whether boolean values are returned as bool objects
- get/set_array – whether arrays are returned as list objects
- get/set_bytea_escaped – whether bytea data is returned escaped
- get/set_jsondecode – decoding JSON format
- get/set_datestyle – assume a fixed date style
- get/set_typecast – custom typecasting
- cast_array/record – fast parsers for arrays and records
- Type helpers
- Module constants
- Connection – The connection object
Connection
- query – execute a SQL command string
- send_query - executes a SQL command string asynchronously
- query_prepared – execute a prepared statement
- prepare – create a prepared statement
- describe_prepared – describe a prepared statement
- reset – reset the connection
- poll - completes an asynchronous connection
- cancel – abandon processing of current SQL command
- close – close the database connection
- transaction – get the current transaction state
- parameter – get a current server parameter setting
- date_format – get the currently used date format
- fileno – get the socket used to connect to the database
- set_non_blocking - set the non-blocking status of the connection
- is_non_blocking - report the blocking status of the connection
- getnotify – get the last notify from the server
- inserttable – insert an iterable into a table
- get/set_cast_hook – fallback typecast function
- get/set_notice_receiver – custom notice receiver
- putline – write a line to the server socket
- getline – get a line from server socket
- endcopy – synchronize client and server
- locreate – create a large object in the database
- getlo – build a large object from given oid
- loimport – import a file to a large object
- Object attributes
- The DB wrapper class
DB
- Initialization
- pkey – return the primary key of a table
- pkeys – return the primary keys of a table
- get_databases – get list of databases in the system
- get_relations – get list of relations in connected database
- get_tables – get list of tables in connected database
- get_attnames – get the attribute names of a table
- get_generated – get the generated columns of a table
- has_table_privilege – check table privilege
- get/set_parameter – get or set run-time parameters
- begin/commit/rollback/savepoint/release – transaction handling
- get – get a row from a database table or view
- insert – insert a row into a database table
- update – update a row in a database table
- upsert – insert a row with conflict resolution
- query – execute a SQL command string
- query_formatted – execute a formatted SQL command string
- query_prepared – execute a prepared statement
- prepare – create a prepared statement
- describe_prepared – describe a prepared statement
- delete_prepared – delete a prepared statement
- clear – clear row values in memory
- delete – delete a row from a database table
- truncate – quickly empty database tables
- get_as_list/dict – read a table as a list or dictionary
- escape_literal/identifier/string/bytea – escape for SQL
- unescape_bytea – unescape data retrieved from the database
- encode/decode_json – encode and decode JSON data
- use_regtypes – choose usage of registered type names
- notification_handler – create a notification handler
- Attributes of the DB wrapper class
- Query methods
Query
- getresult – get query values as list of tuples
- dictresult/dictiter – get query values as dictionaries
- namedresult/namediter – get query values as named tuples
- scalarresult/scalariter – get query values as scalars
- one/onedict/onenamed/onescalar – get one result of a query
- single/singledict/singlenamed/singlescalar – get single result of a query
- listfields – list field names of query result
- fieldname, fieldnum – field name/number conversion
- fieldinfo – detailed info about query result fields
- memsize – return number of bytes allocated by query result
- LargeObject – Large Objects
- The Notification Handler
- DbTypes – The internal cache for database types
- Remarks on Adaptation and Typecasting