Skip site navigation (1) Skip section navigation (2)

Re: Notes on implementing URI syntax for libpq

From: Robert Haas <robertmhaas(at)gmail(dot)com>
To: Alexander Shulgin <ash(at)commandprompt(dot)com>
Cc: Alexey Klyukin <alexk(at)commandprompt(dot)com>, Martijn van Oosterhout <kleptog(at)svana(dot)org>, pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Notes on implementing URI syntax for libpq
Date: 2011-11-24 15:02:13
Message-ID: (view raw, whole thread or download thread mbox)
Lists: pgsql-hackers
On Thu, Nov 24, 2011 at 9:40 AM, Alexander Shulgin
<ash(at)commandprompt(dot)com> wrote:
>> Another idea is to use local:/dir/name for UNIX domain socket instead of hostname:port, like it's displayed in the psql prompt.
> So the whole thing would look like this:
>  postgresql://local:/dir/name/dbname?param1=val1&...
> Where "/dir/name" is the absolute path to the directory containing the socket file.  If one wants to use the default directory the following syntax may serve the need:
>   postgresql://local:/dbname

I think this is just weird.  libpq treats any hostname that starts
with a slash as hostname.  And there's a standard way of URL-encoding
characters that would otherwise be treated as terminators: you write a
percent sign followed by two hex digits.  So if you want the host to
be /tmp, you just should just write:


Which is the equivalent of the connection string:

host=/tmp dbname=fred

This may appear to be slightly inconvenient notation, but there is
little reason to reinvent syntax that the URL gods have already
devised, and in practice specifying an explicit pathname in a
connection string is quite rare.  One normally specifies a local
socket connection by omitting to specify a hostname at all, and that
can work here, too.  That is, postgresql:///fred should be equivalent
to the connection string:


...which means it will use the default socket directory on UNIX, and a
loopback connection on Windows.  And postgresql:/// should be
equivalent to an empty connection string, defaulting everything.

Robert Haas
The Enterprise PostgreSQL Company

In response to


pgsql-hackers by date

Next:From: Yoann MoreauDate: 2011-11-24 15:08:50
Subject: tsvector term positions and character offset
Previous:From: Florian WeimerDate: 2011-11-24 14:50:45
Subject: Re: Notes on implementing URI syntax for libpq

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group