psql's is_select_command is naive

Lists: pgsql-hackers
From: Robert Haas <robertmhaas(at)gmail(dot)com>
To: pgsql-hackers(at)postgresql(dot)org
Subject: psql's is_select_command is naive
Date: 2010-05-27 02:09:22
Message-ID: AANLkTimMSbRbkpVNcv3DInY9i1DpsxznIgE6bz5CU2Xk@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

It knows that queries beginning with "select" or "values" are select
commands, but it seems not to be clued in about "table" and "with".

For now, we can probably get by with just adding those to the list of
things it checks for. But I wonder what we'll do about this if we
ever get CTEs for insert/update/delete statements... you'd have to
parse the whole darn thing to figure out whether it was WITH...SELECT
or WITH...INSERT or WITH...INSERT...RETURNING.

--
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise Postgres Company


From: Stephen Frost <sfrost(at)snowman(dot)net>
To: Robert Haas <robertmhaas(at)gmail(dot)com>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: psql's is_select_command is naive
Date: 2010-05-27 02:19:46
Message-ID: 20100527021946.GJ21875@tamriel.snowman.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

* Robert Haas (robertmhaas(at)gmail(dot)com) wrote:
> For now, we can probably get by with just adding those to the list of
> things it checks for. But I wonder what we'll do about this if we
> ever get CTEs for insert/update/delete statements... you'd have to
> parse the whole darn thing to figure out whether it was WITH...SELECT
> or WITH...INSERT or WITH...INSERT...RETURNING.

Would be nice if it could just ask the backend if it's planning to send
back some data. :)

Stephen


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Robert Haas <robertmhaas(at)gmail(dot)com>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: psql's is_select_command is naive
Date: 2010-05-27 02:35:13
Message-ID: 6701.1274927713@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Robert Haas <robertmhaas(at)gmail(dot)com> writes:
> It knows that queries beginning with "select" or "values" are select
> commands, but it seems not to be clued in about "table" and "with".

What we really ought to do IMO is throw out the entire current
implementation of fetch_count. If libpq exposed access to the
protocol-level fetch count, we could implement it without this
cursor kluge.

regards, tom lane


From: Robert Haas <robertmhaas(at)gmail(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: psql's is_select_command is naive
Date: 2010-05-27 02:38:34
Message-ID: AANLkTin_kW-nlZWEpF_X49RBtsc7sNEP_u-QwWz2zsDP@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Wed, May 26, 2010 at 10:35 PM, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
> Robert Haas <robertmhaas(at)gmail(dot)com> writes:
>> It knows that queries beginning with "select" or "values" are select
>> commands, but it seems not to be clued in about "table" and "with".
>
> What we really ought to do IMO is throw out the entire current
> implementation of fetch_count.  If libpq exposed access to the
> protocol-level fetch count, we could implement it without this
> cursor kluge.

I suspect that would make a lot of people very happy.

--
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise Postgres Company


From: Bruce Momjian <bruce(at)momjian(dot)us>
To: Robert Haas <robertmhaas(at)gmail(dot)com>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: psql's is_select_command is naive
Date: 2010-05-28 22:39:25
Message-ID: 201005282239.o4SMdP808532@momjian.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Robert Haas wrote:
> On Wed, May 26, 2010 at 10:35 PM, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
> > Robert Haas <robertmhaas(at)gmail(dot)com> writes:
> >> It knows that queries beginning with "select" or "values" are select
> >> commands, but it seems not to be clued in about "table" and "with".
> >
> > What we really ought to do IMO is throw out the entire current
> > implementation of fetch_count. ?If libpq exposed access to the
> > protocol-level fetch count, we could implement it without this
> > cursor kluge.
>
> I suspect that would make a lot of people very happy.

I have added the following TODO:

Fix FETCH_COUNT to handle SELECT ... INTO and WITH queries
* http://archives.postgresql.org/pgsql-hackers/2010-05/msg01565.php
* http://archives.postgresql.org/pgsql-bugs/2010-05/msg00192.php

--
Bruce Momjian <bruce(at)momjian(dot)us> http://momjian.us
EnterpriseDB http://enterprisedb.com