mirror of
https://github.com/postgres/postgres.git
synced 2025-07-02 09:02:37 +03:00
psql: Support zero byte field and record separators
Add new psql settings and command-line options to support setting the field and record separators for unaligned output to a zero byte, for easier interfacing with other shell tools. reviewed by Abhijit Menon-Sen
This commit is contained in:
@ -2272,11 +2272,26 @@ do_pset(const char *param, const char *value, printQueryOpt *popt, bool quiet)
|
||||
{
|
||||
if (value)
|
||||
{
|
||||
free(popt->topt.fieldSep);
|
||||
popt->topt.fieldSep = pg_strdup(value);
|
||||
free(popt->topt.fieldSep.separator);
|
||||
popt->topt.fieldSep.separator = pg_strdup(value);
|
||||
popt->topt.fieldSep.separator_zero = false;
|
||||
}
|
||||
if (!quiet)
|
||||
printf(_("Field separator is \"%s\".\n"), popt->topt.fieldSep);
|
||||
{
|
||||
if (popt->topt.fieldSep.separator_zero)
|
||||
printf(_("Field separator is zero byte.\n"));
|
||||
else
|
||||
printf(_("Field separator is \"%s\".\n"), popt->topt.fieldSep.separator);
|
||||
}
|
||||
}
|
||||
|
||||
else if (strcmp(param, "fieldsep_zero") == 0)
|
||||
{
|
||||
free(popt->topt.fieldSep.separator);
|
||||
popt->topt.fieldSep.separator = NULL;
|
||||
popt->topt.fieldSep.separator_zero = true;
|
||||
if (!quiet)
|
||||
printf(_("Field separator is zero byte.\n"));
|
||||
}
|
||||
|
||||
/* record separator for unaligned text */
|
||||
@ -2284,18 +2299,30 @@ do_pset(const char *param, const char *value, printQueryOpt *popt, bool quiet)
|
||||
{
|
||||
if (value)
|
||||
{
|
||||
free(popt->topt.recordSep);
|
||||
popt->topt.recordSep = pg_strdup(value);
|
||||
free(popt->topt.recordSep.separator);
|
||||
popt->topt.recordSep.separator = pg_strdup(value);
|
||||
popt->topt.recordSep.separator_zero = false;
|
||||
}
|
||||
if (!quiet)
|
||||
{
|
||||
if (strcmp(popt->topt.recordSep, "\n") == 0)
|
||||
if (popt->topt.recordSep.separator_zero)
|
||||
printf(_("Record separator is zero byte.\n"));
|
||||
else if (strcmp(popt->topt.recordSep.separator, "\n") == 0)
|
||||
printf(_("Record separator is <newline>."));
|
||||
else
|
||||
printf(_("Record separator is \"%s\".\n"), popt->topt.recordSep);
|
||||
printf(_("Record separator is \"%s\".\n"), popt->topt.recordSep.separator);
|
||||
}
|
||||
}
|
||||
|
||||
else if (strcmp(param, "recordsep_zero") == 0)
|
||||
{
|
||||
free(popt->topt.recordSep.separator);
|
||||
popt->topt.recordSep.separator = NULL;
|
||||
popt->topt.recordSep.separator_zero = true;
|
||||
if (!quiet)
|
||||
printf(_("Record separator is zero byte.\n"));
|
||||
}
|
||||
|
||||
/* toggle between full and tuples-only format */
|
||||
else if (strcmp(param, "t") == 0 || strcmp(param, "tuples_only") == 0)
|
||||
{
|
||||
|
Reference in New Issue
Block a user