Skip to content

Commit 2795592

Browse files
committed
Allow a major PG version psql .psqlrc file to be used if a minor
matching version file does not exist. This avoids needing to rename .psqlrc files after minor version upgrades.
1 parent d26e1eb commit 2795592

File tree

2 files changed

+17
-8
lines changed

2 files changed

+17
-8
lines changed

doc/src/sgml/ref/psql-ref.sgml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3332,8 +3332,10 @@ PSQL_EDITOR_LINENUMBER_ARG='--line '
33323332
Both the system-wide <filename>psqlrc</filename> file and the user's
33333333
<filename>~/.psqlrc</filename> file can be made version-specific
33343334
by appending a dash and the <productname>PostgreSQL</productname>
3335-
release number, for example <filename>~/.psqlrc-&version;</filename>.
3336-
A matching version-specific file will be read in preference to a
3335+
major or minor release number, for example
3336+
<filename>~/.psqlrc-9.2</filename> or
3337+
<filename>~/.psqlrc-9.2.5</filename>. The most specific
3338+
version-matching file will be read in preference to a
33373339
non-version-specific file.
33383340
</para>
33393341
</listitem>

src/bin/psql/startup.c

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -594,20 +594,27 @@ process_psqlrc(char *argv0)
594594
static void
595595
process_psqlrc_file(char *filename)
596596
{
597-
char *psqlrc;
597+
char *psqlrc_minor, *psqlrc_major;
598598

599599
#if defined(WIN32) && (!defined(__MINGW32__))
600600
#define R_OK 4
601601
#endif
602602

603-
psqlrc = pg_malloc(strlen(filename) + 1 + strlen(PG_VERSION) + 1);
604-
sprintf(psqlrc, "%s-%s", filename, PG_VERSION);
603+
psqlrc_minor = pg_malloc(strlen(filename) + 1 + strlen(PG_VERSION) + 1);
604+
sprintf(psqlrc_minor, "%s-%s", filename, PG_VERSION);
605+
psqlrc_major = pg_malloc(strlen(filename) + 1 + strlen(PG_MAJORVERSION) + 1);
606+
sprintf(psqlrc_major, "%s-%s", filename, PG_MAJORVERSION);
605607

606-
if (access(psqlrc, R_OK) == 0)
607-
(void) process_file(psqlrc, false, false);
608+
/* check for minor version first, then major, then no version */
609+
if (access(psqlrc_minor, R_OK) == 0)
610+
(void) process_file(psqlrc_minor, false, false);
611+
else if (access(psqlrc_major, R_OK) == 0)
612+
(void) process_file(psqlrc_major, false, false);
608613
else if (access(filename, R_OK) == 0)
609614
(void) process_file(filename, false, false);
610-
free(psqlrc);
615+
616+
free(psqlrc_minor);
617+
free(psqlrc_major);
611618
}
612619

613620

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy