public inbox for [email protected]help / color / mirror / Atom feed
connect using env. variables 6+ messages / 3 participants [nested] [flat]
* connect using env. variables @ 2021-03-09 10:45 Hans Ginzel <[email protected]> 0 siblings, 1 reply; 6+ messages in thread From: Hans Ginzel @ 2021-03-09 10:45 UTC (permalink / raw) To: psycopg Please, there should be a possibility to call connect() without parameters for connecting using environment variables (PGSERVICE, PGDATABASE,…) or defaults ($USER@localhost/postgres). Even pg uri postgres:// is valid, https://www.postgresql.org/docs/current/libpq-connect.html. >>> d = psycopg2.connect(**parse_dsn('postgres://')) Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/usr/lib/python3/dist-packages/psycopg2/__init__.py", line 124, in connect raise TypeError('missing dsn and no parameters') TypeError: missing dsn and no parameters >>> d = psycopg2.connect(**parse_dsn('')) Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/usr/lib/python3/dist-packages/psycopg2/__init__.py", line 124, in connect raise TypeError('missing dsn and no parameters') TypeError: missing dsn and no parameters >>> db = psycopg2.connect() Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/usr/lib/python3/dist-packages/psycopg2/__init__.py", line 124, in connect raise TypeError('missing dsn and no parameters') TypeError: missing dsn and no parameters Thank you in advance, Hans ^ permalink raw reply [nested|flat] 6+ messages in thread
* Re: connect using env. variables @ 2021-03-09 10:47 Sebastiaan Mannem <[email protected]> parent: Hans Ginzel <[email protected]> 0 siblings, 1 reply; 6+ messages in thread From: Sebastiaan Mannem @ 2021-03-09 10:47 UTC (permalink / raw) To: Hans Ginzel <[email protected]>; +Cc: psycopg How about emptystring (e.a. '')? Power to Postgres™! Sebastiaan Mannem Product Manager M: +31 6 8252 1560 edbpostgres.com EDB, Anthony Fokkerweg 1, 1059 CM Amsterdam, The Netherlands On Tue, Mar 9, 2021 at 11:45 AM Hans Ginzel <[email protected]> wrote: > Please, there should be a possibility to call connect() without parameters > for connecting using environment variables (PGSERVICE, PGDATABASE,…) > or defaults ($USER@localhost/postgres). > > Even pg uri postgres:// is valid, > https://www.postgresql.org/docs/current/libpq-connect.html. > > >>> d = psycopg2.connect(**parse_dsn('postgres://')) > Traceback (most recent call last): > File "<stdin>", line 1, in <module> > File "/usr/lib/python3/dist-packages/psycopg2/__init__.py", line 124, > in connect > raise TypeError('missing dsn and no parameters') > TypeError: missing dsn and no parameters > >>> d = psycopg2.connect(**parse_dsn('')) > Traceback (most recent call last): > File "<stdin>", line 1, in <module> > File "/usr/lib/python3/dist-packages/psycopg2/__init__.py", line 124, > in connect > raise TypeError('missing dsn and no parameters') > TypeError: missing dsn and no parameters > >>> db = psycopg2.connect() > Traceback (most recent call last): > File "<stdin>", line 1, in <module> > File "/usr/lib/python3/dist-packages/psycopg2/__init__.py", line 124, > in connect > raise TypeError('missing dsn and no parameters') > TypeError: missing dsn and no parameters > > Thank you in advance, > Hans > > > ^ permalink raw reply [nested|flat] 6+ messages in thread
* Re: connect using env. variables @ 2021-03-09 11:06 Hans Ginzel <[email protected]> parent: Sebastiaan Mannem <[email protected]> 0 siblings, 1 reply; 6+ messages in thread From: Hans Ginzel @ 2021-03-09 11:06 UTC (permalink / raw) To: Sebastiaan Mannem <[email protected]>; +Cc: psycopg Empty string does not work for **parse_dsn(), see example below. H. On Tue, Mar 09, 2021 at 11:47:42AM +0100, Sebastiaan Mannem wrote: >How about emptystring (e.a. '')? > >Power to Postgres™! > > >Sebastiaan Mannem > >Product Manager > > >M: +31 6 8252 1560 > >edbpostgres.com > >EDB, Anthony Fokkerweg 1, 1059 CM Amsterdam, The Netherlands > > >On Tue, Mar 9, 2021 at 11:45 AM Hans Ginzel <[email protected]> wrote: > >> Please, there should be a possibility to call connect() without parameters >> for connecting using environment variables (PGSERVICE, PGDATABASE,…) >> or defaults ($USER@localhost/postgres). >> >> Even pg uri postgres:// is valid, >> https://www.postgresql.org/docs/current/libpq-connect.html. >> >> >>> d = psycopg2.connect(**parse_dsn('postgres://')) >> Traceback (most recent call last): >> File "<stdin>", line 1, in <module> >> File "/usr/lib/python3/dist-packages/psycopg2/__init__.py", line 124, >> in connect >> raise TypeError('missing dsn and no parameters') >> TypeError: missing dsn and no parameters >> >>> d = psycopg2.connect(**parse_dsn('')) >> Traceback (most recent call last): >> File "<stdin>", line 1, in <module> >> File "/usr/lib/python3/dist-packages/psycopg2/__init__.py", line 124, >> in connect >> raise TypeError('missing dsn and no parameters') >> TypeError: missing dsn and no parameters >> >>> db = psycopg2.connect() >> Traceback (most recent call last): >> File "<stdin>", line 1, in <module> >> File "/usr/lib/python3/dist-packages/psycopg2/__init__.py", line 124, >> in connect >> raise TypeError('missing dsn and no parameters') >> TypeError: missing dsn and no parameters >> >> Thank you in advance, >> Hans >> >> >> ^ permalink raw reply [nested|flat] 6+ messages in thread
* Re: connect using env. variables @ 2021-03-09 11:44 Daniele Varrazzo <[email protected]> parent: Hans Ginzel <[email protected]> 0 siblings, 1 reply; 6+ messages in thread From: Daniele Varrazzo @ 2021-03-09 11:44 UTC (permalink / raw) To: Hans Ginzel <[email protected]>; +Cc: Sebastiaan Mannem <[email protected]>; psycopg On Tue, 9 Mar 2021, 12:06 Hans Ginzel, <[email protected]> wrote: > Empty string does not work for **parse_dsn(), see example below. > It does: connect("", **parse_dsn()) -- Daniele ^ permalink raw reply [nested|flat] 6+ messages in thread
* Re: connect using env. variables @ 2021-03-09 11:53 Hans Ginzel <[email protected]> parent: Daniele Varrazzo <[email protected]> 0 siblings, 1 reply; 6+ messages in thread From: Hans Ginzel @ 2021-03-09 11:53 UTC (permalink / raw) To: Daniele Varrazzo <[email protected]>; +Cc: Sebastiaan Mannem <[email protected]>; psycopg Thank you. Is there a reason why connect() must get the empty string as parametr, please? On Tue, Mar 09, 2021 at 12:44:27PM +0100, Daniele Varrazzo wrote: >It does: connect("", **parse_dsn()) > >-- Daniele ^ permalink raw reply [nested|flat] 6+ messages in thread
* Re: connect using env. variables @ 2021-03-09 14:02 Daniele Varrazzo <[email protected]> parent: Hans Ginzel <[email protected]> 0 siblings, 0 replies; 6+ messages in thread From: Daniele Varrazzo @ 2021-03-09 14:02 UTC (permalink / raw) To: Hans Ginzel <[email protected]>; +Cc: Sebastiaan Mannem <[email protected]>; psycopg On Tue, 9 Mar 2021 at 12:53, Hans Ginzel <[email protected]> wrote: > > Thank you. > > Is there a reason why connect() must get the empty string as parametr, please? No, and I'm happy to make the dsn string optional, as you requested in github. psycopg3 already works this way and you can use connect(). I just wanted to point out that you can do what you want to do already: connecting using only the PG* env var or the parse_dsn() produce. It's one of these things that is ugly but has been that way for so long that we are used to it. Or better, which should have been fixed when we introduced the possibility to pass both the dsn string and the keywords to connect(), because in the past there was no parse_dsn() and facility to merge the two. Cheers -- Daniele ^ permalink raw reply [nested|flat] 6+ messages in thread
end of thread, other threads:[~2021-03-09 14:02 UTC | newest] Thread overview: 6+ messages (download: mbox mbox.gz follow: Atom feed) -- links below jump to the message on this page -- 2021-03-09 10:45 connect using env. variables Hans Ginzel <[email protected]> 2021-03-09 10:47 ` Sebastiaan Mannem <[email protected]> 2021-03-09 11:06 ` Hans Ginzel <[email protected]> 2021-03-09 11:44 ` Daniele Varrazzo <[email protected]> 2021-03-09 11:53 ` Hans Ginzel <[email protected]> 2021-03-09 14:02 ` Daniele Varrazzo <[email protected]>
This inbox is served by agora; see mirroring instructions for how to clone and mirror all data and code used for this inbox