Unix Technical Forum

Re: [BUGS] BUG #2221: Bad delimiters allowed in COPY ... TO

This is a discussion on Re: [BUGS] BUG #2221: Bad delimiters allowed in COPY ... TO within the Pgsql Patches forums, part of the PostgreSQL category; --> On Sun, Jan 29, 2006 at 09:50:08PM +0000, David Fetter wrote: > > The following bug has been logged ...


Go Back   Unix Technical Forum > Database Server Software > PostgreSQL > Pgsql Patches

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-18-2008, 01:17 AM
David Fetter
 
Posts: n/a
Default Re: [BUGS] BUG #2221: Bad delimiters allowed in COPY ... TO

On Sun, Jan 29, 2006 at 09:50:08PM +0000, David Fetter wrote:
>
> The following bug has been logged online:
>
> Bug reference: 2221
> Logged by: David Fetter
> Email address: david@fetter.org
> PostgreSQL version: all
> Operating system: all
> Description: Bad delimiters allowed in COPY ... TO
> Details:
>
> This came up while I was testing my pg_dump "specify DELIMITER AS and/or
> NULL AS" patch.


Folks,

Please pardon the self-followup. I believe that this patch fixes the
problem in COPY.

Cheers,
D
--
David Fetter david@fetter.org http://fetter.org/
phone: +1 415 235 3778

Remember to vote!


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

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 04-18-2008, 01:17 AM
David Fetter
 
Posts: n/a
Default Re: [BUGS] BUG #2221: Bad delimiters allowed in COPY ... TO

On Sun, Jan 29, 2006 at 04:41:43PM -0800, David Fetter wrote:
> On Sun, Jan 29, 2006 at 09:50:08PM +0000, David Fetter wrote:
> >
> > The following bug has been logged online:
> >
> > Bug reference: 2221
> > Logged by: David Fetter
> > Email address: david@fetter.org
> > PostgreSQL version: all
> > Operating system: all
> > Description: Bad delimiters allowed in COPY ... TO
> > Details:
> >
> > This came up while I was testing my pg_dump "specify DELIMITER AS and/or
> > NULL AS" patch.

>
> Folks,
>
> Please pardon the self-followup. I believe that this patch fixes
> the problem in COPY.


Another followup, this time with the comment done right.

Cheers,
D
--
David Fetter david@fetter.org http://fetter.org/
phone: +1 415 235 3778

Remember to vote!


---------------------------(end of broadcast)---------------------------
TIP 9: In versions below 8.0, the planner will ignore your desire to
choose an index scan if your joining column's datatypes do not
match

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 04-18-2008, 01:17 AM
Neil Conway
 
Posts: n/a
Default Re: [BUGS] BUG #2221: Bad delimiters allowed in COPY ...

On Sun, 2006-01-29 at 17:03 -0800, David Fetter wrote:
> Another followup, this time with the comment done right.


+ /* Disallow the forbidden_delimiter strings */
+ if (strcspn(cstate->delim, BADCHARS) != 1)
+ elog(ERROR, "COPY delimiter cannot be %#02x",
+ *cstate->delim);
+

The comment is still wrong: referencing "forbidden_delimiter" makes it
sound like there is something named forbidden_delimiter, but there is
not (at least in the patch as submitted).

The patch should also use ereport rather than elog, because this error
message might reasonably be encountered by the user.

-Neil



---------------------------(end of broadcast)---------------------------
TIP 6: explain analyze is your friend

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 04-18-2008, 01:17 AM
David Fetter
 
Posts: n/a
Default Re: [BUGS] BUG #2221: Bad delimiters allowed in COPY ...

On Sun, Jan 29, 2006 at 10:20:47PM -0500, Neil Conway wrote:
> On Sun, 2006-01-29 at 17:03 -0800, David Fetter wrote:
> > Another followup, this time with the comment done right.

>
> + /* Disallow the forbidden_delimiter strings */
> + if (strcspn(cstate->delim, BADCHARS) != 1)
> + elog(ERROR, "COPY delimiter cannot be %#02x",
> + *cstate->delim);
> +
>
> The comment is still wrong: referencing "forbidden_delimiter" makes
> it sound like there is something named forbidden_delimiter, but
> there is not (at least in the patch as submitted).
>
> The patch should also use ereport rather than elog, because this
> error message might reasonably be encountered by the user.


Patch with BADCHARS attached

Cheers,
D
--
David Fetter david@fetter.org http://fetter.org/
phone: +1 415 235 3778

Remember to vote!


---------------------------(end of broadcast)---------------------------
TIP 4: Have you searched our list archives?

http://archives.postgresql.org

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 04-18-2008, 01:17 AM
Andrew Dunstan
 
Posts: n/a
Default Re: [BUGS] BUG #2221: Bad delimiters allowed in COPY ...



David Fetter wrote:

>
>+ /* Disallow BADCHARS characters */
>+ if (strcspn(cstate->delim, BADCHARS) != 1)
>+ ereport(ERROR,
>+ (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
>+ errmsg("COPY delimiter cannot be \"%#02x\"",
>+ *cstate->delim)));
>+
>
>
>


Is ERRCODE_FEATURE_NOT_SUPPORTED the right errcode? This isn't a
missing feature; we are performing a sanity check here. We can
reasonably expect never to support CR, LF or \ as the text delimiter.
Maybe ERRCODE_INVALID_PARAMETER_VALUE ? Or maybe we need a new one.

Also, I would probably make the format %#.02x so the result would look
like 0x0d (for a CR).

(I bet David never thought there would so much fuss over a handful of
lines of code)

cheers

andrew

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

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 04-18-2008, 01:17 AM
David Fetter
 
Posts: n/a
Default Re: [BUGS] BUG #2221: Bad delimiters allowed in COPY ...

On Mon, Jan 30, 2006 at 08:21:34AM -0500, Andrew Dunstan wrote:
>
>
> David Fetter wrote:
>
> >
> >+ /* Disallow BADCHARS characters */
> >+ if (strcspn(cstate->delim, BADCHARS) != 1)
> >+ ereport(ERROR,
> >+ (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
> >+ errmsg("COPY delimiter cannot be \"%#02x\"",
> >+ *cstate->delim)));
> >+

>
> Is ERRCODE_FEATURE_NOT_SUPPORTED the right errcode? This isn't a
> missing feature; we are performing a sanity check here. We can
> reasonably expect never to support CR, LF or \ as the text
> delimiter.


I guess that depends on whether we ever plan to allow people to set
the output record separator to something other than CR?LF.

> Maybe ERRCODE_INVALID_PARAMETER_VALUE ? Or maybe we need a new one.
>
> Also, I would probably make the format %#.02x so the result would
> look like 0x0d (for a CR).
>
> (I bet David never thought there would so much fuss over a handful
> of lines of code)


Actually, I'm happy to see it's getting QA. COPY is something that
has Consequences™ if anything goes wrong with it, so I'd rather do
best efforts up front to get it right.

Cheers,
D
--
David Fetter david@fetter.org http://fetter.org/
phone: +1 415 235 3778

Remember to vote!

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

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 04-18-2008, 01:17 AM
Bruce Momjian
 
Posts: n/a
Default Re: [BUGS] BUG #2221: Bad delimiters allowed in COPY ...

> Is ERRCODE_FEATURE_NOT_SUPPORTED the right errcode? This isn't a
> missing feature; we are performing a sanity check here. We can
> reasonably expect never to support CR, LF or \ as the text
> delimiter.


I guess that depends on whether we ever plan to allow people to set
the output record separator to something other than CR?LF.

> Maybe ERRCODE_INVALID_PARAMETER_VALUE ? Or maybe we need a new one.


Agreed. Right now it is invalid and there are no plans to support other
values for end-of-line. I will make the change when the patch is
applied.

--
Bruce Momjian | http://candle.pha.pa.us
pgman@candle.pha.pa.us | (610) 359-1001
+ If your life is a hard drive, | 13 Roberts Road
+ Christ can be your backup. | Newtown Square, Pennsylvania 19073

---------------------------(end of broadcast)---------------------------
TIP 6: explain analyze is your friend

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #8 (permalink)  
Old 04-18-2008, 01:17 AM
Bruce Momjian
 
Posts: n/a
Default Re: [BUGS] BUG #2221: Bad delimiters allowed in COPY ...


Uh, couldn't the delimiter be a backslash in CVS mode?

+ #define BADCHARS "\r\n\\"

Also, should we disable DELIMITER and NULL from sharing characters?

---------------------------------------------------------------------------

David Fetter wrote:
> On Sun, Jan 29, 2006 at 10:20:47PM -0500, Neil Conway wrote:
> > On Sun, 2006-01-29 at 17:03 -0800, David Fetter wrote:
> > > Another followup, this time with the comment done right.

> >
> > + /* Disallow the forbidden_delimiter strings */
> > + if (strcspn(cstate->delim, BADCHARS) != 1)
> > + elog(ERROR, "COPY delimiter cannot be %#02x",
> > + *cstate->delim);
> > +
> >
> > The comment is still wrong: referencing "forbidden_delimiter" makes
> > it sound like there is something named forbidden_delimiter, but
> > there is not (at least in the patch as submitted).
> >
> > The patch should also use ereport rather than elog, because this
> > error message might reasonably be encountered by the user.

>
> Patch with BADCHARS attached
>
> Cheers,
> D
> --
> David Fetter david@fetter.org http://fetter.org/
> phone: +1 415 235 3778
>
> Remember to vote!


[ Attachment, skipping... ]

>
> ---------------------------(end of broadcast)---------------------------
> TIP 3: Have you checked our extensive FAQ?
>
> http://www.postgresql.org/docs/faq


--
Bruce Momjian | http://candle.pha.pa.us
pgman@candle.pha.pa.us | (610) 359-1001
+ If your life is a hard drive, | 13 Roberts Road
+ Christ can be your backup. | Newtown Square, Pennsylvania 19073

---------------------------(end of broadcast)---------------------------
TIP 4: Have you searched our list archives?

http://archives.postgresql.org

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #9 (permalink)  
Old 04-18-2008, 01:17 AM
David Fetter
 
Posts: n/a
Default Re: [BUGS] BUG #2221: Bad delimiters allowed in COPY ...

On Tue, Jan 31, 2006 at 08:03:41PM -0500, Bruce Momjian wrote:
> Uh, couldn't the delimiter be a backslash in CVS mode?


I don't think so. Folks?

Anyhow, if there are different sets, I could do something like:

#define BADCHARS "\r\n\\"
#define BADCHARS_CSV "\r\n"

and then check for csv_mode, etc.

> + #define BADCHARS "\r\n\\"
>
> Also, should we disable DELIMITER and NULL from sharing characters?


That's on about line 916, post-patch:

/* Don't allow the delimiter to appear in the null string. */
if (strchr(cstate->null_print, cstate->delim[0]) != NULL)
ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("COPY delimiter must not appear in the NULL specification")));

I suppose that a different error code might be The Right Thing™ here.

Cheers,
D
--
David Fetter david@fetter.org http://fetter.org/
phone: +1 415 235 3778

Remember to vote!

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

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #10 (permalink)  
Old 04-18-2008, 01:17 AM
Andrew Dunstan
 
Posts: n/a
Default Re: [BUGS] BUG #2221: Bad delimiters allowed in COPY ...

David Fetter said:
> On Tue, Jan 31, 2006 at 08:03:41PM -0500, Bruce Momjian wrote:
>> Uh, couldn't the delimiter be a backslash in CVS mode?

>
> I don't think so. Folks?


Using backslash as a delimiter in CSV would be odd, to say the least. As an
escape char it is occasionally used, but not as a delimiter in my
experience. Maybe we should apply the "be liberal in what you accept" rule,
but I think this would be stretching it.

>
> Anyhow, if there are different sets, I could do something like:
>
> #define BADCHARS "\r\n\\"
> #define BADCHARS_CSV "\r\n"
>
> and then check for csv_mode, etc.
>
>> + #define BADCHARS "\r\n\\"
>>
>> Also, should we disable DELIMITER and NULL from sharing characters?

>
> That's on about line 916, post-patch:
>
> /* Don't allow the delimiter to appear in the null string. */
> if (strchr(cstate->null_print, cstate->delim[0]) != NULL)
> ereport(ERROR,
> (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
> errmsg("COPY delimiter must not appear in the NULL
> specification")));
>
> I suppose that a different error code might be The Right Thing™ here.
>


ERRCODE_WHAT WERE_YOU_THINKING ?

cheers

andrew



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

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
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
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 05:12 PM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com