Skip to content

Commit

Permalink
i
Browse files Browse the repository at this point in the history
  • Loading branch information
tlocke committed Sep 14, 2024
1 parent 0e7d1fb commit eb5eb7f
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 10 deletions.
33 changes: 31 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -972,6 +972,33 @@ the `replication` keyword when creating a connection:

```

### Extra Startup Parameters

The standard startup parameters `user`, `database` and `replication` are set with their
own parameters in the `Connection()` constructor. However, as the
[docs](https://www.postgresql.org/docs/current/protocol-message-formats.html) say:

> In addition to the above, other parameters may be listed. Parameter names beginning
> with \_pq\_. are reserved for use as protocol extensions, while others are treated as
> run-time parameters to be set at backend start time. Such settings will be applied
> during backend start (after parsing the command-line arguments if any) and will act as
> session defaults.
these additional parameters can be specified using the `startup_params` parameter of the
`Connection()` constructor:

```python
>>> import pg8000.native
>>>
>>> con = pg8000.native.Connection(
... 'postgres', password="cpsnow", startup_params={'IntervalStyle': 'sql_standard'})
>>>
>>> con.run("SHOW IntervalStyle")
[['...', 1, '.../...', 'postgres']]
>>>
>>> con.close()

```

## DB-API 2 Interactive Examples

Expand Down Expand Up @@ -1459,6 +1486,7 @@ Creates a connection to a PostgreSQL database.
- *application_name* - Sets the [application\_name](https://www.postgresql.org/docs/current/runtime-config-logging.html#GUC-APPLICATION-NAME). If your server character encoding is not `ascii` or `utf8`, then you need to provide values as bytes, eg. `'my_application_name'.encode('EUC-JP')`. The default is `None` which means that the server will set the application name.
- *replication* - Used to run in [streaming replication mode](https://www.postgresql.org/docs/current/protocol-replication.html). If your server character encoding is not `ascii` or `utf8`, then you need to provide values as bytes, eg. `'database'.encode('EUC-JP')`.
- *sock* - A socket-like object to use for the connection. For example, `sock` could be a plain `socket.socket`, or it could represent an SSH tunnel or perhaps an `ssl.SSLSocket` to an SSL proxy. If an `ssl.SSLContext` is provided, then it will be used to attempt to create an SSL socket from the provided socket.
- *startup_params* - The standard startup parameters 'user', 'database' and 'replication' have their own parameters in this constructor. Other startup parameters can be specified in this dictionary. To quote the [docs](https://www.postgresql.org/docs/current/protocol-message-formats.html): "Parameter names beginning with _pq_. are reserved for use as protocol extensions, while others are treated as run-time parameters to be set at backend start time. Such settings will be applied during backend start (after parsing the command-line arguments if any) and will act as session defaults."

### pg8000.native.Connection.notifications

Expand Down Expand Up @@ -1663,14 +1691,15 @@ Creates a connection to a PostgreSQL database.
- *application_name* - Sets the [application\_name](https://www.postgresql.org/docs/current/runtime-config-logging.html#GUC-APPLICATION-NAME). If your server character encoding is not `ascii` or `utf8`, then you need to provide values as bytes, eg. `'my_application_name'.encode('EUC-JP')`. The default is `None` which means that the server will set the application name.
- *replication* - Used to run in [streaming replication mode](https://www.postgresql.org/docs/current/protocol-replication.html). If your server character encoding is not `ascii` or `utf8`, then you need to provide values as bytes, eg. `'database'.encode('EUC-JP')`.
- *sock* - A socket-like object to use for the connection. For example, `sock` could be a plain `socket.socket`, or it could represent an SSH tunnel or perhaps an `ssl.SSLSocket` to an SSL proxy. If an `ssl.SSLContext` is provided, then it will be used to attempt to create an SSL socket from the provided socket.
- *startup_params* - The standard startup parameters 'user', 'database' and 'replication' have their own parameters in this constructor. Other startup parameters can be specified in this dictionary. To quote the [docs](https://www.postgresql.org/docs/current/protocol-message-formats.html): "Parameter names beginning with _pq_. are reserved for use as protocol extensions, while others are treated as run-time parameters to be set at backend start time. Such settings will be applied during backend start (after parsing the command-line arguments if any) and will act as session defaults."


#### pg8000.dbapi.Date(year, month, day)

Construct an object holding a date value.

This property is part of the `DBAPI 2.0 specification
<http://www.python.org/dev/peps/pep-0249/>`_.
This property is part of the
[DBAPI 2.0 specification](http://www.python.org/dev/peps/pep-0249/).

Returns: `datetime.date`

Expand Down
4 changes: 2 additions & 2 deletions src/pg8000/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def connect(
tcp_keepalive=True,
application_name=None,
replication=None,
init_params=None,
startup_params=None,
):
return Connection(
user,
Expand All @@ -122,7 +122,7 @@ def connect(
tcp_keepalive=tcp_keepalive,
application_name=application_name,
replication=replication,
init_params=init_params,
startup_params=startup_params,
)


Expand Down
10 changes: 8 additions & 2 deletions src/pg8000/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ def __init__(
tcp_keepalive=True,
application_name=None,
replication=None,
init_params=None,
startup_params=None,
sock=None,
):
self._client_encoding = "utf8"
Expand All @@ -296,8 +296,14 @@ def __init__(
"database": database,
"application_name": application_name,
"replication": replication,
**(init_params or {})
}
common_params = init_params.keys() & startup_params
if len(common_params) > 0:
raise InterfaceError(
"The parameters '{common_params}' can't appear in startup_params, they "
"must be set using keyword arguments."
)
init_params.update(startup_params)

for k, v in tuple(init_params.items()):
if isinstance(v, str):
Expand Down
4 changes: 2 additions & 2 deletions src/pg8000/dbapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ def connect(
tcp_keepalive=True,
application_name=None,
replication=None,
init_params=None,
startup_params=None,
sock=None,
):
return Connection(
Expand All @@ -222,7 +222,7 @@ def connect(
tcp_keepalive=tcp_keepalive,
application_name=application_name,
replication=replication,
init_params=init_params,
startup_params=startup_params,
sock=sock,
)

Expand Down
4 changes: 2 additions & 2 deletions src/pg8000/legacy.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ def connect(
tcp_keepalive=True,
application_name=None,
replication=None,
init_params=None,
startup_params=None,
):
return Connection(
user,
Expand All @@ -140,7 +140,7 @@ def connect(
tcp_keepalive=tcp_keepalive,
application_name=application_name,
replication=replication,
init_params=init_params,
startup_params=startup_params,
)


Expand Down

0 comments on commit eb5eb7f

Please sign in to comment.