dbTalk Databases Forums  

[BUGS] pg_dump case folding bug

mailing.database.pgsql-bugs mailing.database.pgsql-bugs


Discuss [BUGS] pg_dump case folding bug in the mailing.database.pgsql-bugs forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Russell Smith
 
Posts: n/a

Default [BUGS] pg_dump case folding bug - 11-12-2004 , 09:54 PM






--Boundary-00=_TTYlBx0kYnIe6zh
Content-Type: text/plain;
charset="us-ascii"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

If PostgreSQL failed to compile on your computer or you found a bug that
is likely to be specific to one platform then please fill out this form
and e-mail it to pgsql-ports (AT) postgresql (DOT) org.

To report any other bug, fill out the form below and e-mail it to
pgsql-bugs (AT) postgresql (DOT) org.

If you not only found the problem but solved it and generated a patch
then e-mail it to pgsql-patches (AT) postgresql (DOT) org instead. Please use the
command "diff -c" to generate the patch.

You may also enter a bug report at http://www.postgresql.org/ instead of
e-mail-ing this form.

================================================== ==========================
POSTGRESQL BUG REPORT TEMPLATE
================================================== ==========================


Your name : Russell Smith
Your email address : As From address


System Configuration
---------------------
Architecture (example: Intel Pentium) : AMD 2000XP

Operating System (example: Linux 2.4.18) : Gentoo Linux 2.4.20-r9

PostgreSQL version (example: PostgreSQL-8.0): PostgreSQL-8.0-beta4

Compiler used (example: gcc 2.95.2) : gcc (GCC) 3.3.3 20040412 (Gentoo Linux 3.3.3-r6, ssp-3.3.2-2, pie-8.7.6)


Please enter a FULL description of your problem:
------------------------------------------------
pg_dump -i -h '10.0.0.5' -p '5432' -s 'test' -t '"Test"'

pg_dump does not fold case, and quote table and schema names correctly.
the above line will dump the table named "Test"

pg_dump -i -h '10.0.0.5' -p '5432' -s 'test' -t 'Test'
the above will dump the table named Test

I believe the correct output from 1 should be to dump the table named Test.
and correct output from 2 should dump the table named test


Please describe a way to repeat the problem. Please try to provide a
concise reproducible example, if at all possible:
----------------------------------------------------------------------
Reproduction from commands in description.


If you know how this problem might be fixed, list the solution below:
---------------------------------------------------------------------
Attempted patches attached. Most code taken from libpq and modified for pg_dump.

--Boundary-00=_TTYlBx0kYnIe6zh
Content-Type: text/x-diff;
charset="us-ascii";
name="fold_case.diff"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
filename="fold_case.diff"

Index: pg_dump.c
================================================== =================
RCS file: /projects/cvsroot/pgsql/src/bin/pg_dump/pg_dump.c,v
retrieving revision 1.392
diff -c -r1.392 pg_dump.c
*** pg_dump.c 6 Nov 2004 19:36:02 -0000 1.392
--- pg_dump.c 13 Nov 2004 03:29:17 -0000
***************
*** 112,117 ****
--- 112,118 ----
static int disable_dollar_quoting = 0;


+ static char* caseCastedQuotedName(const char *ident);
static void help(const char *progname);
static NamespaceInfo *findNamespace(Oid nsoid, Oid objoid);
static void dumpTableData(Archive *fout, TableDataInfo *tdinfo);
***************
*** 326,332 ****
break;

case 'n': /* Dump data for this schema only */
! selectSchemaName = strdup(optarg);
break;

case 'o': /* Dump oids */
--- 327,333 ----
break;

case 'n': /* Dump data for this schema only */
! selectSchemaName = caseCastedQuotedName(optarg);
break;

case 'o': /* Dump oids */
***************
*** 355,361 ****
break;

case 't': /* Dump data for this table only */
! selectTableName = strdup(optarg);
break;

case 'u':
--- 356,362 ----
break;

case 't': /* Dump data for this table only */
! selectTableName = caseCastedQuotedName(optarg);
break;

case 'u':
***************
*** 655,660 ****
--- 656,731 ----
exit(0);
}

+ /*
+ * caseCastedQuotedName: fold the case of a column unless "'d
+ *
+ * The column name is parsed as if it were in a SQL statement, including
+ * case-folding and double-quote processing. But note a possible gotcha:
+ * downcasing in the frontend might follow different locale rules than
+ * downcasing in the backend...
+ *
+ * Returns NULL on failure.
+ */
+ static char*
+ caseCastedQuotedName(const char *ident)
+ {
+ char *ident_case;
+ bool in_quotes;
+ char *iptr;
+ char *optr;
+
+ /*
+ * Note: it is correct to reject a zero-length input string; the
+ * proper input to match a zero-length field name would be "".
+ */
+ if (ident == NULL ||
+ ident[0] == '\0')
+ return NULL;
+
+ /*
+ * Note: this code will not reject partially quoted strings, eg
+ * foo"BAR"foo will become fooBARfoo when it probably ought to be an
+ * error condition.
+ */
+ ident_case = strdup(ident);
+ if (ident_case == NULL)
+ return NULL; /* grotty */
+
+ in_quotes = false;
+ optr = ident_case;
+ for (iptr = ident_case; *iptr; iptr++)
+ {
+ char c = *iptr;
+
+ if (in_quotes)
+ {
+ if (c == '"')
+ {
+ if (iptr[1] == '"')
+ {
+ /* doubled quotes become a single quote */
+ *optr++ = '"';
+ iptr++;
+ }
+ else
+ in_quotes = false;
+ }
+ else
+ *optr++ = c;
+ }
+ else if (c == '"')
+ in_quotes = true;
+ else
+ {
+ c = pg_tolower((unsigned char) c);
+ *optr++ = c;
+ }
+ }
+ *optr = '\0';
+
+ return ident_case;
+ }
+

static void
help(const char *progname)

--Boundary-00=_TTYlBx0kYnIe6zh
Content-Type: text/plain
Content-Disposition: inline
Content-Transfer-Encoding: 8bit
MIME-Version: 1.0


---------------------------(end of broadcast)---------------------------
TIP 4: Don't 'kill -9' the postmaster

--Boundary-00=_TTYlBx0kYnIe6zh--

Reply With Quote
  #2  
Old   
Tom Lane
 
Posts: n/a

Default Re: [BUGS] pg_dump case folding bug - 11-12-2004 , 11:07 PM






Russell Smith <mr-russ (AT) pws (DOT) com.au> writes:
Quote:
pg_dump does not fold case, and quote table and schema names correctly.
This is not a bug; it is a behavior we deliberately adopted years ago,
after unsuccessful experiments with behavior like what you propose.

The rule is that names appearing on a shell command line are taken
literally, without dequoting or case folding. Yes, this is inconsistent
with the behavior if the same string were entered within an SQL context,
but then again the command line isn't an SQL context.

The main reason for this position is that the shell imposes its own
quoting rules that we can't avoid, and these rules are not very
compatible with the SQL identifier quoting rules. Do you *really*
want to have to type '"Test"' when you could just write Test ?

Even more to the point, the only argument in favor of adding code to do
it like this is to try to make the shell command line context just like
the SQL context, but *you can't make it so*. If you could make "Test"
on the command line work just like "Test" in SQL it'd be great ... but
you can't because the shell will strip the double quotes before you ever
see them.

We went around a few times on this, but eventually decided it was
unhelpful to try to emulate the SQL quoting behavior.

BTW, this behavior is consistent across all our command-line tools;
if we did want to change it it'd affect much more than just pg_dump.

regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 7: don't forget to increase your free space map settings


Reply With Quote
  #3  
Old   
Russell Smith
 
Posts: n/a

Default Re: [BUGS] pg_dump case folding bug - 11-13-2004 , 04:51 AM



On Sat, 13 Nov 2004 04:05 pm, Tom Lane wrote:
Quote:
Russell Smith <mr-russ (AT) pws (DOT) com.au> writes:
pg_dump does not fold case, and quote table and schema names correctly.

This is not a bug; it is a behavior we deliberately adopted years ago,
after unsuccessful experiments with behavior like what you propose.

The rule is that names appearing on a shell command line are taken
literally, without dequoting or case folding. Yes, this is inconsistent
with the behavior if the same string were entered within an SQL context,
but then again the command line isn't an SQL context.

The main reason for this position is that the shell imposes its own
quoting rules that we can't avoid, and these rules are not very
compatible with the SQL identifier quoting rules. Do you *really*
want to have to type '"Test"' when you could just write Test ?

Even more to the point, the only argument in favor of adding code to do
it like this is to try to make the shell command line context just like
the SQL context, but *you can't make it so*. If you could make "Test"
on the command line work just like "Test" in SQL it'd be great ... but
you can't because the shell will strip the double quotes before you ever
see them.

We went around a few times on this, but eventually decided it was
unhelpful to try to emulate the SQL quoting behavior.

Thanks Tom, I found this out after talking to the pg_dump developers.
I had discussed with Neil if this should be implement and proposed I
have a go at it. I have since seen otherwise and identified the bug
in phppgadmin causing the problem.

Thanks for the detailed answer.


Quote:
BTW, this behavior is consistent across all our command-line tools;
if we did want to change it it'd affect much more than just pg_dump.

regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 7: don't forget to increase your free space map settings


---------------------------(end of broadcast)---------------------------
TIP 3: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to majordomo (AT) postgresql (DOT) org so that your
message can get through to the mailing list cleanly


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.