X-Original-To: pgsql-interfaces@postgresql.org Received: from candle.pha.pa.us (momjian.navpoint.com [207.106.42.251]) by postgresql.org (Postfix) with ESMTP id BCF59475CA9 for ; Thu, 20 Mar 2003 13:04:11 -0500 (EST) Received: (from pgman@localhost) by candle.pha.pa.us (8.11.6/8.10.1) id h2KI43b23863; Thu, 20 Mar 2003 13:04:03 -0500 (EST) From: Bruce Momjian Message-Id: <200303201804.h2KI43b23863@candle.pha.pa.us> Subject: Re: I want to send comments to the backend! In-Reply-To: <24626.1048181454@sss.pgh.pa.us> To: Tom Lane Date: Thu, 20 Mar 2003 13:04:03 -0500 (EST) Cc: =?ISO-8859-1?Q?Gerhard_H=E4ring?= , pgsql-interfaces@postgresql.org X-Mailer: ELM [version 2.4ME+ PL99 (25)] MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=US-ASCII X-Archive-Number: 200303/102 X-Sequence-Number: 3851 Tom Lane wrote: > Bruce Momjian writes: > > Yes, I see that now. res is NULL and PQresultStatus() is returning > > PGRES_NONFATAL_ERROR. What is strange is that "" and "\n" both return > > an OK result, so I am trying to figure out why comments are different. > > The backend special-cases an input string that contains only whitespace > (look in postgres.c). The special case doesn't apply here, though. > > >> Perhaps PGRES_EMPTY_QUERY would be more appropriate? Not sure where in > >> the chain would be best to change the behavior, though. > > > Yes. > > Well, we could change the backend --- but that would be a nontrivial > change, and to tell you the truth I think the special response for empty > query is a wart on the protocol anyhow. In the long run I'd rather get > rid of it. Yes, I see that now: if (strspn(parser_input->data, " \t\r\n") == parser_input->len) > Or we could change PQexec to return a PGRES_EMPTY_QUERY result if it > gets nothing back from the backend except ReadyForQuery. Question is, > does that create the possibility of masking error conditions? > > Or we could just change PQresultStatus to return PGRES_EMPTY_QUERY for > a null input. Attractive 'cause it's a one-line change, but I think it > really does create the possibility of masking errors --- application > programmer errors, mostly. Could we change the backend to return NullCommand() if the query string was empty, rather than checking for whitespace directly? I thought the whitespace test was there only as a performance hack. In fact, the comment in postgres.c says that: * if there is nothing in the input buffer, don't * bother trying to parse and execute anything; just * send back a quick NullCommand response. In pg_exec_query_string(), if nothing is processed, we can do the call there. or course assuming destination is correct? -- 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