Skip to content

Conversation

@Mikulas
Copy link
Contributor

@Mikulas Mikulas commented Oct 28, 2015

Nextras\Dbal\QueryException: ERROR: invalid input syntax for type interval: "2015-10-28 11:22:42"
LINE 1: SELECT Now() <= '2015-10-28 11:22:42' + (INTERVAL '2 DAYS')

@Mikulas Mikulas changed the title drivers: fixed %dt with interval pg driver: fixed %dt with interval Oct 28, 2015
@Mikulas
Copy link
Contributor Author

Mikulas commented Oct 28, 2015

This should not introduce any bc break. Pg allows type cast nesting and timestamptz does not loose data

select '2015-11-27 11:49:36.002+02'::timestamptz::timestamptz 2015-11-27 10:49:36.002+01
@milo
Copy link

milo commented Oct 28, 2015

Opened Tester issue nette/tester#268.

@hrach
Copy link
Member

hrach commented Oct 29, 2015

SELECT Now() <= %dt::timestamptz + (INTERVAL '2 DAYS')

doesn't work?

@hrach
Copy link
Member

hrach commented Oct 29, 2015

I'm not sure, if passing parameters should automatically cast them. We may do the same for integers, booleans, ...

@Mikulas
Copy link
Contributor Author

Mikulas commented Oct 29, 2015

Not quite, this type cast does not loose any precision and is in fact the cast postgres would love to do internally, but does not have enough information about. The string could be a generic (even composite) type, but orm knows it's a simple ymd his format.

The cast is not strictly required in orm, but it never breaks anything and is very convenient.

@hrach
Copy link
Member

hrach commented Oct 29, 2015

Not quite, this type cast does not loose any precision

I do not claim it does.

but orm knows it's a simple ymd his format.

but we are in Dbal, not in ORM layer. Since Nextras ORM doesn't allow you to use interval expression and you always have to write it manually using dbal's interface, I still don't see the usecase even for Orm.

@Mikulas
Copy link
Contributor Author

Mikulas commented Oct 29, 2015

but we are in Dbal, not in ORM layer

I misspoke, dbal indeed, but the argument holds.

Nextras ORM doesn't allow you to use interval expression

Not a requirement, interval is simply the case I chose to put in test as it's afaik the most common case. The cast is required anywhere pg can't type cast it automatically.

Is there any negative effect of this change?

@hrach
Copy link
Member

hrach commented Oct 29, 2015

At least inconsitence. Also sql clutter.

We may do the same for integers, booleans

@JanTvrdik what do you think?

@Mikulas
Copy link
Contributor Author

Mikulas commented Oct 29, 2015

Fair point. I would obviously like to see this merged, but it's up to you.

Int and bool typecasts are either not required as dbal sends the correct type (eg %d => 1 or %b => false) or cannot be cast automatically by dbal (%s with 'false' => 'false'::bool => false)

@hrach hrach added feature and removed bug labels Oct 29, 2015
@hrach
Copy link
Member

hrach commented Oct 29, 2015

Could you provide your real-worl usecase, when you discovered such drawback?

@Mikulas
Copy link
Contributor Author

Mikulas commented Oct 29, 2015

Interval, complex query but the test case is the minimal version of that already. It would also be required for any function or operator that is defined for both string and a timestamp[tz]/date[time]/time.

@Mikulas
Copy link
Contributor Author

Mikulas commented Oct 29, 2015

Another way of thinking about it is that orm is currently relying on automatic type cast.

SELECT pg_typeof(timestamptz('2015-01-01 10:10:10')); -- timestamp with time zone SELECT pg_typeof('2015-01-01 10:10:10'); -- unknown 
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

change this to timestamp and I will merge this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That was original implementation. I choose to rebase it with this simply for it's semantic value: I interpret tz as the timezone is known (in contrast to timestamp, which might indicate a time from application in unknown tz).

Without the timezone specified in the format string, those are all equivalent (as in interchangeable)

select '2015-01-01 16:00:00'::timestamp; select '2015-01-01 16:00:00'::timestamptz::timestamp; select '2015-01-01 16:00:00'::timestamptz; select '2015-01-01 16:00:00'::timestamp::timestamptz;

but I wouldn't mind timestamp either; is there a reason you requested timestamp?

@Mikulas
Copy link
Contributor Author

Mikulas commented Nov 18, 2015

I'm ok if this does not get merged, but we will need Mikulas@d9c9245 anyway (that's why #16 is broken)

@hrach
Copy link
Member

hrach commented Nov 18, 2015

Sorry, I forget to fully think it out. I'm definitelly against timestampttz for both cases. If the behavior is the same as you pointed out, it doesn't make sence at all.

@hrach
Copy link
Member

hrach commented Nov 18, 2015

Oh no, seems that you still didn't understand the dbal approach :)) Please, keep timestamptz for %dt :)

@Mikulas
Copy link
Contributor Author

Mikulas commented Nov 24, 2015

Sorry, that makes no sense (to me, anyway). I rebased it, though.

edit: misclick

@Mikulas Mikulas closed this Nov 24, 2015
@Mikulas Mikulas reopened this Nov 24, 2015
hrach added a commit that referenced this pull request Nov 24, 2015
pg driver: fixed %dt with interval
@hrach hrach merged commit 83ef25d into nextras:master Nov 24, 2015
@hrach
Copy link
Member

hrach commented Nov 24, 2015

great! thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment