473,666 Members | 2,237 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

timeofday() and CAST

Greetings,

I was executing some queries when I discovered that 7.3.4's CAST is a
little different from 7.1.2 when working with timestamps. When working with
localized timestamps, I can't use CAST to convert a string for a timestamp
anymore. Please take a look in the following scripts.

#### PostgreSQL 7.1.2 ####

bxs=# SELECT timeofday();
timeofday
-------------------------------------
Thu Aug 21 09:58:57.975598 2003 BRT
(1 row)

bxs=# SELECT CAST(timeofday( ) AS timestamp);
?column?
---------------------------
2003-08-21 09:59:22.16-03
(1 row)
#### PostgreSQL 7.3.4 ####

bxs=# SELECT timeofday();
timeofday
-------------------------------------
Thu Aug 21 10:04:18.215420 2003 BRT
(1 row)

bxs=# SELECT CAST(timeofday( ) AS timestamp);
ERROR: Bad timestamp external representation 'Thu Aug 21 10:04:42.597819
2003 BRT'
bxs=#

bxs=# SELECT CAST('Thu Aug 21 10:04:27.203170 2003 BRT' AS timestamp);
ERROR: Bad timestamp external representation 'Thu Aug 21 10:04:27.203170
2003 BRT'

bxs=# SELECT CAST('Thu Aug 21 10:04:27.203170 2003' AS timestamp);
timestamp
---------------------------
2003-08-21 10:04:27.20317
(1 row)

Best regards

----------------------------------------------------------------------------
----
José Vilson de Mello de Farias
Software Engineer

Dígitro Tecnologia Ltda - www.digitro.com.br
APC - Customer Oriented Applications
E-mail: vi***********@d igitro.com.br
Tel.: +55 48 281 7158
ICQ 11866179
---------------------------(end of broadcast)---------------------------
TIP 5: Have you checked our extensive FAQ?

http://www.postgresql.org/docs/faqs/FAQ.html

Nov 11 '05 #1
2 5830
"Vilson farias" <vi***********@ digitro.com.br> writes:
#### PostgreSQL 7.3.4 #### bxs=# SELECT timeofday();
timeofday
-------------------------------------
Thu Aug 21 10:04:18.215420 2003 BRT
(1 row) bxs=# SELECT CAST(timeofday( ) AS timestamp);
ERROR: Bad timestamp external representation 'Thu Aug 21 10:04:42.597819
2003 BRT'
bxs=#


It's unhappy about "BRT", which is not a known timezone name. Not sure
why the earlier version didn't complain too.

regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 6: Have you searched our list archives?

http://archives.postgresql.org

Nov 11 '05 #2
On Thu, Aug 21, 2003 at 02:58:40PM -0300, Vilson farias wrote:
I've been taking a look at documentation about timezones (Appendix A/Time
Zone Abbreviations) and it seems that BRT is really missing in that list.
Isn't Brazil important/big enough to have at least BRT and BRST timezones
supported from PostgreSQL? IMHO maybe it's time for a more robust support
for timezones, because maybe more people from other countries are getting
the same problem in newer PostgreSQL releases, since timestamps from strings
are not so flexible as they were in older releases.


Hmm... I'm seeing Chile standard timezones, so it's not a matter of how
big the country is. However, in the table at
src/backend/utils/adt/datetime.c I'm seeing conflict between BST
(British Summer Time), BST (Brazil Standard Time) and BST (Bering
Standard Time), so they just picked one. However there's a timezone
called "BRA" that's apparently "Brazil Time".

I agree however that it's a pretty ugly bug that you can get a timezone
that the server won't accept back.

Maybe the bug is that src/backend/utils/adt/nabstime.c::tim eofday() uses
%Z instead of %z.

--
Alvaro Herrera (<alvherre[a]dcc.uchile.cl>)
"Thou shalt not follow the NULL pointer, for chaos and madness await
thee at its end." (2nd Commandment for C programmers)

---------------------------(end of broadcast)---------------------------
TIP 7: don't forget to increase your free space map settings

Nov 11 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
3579
by: Aaron W. West | last post by:
Fun with CAST! (Optimized SQLServerCentral script posts) I found some interesting "tricks" to convert binary to hexadecimal and back, which allow doing 4 or 8 at a time. Test code first: -- These two have the same output, other than the width: select dbo.ufn_vbintohexstr(0x123456789abcdef1234) select 0x123456789abcdef1234
1
1629
by: Pavel Stehule | last post by:
Hello In this version I can't convert returned value to time. timeofday() return text. I need convert to timestamp before. It is normal behavior? I expected timestamp as returned type. regards Pavel Stehule
0
1714
by: Jason Priebe | last post by:
I posted earlier with a very complex example. This simple one gets to the point much faster. timeofday() seems to behave inconsistently when the timezone is set with "GMT+X" notation. foo=> select cast(timeofday() as timestamp with time zone); set time zone 'GMT+4'; select cast(timeofday() as timestamp with time zone); timeofday ------------------------------- 2003-08-13 11:01:26.502064-04 (1 row)
4
10460
by: Ray | last post by:
When a single-bit bitfield that was formed from an enum is promoted/cast into an integer, does ANSI C say anything about whether that integer should be signed or unsigned? SGI IRIX cc thinks it is an unsigned integer, so I see a +1 if the bit is set. Microsoft VC++ thinks it's signed, so I see -1 if the bit is set. Ex. typedef enum {
17
2671
by: Hazz | last post by:
In this sample code of ownerdraw drawmode, why does the '(ComboBox) sender' line of code need to be there in this event handler? Isn't cboFont passed via the managed heap, not the stack, into this cboFont_DrawItem event handler? Why does it need to be cast? -hazz ,................. cboFont.Items.AddRange(FontFamily.Families); } private void cboFont_DrawItem(object sender,
5
3414
by: Nick Flandry | last post by:
I'm running into an Invalid Cast Exception on an ASP.NET application that runs fine in my development environment (Win2K server running IIS 5) and a test environment (also Win2K server running IIS 5), but fails on IIS 6 running on a Win2003 server. The web uses Pages derived from a custom class I wrote (which itself derives from Page) to provide some common functionality. The Page_Load handler the failing webpage starts out like this: ...
4
1735
by: Peter | last post by:
Hi I am using DateTime class and TimeOfDay.Hours attribute to return current time. It returns right value on two servers, but in one particular server it does not return right time. I checked that server's date/time setting and there everything is fine. Could someone tell, why on this server TimeOfDay.Hours do not return right value? I appreciate help of any kind Thanks Peter
6
4694
by: Rich | last post by:
Hello, I have a label in my app where I display time from a Timer contol like this: Private Sub Timer1_Tick(...) Handles Timer1.Tick lbl_Time.Text = TimeOfDay.ToString End Sub The display is 1/1/0001 10:00:01 AM
5
2358
by: Frederick Gotham | last post by:
Before I begin, here's a list of assumptions for this particular example: (1) unsigned int has no padding bits, and therefore no invalid bit- patterns or trap representations. (2) All types have the same alignment requirements. (3) sizeof(double) >= sizeof(unsigned) ===================================== We can cast from double to unsigned int as follows:
0
8440
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8355
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8781
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8550
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
5662
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4193
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4365
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2769
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2006
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.