Windows path in PostgreSQL statements

note This article available in Russian.

There are not so many statements which take filesystem path as an argument. Of the top of my head:

  • CREATE TABLESPACE …
  • CREATE FUNCTION … (in case of dynamic loading C-Language functions)

So, the thing is that those arguments are just string constants, means there is no validation by lexer provided for them, what in it’s turn have different effects in different OSes. Not to say much:

warning Windows user! Replace your usual slashes (backslashes, actually) with the slashes like this one: ‘/’, in the file system path parameters!

WRONG:

CREATE TABLESPACE dbspace
  LOCATION 'C:\Program Files\PostgreSQL\8.3\data\dbs';
CREATE TABLESPACE dbspace
  LOCATION E'C:\Program Files\PostgreSQL\8.3\data\dbs';

RIGHT:

CREATE TABLESPACE dbspace
  LOCATION 'C:/Program Files/PostgreSQL/8.3/data/dbs';
CREATE TABLESPACE dbspace
  LOCATION 'C:\\Program Files\\PostgreSQL\\8.3\\data\\dbs';
-- but with warning! Do not ever do like this
CREATE TABLESPACE dbspace3
  LOCATION E'C:\\Program Files\\PostgreSQL\\8.3\\data\\dbs3'

P.S.: I do not like absolute paths. Why do we have $libdir magic for CREATE FUNCTION and do not have something similar for CREATE TABLESPACE?

That’s all folks!

4 thoughts on “Windows path in PostgreSQL statements

  1. Pingback: 2010 in review « Pasha Golub's Blog
  2. Pingback: Windows path in libpq connection control functions « Pasha Golub's Blog

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s