MySQLdb and column names

B

beef

Hello all,

I am using MySQLdb 1.2.2 and have a question about the construction of
the dictionary keys of a result set.

Here is an example query, from which you may intuit some of the
structure of the tables:

SELECT
shots.*,
users.*,
sequences.*,
jobs.*
FROM
shots
LEFT JOIN
users ON users.id=shots.user_id
INNER JOIN
sequences ON sequences.id=shots.sequence_id
INNER JOIN
jobs AS j ON j.id=sequences.job_id
WHERE
shots.id=%s

1. The 'users' table has a column named 'id', as do all the other
tables.
2. I define my cursor as a 'DictCursor' so that my results are
dictionaries
3. The 'shots' id has the key name of 'id', while all the -other-
'id's have key names of the form: "<TABLE>.id"

I would prefer to have the key names consistent, so that event the
"shots" fields have key names of the form "<TABLE>.id"

Is this possible?

Thanks in advance!
 
B

beef

change:
I would prefer to have the key names consistent, so that event the

to:
I would prefer to have the key names consistent, so that *even* the
 
D

Dennis Lee Bieber

SELECT
shots.*,
users.*,
sequences.*,
jobs.*
FROM
shots
LEFT JOIN
users ON users.id=shots.user_id
INNER JOIN
sequences ON sequences.id=shots.sequence_id
INNER JOIN
jobs AS j ON j.id=sequences.job_id
WHERE
shots.id=%s

3. The 'shots' id has the key name of 'id', while all the -other-
'id's have key names of the form: "<TABLE>.id"
The <TABLE> prefix is probably being used when the query processor
discovers that there are duplicate field names. IE, it is just
processing the table descriptions from left to right, and when a
subsequent table has the same field name as one that has already been
used, it prefaces the second (third, ...) with the source table.
I would prefer to have the key names consistent, so that event the
"shots" fields have key names of the form "<TABLE>.id"
Suggest, first step, do NOT use "table.*" notation, but rather
explicitly list the fields you want from each table, in the order you
want them. That, alone, might add the table names to all fields, though
I suspect not -- so use an "as xxx" renaming of the fields you need to
differentiate.

... shots.id as "shots.id", other.fields, other.tables...
--
Wulfraed Dennis Lee Bieber KD6MOG
(e-mail address removed) (e-mail address removed)
HTTP://wlfraed.home.netcom.com/
(Bestiaria Support Staff: (e-mail address removed))
HTTP://www.bestiaria.com/
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,567
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top