Sqlline date format

20 views
Skip to first unread message

vitalii...@gmail.com

unread,
Aug 21, 2017, 11:02:41 AM8/21/17
to sqlline-dev
Hi all!

SqlLine uses toString() approach for showing a lot of datatypes.
https://github.com/julianhyde/sqlline/blob/master/src/main/java/sqlline/Rows.java#L183
Is it a good idea to rely on toString() for date-time types?

Dates are very locale-dependent. But toString() hardcodes the format. And the display of a date as a string couldn't be controlled by the client.
The similar to numeric data types (NumberFormat#format()), DateFormat could be used.

If it is a good idea I will open an issue here:
https://github.com/julianhyde/sqlline/issues

Julian Hyde

unread,
Aug 21, 2017, 2:56:36 PM8/21/17
to vitalii...@gmail.com, sqlline-dev
Your question has an incorrect assumption. sqlline does not call
Object.toString() on the value. It calls ResultSet.getString(int) on
the column. There is a lot of difference, especially in dateTime
scenarios. Consider TIMESTAMP. SQL TIMESTAMP values do not contain a
time zone, but java.sql.Timestamp values are implicitly based on the
UTC epoch and are printed in the local timezone. Thus,
rs.getObject(i).toString() or rs.getTimestamp(i).toString() will
produce a different string than rs.getString(i).

That said, being able to choose formats for particular columns or
particular data types would be really useful.

Maybe we could do something similar to SQL*Plus: you can associate a
formatter with a particular column alias using the COLUMN command[1].

Julian

[1] https://docs.oracle.com/cd/B19306_01/server.102/b14357/ch6.htm
> --
> You received this message because you are subscribed to the Google Groups
> "sqlline-dev" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to sqlline-dev...@googlegroups.com.
> To post to this group, send email to sqlli...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/sqlline-dev/5a887ffe-b3aa-462b-be7c-f3948a70dbea%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Vitalii Diravka

unread,
Aug 22, 2017, 6:20:08 AM8/22/17
to sqlline-dev
Sorry for being inaccurate. I didn't want to compare rs.getObject().toString() with rs.getString(i).
I only meant that implementation of rs.getString() assume using of toString() without any chance to use custom format of output.

To associate a formatter with particular column alias using the COLUMN command looks useful.
But is an acceptable the way (similar to numberFormatter) to use SqlLineOpts and loading properties?

Julian Hyde

unread,
Aug 22, 2017, 11:01:09 AM8/22/17
to Vitalii Diravka, sqlline-dev
Adding dateFormat, timeFormat, timestampFormat like numberFormat makes sense.

If you submit a pull request, please be sure to update the help, the manual, and add unit tests.

Julian


Reply all
Reply to author
Forward
0 new messages