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

Patch to psql to allow SEARCH_PATH to be set from env

From: Scott Goodwin <scott(at)scottg(dot)net>
To: pgsql-patches(at)postgresql(dot)org
Subject: Patch to psql to allow SEARCH_PATH to be set from env
Date: 2004-02-10 12:34:56
Message-ID: (view raw, whole thread or download thread mbox)
Lists: pgsql-patches
Using schemas is fun. Setting the search_path every time I use psql 
isn't. This patch modifies startup.c in psql to allow the SEARCH_PATH 
to be set to whatever the PG_SCHEMA_SEARCH_PATH environment variable is 
set to. If the var is not defined or is empty, no action is taken and 
the search path is what it would be without this patch. If 
PG_SCHEMA_SEARCH_PATH is set to garbage, psql simply reports the 
database error about non-existent schemas and continues running with 
the search_path it would have without this patch. The patch is against 
PG 7.4.1.

Here's an example session:

powerbook> PG_SCHEMA_SEARCH_PATH="'public','core','objects'"
powerbook> export PG_SCHEMA_SEARCH_PATH
powerbook> ./psql -d opencce
Welcome to psql 7.4.1, the PostgreSQL interactive terminal.

Type:  \copyright for distribution terms
        \h for help with SQL commands
        \? for help on internal slash commands
        \g or terminate with semicolon to execute query
        \q to quit

opencce=# show search_path;
  public, core, objects
(1 row)


The patch is small enough to copy and paste here; I've also attached it 
to this message.




diff -c -r postgresql-7.4.1/src/bin/psql/startup.c 
*** postgresql-7.4.1/src/bin/psql/startup.c Mon Sep 29 13:21:33 2003
--- postgresql-7.4.1.mod/src/bin/psql/startup.c Mon Feb  9 17:52:08 2004
*** 98,103 ****
--- 98,105 ----

     char       *username = NULL;
     char       *password = NULL;
+     char       *potential_SearchPath = NULL;
+     char       *searchpath = NULL;
     bool        need_pass;

     setlocale(LC_ALL, "");
*** 209,214 ****
--- 211,227 ----
     PQsetNoticeProcessor(pset.db, NoticeProcessor, NULL);

+     /*
+      * Set schema search path from environment
+      */
+     potential_SearchPath = getenv("PG_SCHEMA_SEARCH_PATH");
+     if (potential_SearchPath != NULL) {
+         searchpath = (char *) palloc(sizeof("SET SEARCH_PATH TO ") + 
+         sprintf(searchpath, "SET SEARCH_PATH TO %s", 
+       successResult = SendQuery(searchpath) ? EXIT_SUCCESS : 
+     }

     if (options.action == ACT_LIST_DB)

Attachment: searchpath.patch
Description: application/octet-stream (1.1 KB)


pgsql-patches by date

Next:From: Bruce MomjianDate: 2004-02-10 13:22:02
Subject: Re: Dev version doesn't acknowledge cross type indexes
Previous:From: Petri JoosteDate: 2004-02-10 10:04:34
Subject: Afrikaans translation of libpq

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