HSQLDB to Firebird migration subtracted one day from all date values in tables - firebird

Using Libreoffice Base and was prompted to migrate to Firebird from HSQLDB. I had read up about this bug and ensured I had a backup of the original database before proceeding with the migration. It seems the date bug was the only issue with the migration.
What is the easiest way to fix the values? I have hundreds of lines to correct in multiple tables. Is there any way to execute some sort of Date + 1 day script on the date columns and call it a day, or am I doomed to manually change each row one by one?

Yes, it is exactly as simple as you wrote. To be sure you can use function DATEADD instead of addition.
update the_table set the_field = dateadd(1 day to the_field)

Related

Truncate datetimes by second for all queries, but keep milliseconds stored in Postgres

I'm trying to find a way to tell Postgres to truncate all datetime columns so that they are displayed and filtered by seconds (ignoring milliseconds).
I'm aware of the
date_trunc('second', my_date_field)
method, but do not want to do that for all datetime fields in every select and where clause that mentions them. Dates in the where clause need to also capture records with the granularity of seconds.
Ideally, I'd avoid stripping milliseconds from the data when it is stored. But then again, maybe this is the best way. I'd really like to avoid that data migration.
I can imagine Postgres having some kind of runtime configuration like this:
SET DATE_TRUNC 'seconds';
similar to how timezones are configured, but of course that doesn't work and I'm unable to find anything else in the docs. Do I need to write my own Postgres extension? Did someone already write this?

Postgres timestamp to date

I am building a map in CartoDB which uses Postgres. I'm simply trying to display my dates as: 10-16-2014 but, haven't been able to because Postgres includes an unneeded timestamp in every date column.
Should I alter the column to remove the timestamp or, is it simply a matter of a (correct) SELECT query? I can SELECT records from a date range no problem with:
SELECT * FROM mytable
WHERE myTableDate >= '2014-01-01' AND myTableDate < '2014-12-31'
However, my dates appear in my CartoDB maps as: 2014-10-16T00:00:00Z and I'm just trying to get the popups on my maps to read: 10-16-2014.
Any help would be appreciated - Thank you!
You are confusing storage with display.
Store a timestamp or date, depending on whethether you need time or not.
If you want formatted output, ask the database for formatted output with to_char, e.g.
SELECT col1, col2, to_char(col3, 'DD-MM-YY'), ... FROM ...;
See the PostgreSQL manual.
There is no way to set a user-specified date output format. Dates are always output in ISO format. If PostgreSQL let you specify other formats without changing the SQL query text it'd really confuse client drivers and applications that expect the date format the protocol specifies and get something entirely different.
You have two basic options.
1 Change the column from a timestamp to a date column.
2 Cast to date in your SQL query (i.e. mytimestamp::date works).
In general if this is a presentation issue, I don't usually think that is a good reason to muck around with the database structure. That's better handled by client-side processing or casting in an SQL query. On the other hand if the issue is a semantic one, then you may want to revisit your database structure.

LibreOffice date shift in PostgreSQL

I'm managing small PostgreSQL database. Recently I created new date field in one of tables. I'm working on pgAdminIII and everything is fine, but one of the users just reported that while working on LibreOffice all dates are shifted by 10 days to the past.
I just installed LibreOffice to check it and they are shifted on my copy too but by 9 days.
This is simple date field without any default value or constraints. All dates are before year 1900 (1400-1500).
In pgAdmin and console psql client everything is fine.
What can cause such an issue? How to fix that?
EDIT:
Problem occurs in table view only. I can access correct date via Tools > SQL... menu while viewing table data or creating query produces invalid results. It may be format conversion error (from Y-M-D to D.M.Y).

Format Hour in DB2?

Is there any way to display db2 Hour function with AM and PM?
select hour(TIMESTAMP) from ORDERS with ur
This will give out like 5,6,7 etc..
But i want AM/PM after the Hour time.
I'd like to Dislpay as 5AM,6AM,7AM. Is it possible in db2?
Use the TIME() and CHAR() functions:
SELECT CHAR(TIME(timestamp), USA)
FROM Orders
WITH UR
Although, honestly, you should be doing this type of formatting in the application layer, not the SQL Layer.
(Statement run on my local DB2 instance)
EDIT:
Sorry, I missed that part earlier. Going through the documentation has shown me a new function, VARCHAR_FORMAT(). Assuming you're on DB2 9.5, the following should grant you some form of what you're looking for:
SELECT VARCHAR_FORMAT(timestamp, 'HH12 AM')
FROM Orders
WITH UR
Unfortunately, I can't test this myself, as iSeries V6R1 doesn't support the HH12 flag (HH24 only, what?). Otherwise, you're going to have to parse it out yourself.

Can Perl DBIx::Class override the way a column is retrieved from the database?

I have never used DBIx::Class until today, so I'm completely new at it.
I'm not sure if this is possible or not, but basically I have a table in my SQLite database that has a timestamp column in it. The default value for the timestamp column is "CURRENT_TIMESTAMP". SQLite stores this in the GMT timezone, but my server is in the CDT timeszone.
My SQLite query to get the timestamp in the correct timezone is this:
select datetime(timestamp, 'localtime') from mytable where id=1;
I am wondering if it is possible in my DBIx schema for "MyTable" to force it to apply the datetime function every time it is retrieving the "timestamp" field from the database?
In the cookbook it looks like it is possible to do this when using the ->search() function, but I am wondering if it's possible to make it so if I'm using search(), find(), all(), find_or_new(), or any function that will pull this column from the database, it will apply the datetime() SQLite function to it?
DBIx::Class seems to have great documentation - I think I'm just so new at it I'm not finding the right places/things to search for.
Thanks in advance!
I've used InflateColumn::DateTime in this way and with a timestamp, and I can confirm it works, but I wonder if you have this backward.
If your column is in UTC, mark the column UTC, and then it should be a UTC time when you load it. Then when you set_timezone on the DateTime (presumably that would be an output issue - it's at output that you care it's locally zoned) you can set it to local time and it will make the necessary adjustment.