Re: "unexpected" query behaviour after i change parser code

From: Robert Haas <robertmhaas(at)gmail(dot)com>
To: Mohammad Heykal Abdillah <heykal(dot)abdillah(at)gmail(dot)com>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: "unexpected" query behaviour after i change parser code
Date: 2010-05-22 18:42:25
Message-ID: AANLkTim79q7X9NUviYlW3iQhe8TFgMeV8sqVaAvDZAmc@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Sat, May 22, 2010 at 9:21 AM, Mohammad Heykal Abdillah
<heykal(dot)abdillah(at)gmail(dot)com> wrote:
> All,
>
> Lately i have play with "parser"-part. I was try to make valid query
> command without using "FROM clause", so far it's work.
>
> I know this modification will make all query that using "FROM clause"
> failed, for example "/df" command. But normal or simple "select
> statement" so far is work.
>
> Now before my question, this what i do to make query without FROM clause
> work :
> 1) change "src/backend/parser/gram.y" at "simple_select:" delete
> from_clause
> 2) change "src/backend/parser/parse_relation.c" at function
> warnAutoRange, comment or delete "if (!add_missing_from)" part and
> change the "else" above to "if (add_missing_from)".
>
> Ok this my test result to "customer" and "item" table :
> - select id_item,name from item;
> --> failed, because there is "from clause" (failed like i expected)
>
> - select item.id_item, item.name;
> --> work, like i expected
>
> - select id_item,name;
> --> failed, with error : column "id_item" does not exist (failed like i
> expected)
>
> - select item.id_item,customer.fname;
> --> work, the data not acurate though because there is no joined atribut
>
> - select item.id_item,customer.fname where item.id_item=customer.id;
> --> work, normaly
>
> - select item.id,item;
> --> work, the result was concanted in "item" column. (i expected this
> query was failed). Try many combination including using more than one
> table with previous test, the result always work ONLY IF i put
> "table_name.colId" first.
>
> My question :
> 1) Can someone explain why my last test it's work?

In standard PostgreSQL, "select item from item" is valid SQL. It
returns a single column whose value is a record containing all the
columns from the item table. I suspect something similar is happening
in your case.

> 2) Why PostgreSQL won't query my 3rd test?
> Considering my last test it's work.

I'm not sure which test you're referring to here, but all of your
results look like about what would happen with adding_missing_from
set. Which brings me to another point: I'm not really sure what
you're trying to accomplish with this modification, considering that
adding_missing_from sounds like it does about what you want, but
without breaking nearly as much stuff.

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

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Cédric Villemain 2010-05-22 20:53:49 Re: Specification for Trusted PLs?
Previous Message Tim Bunce 2010-05-22 18:07:59 Re: release notes