Getting Table name from Field

49 views
Skip to first unread message

loke...@gmail.com

unread,
Dec 21, 2015, 3:11:08 PM12/21/15
to jOOQ User Group
Hi,

From a join query result record, how could I know which field belongs to which table? Or, how do I group the fields by table name? 

Thanks,
Lokesh

Lukas Eder

unread,
Dec 22, 2015, 4:08:25 AM12/22/15
to jooq...@googlegroups.com
Hi Lokesh,

This would depend on the concrete query that you're running.

- If you're selecting generated TableField instances, then TableField.getTable() can be used
- If you're selecting plain SQL Fields or aliased fields, or any kind of expression, you'll have to manage yourself.

What does the query you're running look like?

Cheers,
Lukas



--
You received this message because you are subscribed to the Google Groups "jOOQ User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jooq-user+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

loke...@gmail.com

unread,
Dec 22, 2015, 10:45:41 PM12/22/15
to jOOQ User Group
Hi Lukas,

Thanks for following up. The query that I am running looks like this:

select().from("A").join("B").on(some condition)

I tried response as ResultSet also. It is giving me empty table name for all the fields.
BTW, if both tables A and B have one attribute with same name e.g.  "xxx" what would the response as map (attribute name to value) contain? 

Thanks,
Lokesh

Lukas Eder

unread,
Dec 23, 2015, 3:26:40 AM12/23/15
to jooq...@googlegroups.com
Hi Lokesh,

Thanks for the details.

Unfortunately, not all databases / JDBC drivers report table (and schema) names with ResultSetMetaData (e.g. Oracle and SQL Server don't). What database are you using?

If those are present, then jOOQ will read those and associate them with the individual fields that are reported in the Result. The fields will then be of the form:

DSL.field(name(schemaName, tableName, columnName), dataType);

The table name can be extracted by calling toString() and then doing string manipulation. There is currently no other way.

BTW, if both tables A and B have one attribute with same name e.g.  "xxx" what would the response as map (attribute name to value) contain? 

jOOQ's Result will contain two Field references with the same column name "xxx". This is OK for jOOQ, because internally, all operations are column index based, not column name base. If you want to read the right column from a jOOQ Result, and there is no table name information available to disambiguate the names, you'll have to either:

- Access columns by index
- Explicitly alias such columns in your original query.

I hope this helps.

Let me know if you have any additional questions
Lukas

vishwa...@gmail.com

unread,
Jul 25, 2017, 4:46:00 AM7/25/17
to jOOQ User Group
Hi,

calling Field's tostring() function creates performance problems. Attached the call stack that has the split up as well. Can you give me suggestion ? 

Thanks,
Vishwanath
perf.png
Reply all
Reply to author
Forward
0 new messages