niXforums Forum Index
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   PreferencesPreferences   Log in to check your private messagesLog in to check your private messages   Log inLog in 
·  nixdoc.net ·  man pages ·  Linux HOWTOs ·  FreeBSD Tips ·  Forums
navigation Forum index » Databases » PostgreSQL
Casting from a domain
Post new topic   Reply to topic Page 1 of 1 [4 Posts] View previous topic :: View next topic
Author Message
Jim C. Nasby
*nix forums Guru Wannabe


Joined: 01 Mar 2005
Posts: 241

PostPosted: Fri Mar 04, 2005 5:49 pm    Post subject: Casting from a domain Reply with quote

I'm trying to create a seconds domain that is an interval 'mashed to
seconds' as I once saw Tom describe it.

decibel=# create domain rrs.seconds as double precision;
CREATE DOMAIN
decibel=# create cast (double precision as rrs.seconds) WITHOUT FUNCTION AS IMPLICIT;
CREATE CAST
decibel=# create function rrs.interval_to_seconds(interval) returns seconds as 'SELECT extract( EPOCH FROM $1 );' LANGUAGE SQL;
CREATE FUNCTION
decibel=# create cast (interval as rrs.seconds) WITH FUNCTION rrs.interval_to_seconds(interval) AS IMPLICIT;
CREATE CAST
decibel=# select cast('1 month'::interval AS seconds);
ERROR: cannot cast type interval to seconds

\dC shows that the cast is there, and rrs.interval_to_seconds works as
expected, and according to \df does return seconds.

Version is 7.4.5.
--
Jim C. Nasby, Database Consultant decibel@decibel.org
Give your computer some brain candy! www.distributed.net Team #1828

Windows: "Where do you want to go today?"
Linux: "Where do you want to go tomorrow?"
FreeBSD: "Are you guys coming, or what?"

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

http://archives.postgresql.org
Back to top
Richard Huxton
*nix forums Guru


Joined: 01 Mar 2005
Posts: 522

PostPosted: Fri Mar 04, 2005 6:47 pm    Post subject: Re: Casting from a domain Reply with quote

Jim C. Nasby wrote:
Quote:
decibel=# create cast (interval as rrs.seconds) WITH FUNCTION rrs.interval_to_seconds(interval) AS IMPLICIT;
^^^
decibel=# select cast('1 month'::interval AS seconds);
ERROR: cannot cast type interval to seconds

It's not a schema issue is it? I.E. the lack of "rrs."?

--
Richard Huxton
Archonet Ltd

---------------------------(end of broadcast)---------------------------
TIP 8: explain analyze is your friend
Back to top
Tom Lane
*nix forums Guru


Joined: 24 Mar 2005
Posts: 2070

PostPosted: Fri Mar 04, 2005 7:40 pm    Post subject: Re: Casting from a domain Reply with quote

"Jim C. Nasby" <decibel@decibel.org> writes:
Quote:
decibel=# create cast (interval as rrs.seconds) WITH FUNCTION rrs.interval_to_seconds(interval) AS IMPLICIT;
CREATE CAST
decibel=# select cast('1 month'::interval AS seconds);
ERROR: cannot cast type interval to seconds

Given the current coercion rules, we should probably disallow attempts
to define casts that involve domains. Casts are on base types. The
down-cast from a domain to its base type is hardwired, and the up-cast
from base type to domain is too (with invocation of any constraints
that may apply). Adding random user-defined casts to this would
probably just create confusion and ambiguity. In particular, this
was already meaningless:

decibel=# create domain rrs.seconds as double precision;
CREATE DOMAIN
decibel=# create cast (double precision as rrs.seconds) WITHOUT FUNCTION AS IMPLICIT;
CREATE CAST

since the presence of the cast might be thought to justify coercing
floats to "seconds" without invoking domain constraints.

regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 5: Have you checked our extensive FAQ?

http://www.postgresql.org/docs/faq
Back to top
Jim C. Nasby
*nix forums Guru Wannabe


Joined: 01 Mar 2005
Posts: 241

PostPosted: Fri Mar 04, 2005 9:47 pm    Post subject: Re: Casting from a domain Reply with quote

On Fri, Mar 04, 2005 at 03:40:17PM -0500, Tom Lane wrote:
Quote:
"Jim C. Nasby" <decibel@decibel.org> writes:
decibel=# create cast (interval as rrs.seconds) WITH FUNCTION rrs.interval_to_seconds(interval) AS IMPLICIT;
CREATE CAST
decibel=# select cast('1 month'::interval AS seconds);
ERROR: cannot cast type interval to seconds

Given the current coercion rules, we should probably disallow attempts
to define casts that involve domains. Casts are on base types. The
down-cast from a domain to its base type is hardwired, and the up-cast
from base type to domain is too (with invocation of any constraints
that may apply). Adding random user-defined casts to this would
probably just create confusion and ambiguity. In particular, this
was already meaningless:

decibel=# create domain rrs.seconds as double precision;
CREATE DOMAIN
decibel=# create cast (double precision as rrs.seconds) WITHOUT FUNCTION AS IMPLICIT;
CREATE CAST

since the presence of the cast might be thought to justify coercing
floats to "seconds" without invoking domain constraints.

Yeah, I figured it was probably an issue with it being a domain. I was
looking for a way to do this without the extra work involved in defining
a full-blown type. I guess the good news is I should be able to re-use
all the double-precision functions and what-not for 'seconds'.

BTW, is there a reason 'double' isn't an alias for 'double precision'?
I'm pretty sure every other database I've used (other than oracle of
course) supports 'double'. " precision" is just too much extra typing
after all... Razz
--
Jim C. Nasby, Database Consultant decibel@decibel.org
Give your computer some brain candy! www.distributed.net Team #1828

Windows: "Where do you want to go today?"
Linux: "Where do you want to go tomorrow?"
FreeBSD: "Are you guys coming, or what?"

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

http://archives.postgresql.org
Back to top
Google

Back to top
Display posts from previous:   
Post new topic   Reply to topic Page 1 of 1 [4 Posts] View previous topic :: View next topic
The time now is Fri Jan 09, 2009 2:43 am | All times are GMT
navigation Forum index » Databases » PostgreSQL
Jump to:  

Similar Topics
Topic Author Forum Replies Last Post
No new posts Postfix relay to specific domain and to everybody else golgotha Postfix 0 Thu Oct 23, 2008 11:11 pm
No new posts Need to convert domain name before relaying jfinn Postfix 0 Tue Sep 16, 2008 12:51 pm
No new posts Filtering internal mail and forwarding to another domain fmaa1 Postfix 0 Wed Apr 30, 2008 12:50 pm
No new posts Postfix sending problem for local domain remote email monkey_magix Postfix 0 Mon Sep 10, 2007 10:17 am
No new posts Newbie question: How to forward a domain to a mailbox? leei Postfix 0 Fri Aug 24, 2007 4:55 pm

Live mortgage rates | Loans | Bankruptcy | Adverse Credit Remortgage | Mortgages
Copyright © 2004-2005 DeniX Solutions SRL
 
Other DeniX Solutions sites: Unix/Linux blog |  electronics forum |  medicine forum |  science forum | 
Privacy Policy


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.1402s ][ Queries: 16 (0.0464s) ][ GZIP on - Debug on ]