Thread: libpq:Find Table Name

libpq:Find Table Name

From
Adam Pigg
Date:
Hi

Am currently writing (or trying to at least) a postgresql driver for the 
koffice app kexi.

The driver requires that i subclass some kexi classes, one being a class that 
represents a field.

I know the SQL statement used to generate the result and for each field inthe 
result i create an object.  However, one property of the object is the table 
name for the field.  Other properties require that i know the table name, eg 
given the table and field names i can query the system catalogs to get things 
like contraints.

In the my_sql c library, the result (tuble) structure contains a filed 
structure that contains the table name that the particular field originated 
in, but libpq doesnt seem to have any similar kind of functionality (and i 
have looked a lot i think)

Has anyone any suggestions on how i can achieve getting the table name for a 
filed in a result without having to parse the sql statement (which i dont 
think wold be easy).

Regards

-- 
adampigg.9p.org.uk
adam@piggz.fsnet.co.uk
adam@adampigg.9p.org.uk



Re: libpq:Find Table Name

From
Christoph Haller
Date:
>
> Am currently writing (or trying to at least) a postgresql driver for
the
> koffice app kexi.
>
> The driver requires that i subclass some kexi classes, one being a
class that
> represents a field.
>
> I know the SQL statement used to generate the result and for each
field inthe
> result i create an object.  However, one property of the object is the
table
> name for the field.  Other properties require that i know the table
name, eg
> given the table and field names i can query the system catalogs to get
things
> like contraints.
>
> In the my_sql c library, the result (tuble) structure contains a filed

> structure that contains the table name that the particular field
originated
> in, but libpq doesnt seem to have any similar kind of functionality
(and i
> have looked a lot i think)
>
> Has anyone any suggestions on how i can achieve getting the table name
for a
> filed in a result without having to parse the sql statement (which i
dont
> think wold be easy).
>
I very much doubt there is such thing, because the result may come from
a complex join or a function. What does MySQL do when it cames to this?
I have no idea, but am pretty sure that's why there is no similar field
in libpq. And even parsing the query would win you nothing, because of
the reason above.
Regards, Christoph




Re: libpq:Find Table Name

From
Darko Prenosil
Date:
On Monday 14 July 2003 13:46, Christoph Haller wrote:
> > Am currently writing (or trying to at least) a postgresql driver for
>
> the
>
> > koffice app kexi.
> >
> > The driver requires that i subclass some kexi classes, one being a
>
> class that
>
> > represents a field.
> >
> > I know the SQL statement used to generate the result and for each
>
> field inthe
>
> > result i create an object.  However, one property of the object is the
>
> table
>
> > name for the field.  Other properties require that i know the table
>
> name, eg
>
> > given the table and field names i can query the system catalogs to get
>
> things
>
> > like contraints.
> >
> > In the my_sql c library, the result (tuble) structure contains a filed
> >
> > structure that contains the table name that the particular field
>
> originated
>
> > in, but libpq doesnt seem to have any similar kind of functionality
>
> (and i
>
> > have looked a lot i think)
> >
> > Has anyone any suggestions on how i can achieve getting the table name
>
> for a
>
> > filed in a result without having to parse the sql statement (which i
>
> dont
>
> > think wold be easy).
>
> I very much doubt there is such thing, because the result may come from
> a complex join or a function. What does MySQL do when it cames to this?
> I have no idea, but am pretty sure that's why there is no similar field
> in libpq. And even parsing the query would win you nothing, because of
> the reason above.
> Regards, Christoph
>
And this is not the only case when table name has no sense.
What if result column is "calculated", for example:table1.field1 * 2
not to mention join:table1.field1 * table2.field1

However, I think that parser has all this information, and the only way to do 
this right would be to get this information from parser, and fill the libpq 
result structure with needed data. Column names that have no sense could be 
marked as "unknown".

Hackers would know better, but I think that such change is not trivial.
If I remember well, Interbase has such feature.

Regards !



Re: libpq:Find Table Name

From
Tom Lane
Date:
Christoph Haller <ch@rodos.fzk.de> writes:
>> Has anyone any suggestions on how i can achieve getting the table name
>> for a
>> filed in a result without having to parse the sql statement (which i
>> dont
>> think wold be easy).
>> 
> I very much doubt there is such thing, because the result may come from
> a complex join or a function.

There is support for this in PG 7.4, in the form of providing the table
OID for a column (when it's determinable).
        regards, tom lane


Re: libpq:Find Table Name

From
"Darko Prenosil"
Date:
----- Original Message ----- 
From: "Tom Lane" <tgl@sss.pgh.pa.us>
To: "Christoph Haller" <ch@rodos.fzk.de>
Cc: <pgsql-interfaces@postgresql.org>; <adam@piggz.fsnet.co.uk>
Sent: Monday, July 14, 2003 4:48 PM
Subject: Re: [INTERFACES] libpq:Find Table Name 


> Christoph Haller <ch@rodos.fzk.de> writes:
> >> Has anyone any suggestions on how i can achieve getting the table name
> >> for a
> >> filed in a result without having to parse the sql statement (which i
> >> dont
> >> think wold be easy).
> >> 
> > I very much doubt there is such thing, because the result may come from
> > a complex join or a function.
> 
> There is support for this in PG 7.4, in the form of providing the table
> OID for a column (when it's determinable).
> 

Wow !!!
I should read changelogs more often !

Regards !



Re: libpq:Find Table Name

From
Adam Pigg
Date:
Excellent....can you point me to anymore info on this, i see that pg7.4 isnt 
even in beta yet, is this function available in cvs?

cheers

Adam Pigg

On Monday 14 July 2003 15:48, Tom Lane wrote:
> Christoph Haller <ch@rodos.fzk.de> writes:
> >> Has anyone any suggestions on how i can achieve getting the table name
> >> for a
> >> filed in a result without having to parse the sql statement (which i
> >> dont
> >> think wold be easy).
> >
> > I very much doubt there is such thing, because the result may come from
> > a complex join or a function.
>
> There is support for this in PG 7.4, in the form of providing the table
> OID for a column (when it's determinable).
>
>             regards, tom lane
>
> ---------------------------(end of broadcast)---------------------------
> TIP 3: 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

-- 
adampigg.9p.org.uk
adam@piggz.fsnet.co.uk
adam@adampigg.9p.org.uk



load database from ascii files

From
Xinyu Hua
Date:
Hi,all
I used the TPC-H database population tool DBgen and generated some ascii
files contain pipe-delimited load data for tables. How may I get these
data loaded to tables and create database in postgresql?
Thanks in advance.
Xinyu



Re: load database from ascii files

From
Robert Treat
Date:
On Fri, 2003-08-01 at 00:26, Xinyu Hua wrote:
> Hi,all
> I used the TPC-H database population tool DBgen and generated some ascii
> files contain pipe-delimited load data for tables. How may I get these
> data loaded to tables and create database in postgresql?
> Thanks in advance.
> Xinyu
>

If you have the tables created, I think you only need to do

COPY table FROM 'filename' WITH DELIMITER '|'

from inside psql and that should work.

Robert Treat
--
Build A Brighter Lamp :: Linux Apache {middleware} PostgreSQL


Re: load database from ascii files

From
markw@osdl.org
Date:
On  1 Aug, Robert Treat wrote:
> On Fri, 2003-08-01 at 00:26, Xinyu Hua wrote:
>> Hi,all
>> I used the TPC-H database population tool DBgen and generated some ascii
>> files contain pipe-delimited load data for tables. How may I get these
>> data loaded to tables and create database in postgresql?
>> Thanks in advance.
>> Xinyu
>>
>
> If you have the tables created, I think you only need to do
>
> COPY table FROM 'filename' WITH DELIMITER '|'
>
> from inside psql and that should work.
>
> Robert Treat

We have a TPC-H derivative, Database Test 3, that works with PostgreSQL
now, if you're interested in that.  You can find your way to it at:
    http://www.osdl.org/projects/performance/dbt3-page.html

It uses the dbgen tool and creates the database for you, as well as all
the query templates to the best we could port them to work with
PostgreSQL, and scripts to run a power and throughput test.

Mark