dbTalk Databases Forums  

Re: Newbie problems with date functions

comp.databases.postgresql comp.databases.postgresql


Discuss Re: Newbie problems with date functions in the comp.databases.postgresql forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Armin Saul
 
Posts: n/a

Default Re: Newbie problems with date functions - 10-25-2008 , 11:45 AM






Björn Keil schrieb:
Quote:
Hello,

I've been trying create a little database for some statistic stuff and
decided to use PostgreSQL instead of the more familiar MySQL for it.
However, it seems I have a typcial newbie problem and don't know what
it expects of. Here is the table (sorry for the German columns, wanted
to test how well it gets along with German umlauts):

CREATE TABLE kurse (
tag date PRIMARY KEY,
eröffnung numeric(7, 2) NOT NULL,
höchst numeric(7, 2) NOT NULL,
niedrigst numeric(7, 2) NOT NULL,
schluss numeric(7, 2) NOT NULL,
menge integer DEFAULT 0 NOT NULL CONSTRAINT keine_negative_menge CHECK
(menge >= 0)
);

and here is the request:

bjoern@schatten:~$ LANG=C psql -c "SELECT date_trunk('month', tag),
avg(schluss) FROM kurse GROUP BY date_trunk('month', tag) ORDER BY
date_trunk('month', tag)" DAX
FEHLER: Funktion date_trunk(unknown, date) existiert nicht
LINE 1: SELECT date_trunk('month', tag), avg(schluss) FROM kurse GRO...
^
HINT: Keine Funktion stimmt mit dem angegebenen Namen und den
Argumenttypen überein. Sie müssen möglicherweise ausdrückliche
Typumwandlungen hinzufügen.

(means as much as the the function doesn't fit to the argument types)

However, the documentation says to date_trunk:
"source is a value expression of type timestamp or interval. (Values of
type date and time are cast automatically, to timestamp or interval
respectively.)"

So ... why doesn't it cast the date column `tag' to a timestamp
automatically as it is said, and what can I do to fix it? I tried to
write TIMESTAMP in front of `tag' but that didn't work either.

Björn

The function is named "date_trunc".

postgres=# select date_trunc('month', TIMESTAMP '2008-10-11') as result;
result
---------------------
2008-10-01 00:00:00
(1 Zeile)

postgres=#

This is what I found inside the German documentation:

9.8.2. date_trunc

Die Funktion date_trunc entspricht in etwa der Funktion trunc für Zahlen.

date_trunc('feld', quelle)

quelle ist ein Wertausdruck vom Typ timestamp. (Werte vom Typ date und
time werden automatisch umgewandelt.) feld bestimmt, auf welche
Genauigkeit der Wert abgeschnitten werden soll. Der Rückgabewert ist vom
Typ timestamp, wobei alle Felder, die kleiner als das angegebene sind,
auf null gesetzt sind (oder eins, bei Tag und Monat).

Gültige Werte für feld sind:

microseconds
milliseconds
second
minute
hour
day
month
year
decade
century
millennium

Beispiele:

SELECT date_trunc('hour', TIMESTAMP '2001-02-16 20:38:40');
Ergebnis: 2001-02-16 20:00:00+00

SELECT date_trunc('year', TIMESTAMP '2001-02-16 20:38:40');
Ergebnis: 2001-01-01 00:00:00+00

Regards

Armin


Reply With Quote
  #2  
Old   
Armin Saul
 
Posts: n/a

Default Re: Newbie problems with date functions - 10-25-2008 , 11:45 AM






Björn Keil schrieb:
Quote:
Hello,

I've been trying create a little database for some statistic stuff and
decided to use PostgreSQL instead of the more familiar MySQL for it.
However, it seems I have a typcial newbie problem and don't know what
it expects of. Here is the table (sorry for the German columns, wanted
to test how well it gets along with German umlauts):

CREATE TABLE kurse (
tag date PRIMARY KEY,
eröffnung numeric(7, 2) NOT NULL,
höchst numeric(7, 2) NOT NULL,
niedrigst numeric(7, 2) NOT NULL,
schluss numeric(7, 2) NOT NULL,
menge integer DEFAULT 0 NOT NULL CONSTRAINT keine_negative_menge CHECK
(menge >= 0)
);

and here is the request:

bjoern@schatten:~$ LANG=C psql -c "SELECT date_trunk('month', tag),
avg(schluss) FROM kurse GROUP BY date_trunk('month', tag) ORDER BY
date_trunk('month', tag)" DAX
FEHLER: Funktion date_trunk(unknown, date) existiert nicht
LINE 1: SELECT date_trunk('month', tag), avg(schluss) FROM kurse GRO...
^
HINT: Keine Funktion stimmt mit dem angegebenen Namen und den
Argumenttypen überein. Sie müssen möglicherweise ausdrückliche
Typumwandlungen hinzufügen.

(means as much as the the function doesn't fit to the argument types)

However, the documentation says to date_trunk:
"source is a value expression of type timestamp or interval. (Values of
type date and time are cast automatically, to timestamp or interval
respectively.)"

So ... why doesn't it cast the date column `tag' to a timestamp
automatically as it is said, and what can I do to fix it? I tried to
write TIMESTAMP in front of `tag' but that didn't work either.

Björn

The function is named "date_trunc".

postgres=# select date_trunc('month', TIMESTAMP '2008-10-11') as result;
result
---------------------
2008-10-01 00:00:00
(1 Zeile)

postgres=#

This is what I found inside the German documentation:

9.8.2. date_trunc

Die Funktion date_trunc entspricht in etwa der Funktion trunc für Zahlen.

date_trunc('feld', quelle)

quelle ist ein Wertausdruck vom Typ timestamp. (Werte vom Typ date und
time werden automatisch umgewandelt.) feld bestimmt, auf welche
Genauigkeit der Wert abgeschnitten werden soll. Der Rückgabewert ist vom
Typ timestamp, wobei alle Felder, die kleiner als das angegebene sind,
auf null gesetzt sind (oder eins, bei Tag und Monat).

Gültige Werte für feld sind:

microseconds
milliseconds
second
minute
hour
day
month
year
decade
century
millennium

Beispiele:

SELECT date_trunc('hour', TIMESTAMP '2001-02-16 20:38:40');
Ergebnis: 2001-02-16 20:00:00+00

SELECT date_trunc('year', TIMESTAMP '2001-02-16 20:38:40');
Ergebnis: 2001-01-01 00:00:00+00

Regards

Armin


Reply With Quote
  #3  
Old   
Armin Saul
 
Posts: n/a

Default Re: Newbie problems with date functions - 10-25-2008 , 11:45 AM



Björn Keil schrieb:
Quote:
Hello,

I've been trying create a little database for some statistic stuff and
decided to use PostgreSQL instead of the more familiar MySQL for it.
However, it seems I have a typcial newbie problem and don't know what
it expects of. Here is the table (sorry for the German columns, wanted
to test how well it gets along with German umlauts):

CREATE TABLE kurse (
tag date PRIMARY KEY,
eröffnung numeric(7, 2) NOT NULL,
höchst numeric(7, 2) NOT NULL,
niedrigst numeric(7, 2) NOT NULL,
schluss numeric(7, 2) NOT NULL,
menge integer DEFAULT 0 NOT NULL CONSTRAINT keine_negative_menge CHECK
(menge >= 0)
);

and here is the request:

bjoern@schatten:~$ LANG=C psql -c "SELECT date_trunk('month', tag),
avg(schluss) FROM kurse GROUP BY date_trunk('month', tag) ORDER BY
date_trunk('month', tag)" DAX
FEHLER: Funktion date_trunk(unknown, date) existiert nicht
LINE 1: SELECT date_trunk('month', tag), avg(schluss) FROM kurse GRO...
^
HINT: Keine Funktion stimmt mit dem angegebenen Namen und den
Argumenttypen überein. Sie müssen möglicherweise ausdrückliche
Typumwandlungen hinzufügen.

(means as much as the the function doesn't fit to the argument types)

However, the documentation says to date_trunk:
"source is a value expression of type timestamp or interval. (Values of
type date and time are cast automatically, to timestamp or interval
respectively.)"

So ... why doesn't it cast the date column `tag' to a timestamp
automatically as it is said, and what can I do to fix it? I tried to
write TIMESTAMP in front of `tag' but that didn't work either.

Björn

The function is named "date_trunc".

postgres=# select date_trunc('month', TIMESTAMP '2008-10-11') as result;
result
---------------------
2008-10-01 00:00:00
(1 Zeile)

postgres=#

This is what I found inside the German documentation:

9.8.2. date_trunc

Die Funktion date_trunc entspricht in etwa der Funktion trunc für Zahlen.

date_trunc('feld', quelle)

quelle ist ein Wertausdruck vom Typ timestamp. (Werte vom Typ date und
time werden automatisch umgewandelt.) feld bestimmt, auf welche
Genauigkeit der Wert abgeschnitten werden soll. Der Rückgabewert ist vom
Typ timestamp, wobei alle Felder, die kleiner als das angegebene sind,
auf null gesetzt sind (oder eins, bei Tag und Monat).

Gültige Werte für feld sind:

microseconds
milliseconds
second
minute
hour
day
month
year
decade
century
millennium

Beispiele:

SELECT date_trunc('hour', TIMESTAMP '2001-02-16 20:38:40');
Ergebnis: 2001-02-16 20:00:00+00

SELECT date_trunc('year', TIMESTAMP '2001-02-16 20:38:40');
Ergebnis: 2001-01-01 00:00:00+00

Regards

Armin


Reply With Quote
  #4  
Old   
Armin Saul
 
Posts: n/a

Default Re: Newbie problems with date functions - 10-25-2008 , 11:45 AM



Björn Keil schrieb:
Quote:
Hello,

I've been trying create a little database for some statistic stuff and
decided to use PostgreSQL instead of the more familiar MySQL for it.
However, it seems I have a typcial newbie problem and don't know what
it expects of. Here is the table (sorry for the German columns, wanted
to test how well it gets along with German umlauts):

CREATE TABLE kurse (
tag date PRIMARY KEY,
eröffnung numeric(7, 2) NOT NULL,
höchst numeric(7, 2) NOT NULL,
niedrigst numeric(7, 2) NOT NULL,
schluss numeric(7, 2) NOT NULL,
menge integer DEFAULT 0 NOT NULL CONSTRAINT keine_negative_menge CHECK
(menge >= 0)
);

and here is the request:

bjoern@schatten:~$ LANG=C psql -c "SELECT date_trunk('month', tag),
avg(schluss) FROM kurse GROUP BY date_trunk('month', tag) ORDER BY
date_trunk('month', tag)" DAX
FEHLER: Funktion date_trunk(unknown, date) existiert nicht
LINE 1: SELECT date_trunk('month', tag), avg(schluss) FROM kurse GRO...
^
HINT: Keine Funktion stimmt mit dem angegebenen Namen und den
Argumenttypen überein. Sie müssen möglicherweise ausdrückliche
Typumwandlungen hinzufügen.

(means as much as the the function doesn't fit to the argument types)

However, the documentation says to date_trunk:
"source is a value expression of type timestamp or interval. (Values of
type date and time are cast automatically, to timestamp or interval
respectively.)"

So ... why doesn't it cast the date column `tag' to a timestamp
automatically as it is said, and what can I do to fix it? I tried to
write TIMESTAMP in front of `tag' but that didn't work either.

Björn

The function is named "date_trunc".

postgres=# select date_trunc('month', TIMESTAMP '2008-10-11') as result;
result
---------------------
2008-10-01 00:00:00
(1 Zeile)

postgres=#

This is what I found inside the German documentation:

9.8.2. date_trunc

Die Funktion date_trunc entspricht in etwa der Funktion trunc für Zahlen.

date_trunc('feld', quelle)

quelle ist ein Wertausdruck vom Typ timestamp. (Werte vom Typ date und
time werden automatisch umgewandelt.) feld bestimmt, auf welche
Genauigkeit der Wert abgeschnitten werden soll. Der Rückgabewert ist vom
Typ timestamp, wobei alle Felder, die kleiner als das angegebene sind,
auf null gesetzt sind (oder eins, bei Tag und Monat).

Gültige Werte für feld sind:

microseconds
milliseconds
second
minute
hour
day
month
year
decade
century
millennium

Beispiele:

SELECT date_trunc('hour', TIMESTAMP '2001-02-16 20:38:40');
Ergebnis: 2001-02-16 20:00:00+00

SELECT date_trunc('year', TIMESTAMP '2001-02-16 20:38:40');
Ergebnis: 2001-01-01 00:00:00+00

Regards

Armin


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.