clkao / plv8js-migrated

Automatically exported from code.google.com/p/plv8js
Other
0 stars 0 forks source link

"date" column type returns "timestamp" style string. #62

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Create a table with a field of type "date" and a couple of records.
2. Select that field from the table manually in psql. 
3. Run plv8.execute('SELECT date_field FROM some_table'); 

What is the expected output? What do you see instead?
From psql: 'YYYY-MM-DD'
From plv8 functions: 'YYYY-MM-DDT00:00:00.000Z'

I am not sure if this is desirable as you get different output selecting the 
same fields with plv8 then you do otherwise. 

Original issue reported on code.google.com by Nitro...@gmail.com on 28 Mar 2013 at 2:11

GoogleCodeExporter commented 9 years ago
JS doesn't have "date" time but does have Date which corresponds to timestamp 
in postgres.  And the format of date/timestamp in postgres depends on the 
datestyle GUC and I know it's sometimes confusing.  If you really need a 
consistent date format, you are encouraged to use to_char().

Does this answer your question?

Original comment by umi.tan...@gmail.com on 29 Mar 2013 at 5:32

GoogleCodeExporter commented 9 years ago
Yes I understood that going in, my question is does it make sense to have plv8 
output something different than what postgres's datestyle is set to? Would 
having any date column output a string that matches the datestyle instead of a 
Js Date object make more sense or no?

Original comment by Nitro...@gmail.com on 29 Mar 2013 at 4:33

GoogleCodeExporter commented 9 years ago
I am still not sure what you mean by "output".  plv8.execute just returns JS 
Date object and the output depends on what you do on it.  If you call 
toString() on the Date object it'll look different from the standard postgres' 
date string format and it is expected as well as I don't see much we can do.

Original comment by umi.tan...@gmail.com on 1 Apr 2013 at 6:18

GoogleCodeExporter commented 9 years ago
Exactly thats my point, does it make more sense to have plv8.execute return a 
string object that matches the date style set in postgres for the date column 
instead of a JS Date object? 

You end up with oddities like '2012-01-20' is returned as 
'2012-01-19-00:00:00.000Z' which does not necessarily seem desirable to me, 
although I could be in the wrong (I understand they are the same just the 
second can be confusing and almost always requires some sort of reformatting to 
work with)

Original comment by Nitro...@gmail.com on 1 Apr 2013 at 2:23

GoogleCodeExporter commented 9 years ago
You are comparing apples and oranges.  And it is designed in plv8 from the 
beginning that plv8.execute should return JS-friendly object instead of plan 
string, which was proved to be not a desirable idea in other PLs.

Original comment by umi.tan...@gmail.com on 2 Apr 2013 at 5:49

GoogleCodeExporter commented 9 years ago
Please re-open this issue if you still have concerns.

Original comment by umi.tan...@gmail.com on 9 Apr 2013 at 7:32