Re: question about efficiency

From: Stephan Szabo <sszabo(at)megazone23(dot)bigpanda(dot)com>
To: "Johnson, Shaunn" <SJohnson6(at)bcbsm(dot)com>
Cc: <pgsql-general(at)postgresql(dot)org>
Subject: Re: question about efficiency
Date: 2002-11-11 15:56:38
Message-ID: 20021111075331.K52103-100000@megazone23.bigpanda.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Mon, 11 Nov 2002, Johnson, Shaunn wrote:

> Howdy:
>
> Running PostgreSQL 7.2.1 on RedHat Linux 7.2.
>
> Have a question about a query and it's efficiency:
>
> One of the users created a query that looks like this:
>
> [snip]
> "create table dev_lbpclaimsum as
> SELECT
> claimsum2001.c_contract_num,
> claimsum2001.c_mbr_num,
> claimsum2001.c_proc_cd,
> claimsum2001.c_proc_mod,
> claimsum2001.d_from_dt,
> claimsum2001.d_thru_dt,
> claimsum2001.i_pd,
> claimsum2001.c_serv_prov
> FROM
> claimsum2001 a join dev_pb_proc b on a.c_proc_cd = substr
> (b.c_proc_cd,1,6)

This query is (afaik) illegal in plain SQL and for postgres assumes you
want a join with claimsum2001 as claimsum2001. See notice,
> psql:./jans_stuff.sql:14: NOTICE: Adding missing FROM-clause entry for
> table "claimsum2001"

It's basically converted it into a three way join.

> Can someone explain why there's a difference between using
> claimsum2001.(whatever) and a.(whatever)?

Once you alias claimsum2001 as a there isn't a table claimsum2001
in the query, but you're asking for columns from the non-existant
table in the select clause. PostgreSQL tries to be helpful by
adding a from entry for the table whereas it'd technically be illegal.

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message scott.marlowe 2002-11-11 16:08:39 Re: Stale Process
Previous Message Johnson, Shaunn 2002-11-11 15:38:56 question about efficiency