By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,374 Members | 2,014 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,374 IT Pros & Developers. It's quick & easy.

Casting Point to Text

P: n/a

Hi all,

PG 7.4 beta4 (not had a chance to upgrade yet :-(

how do i cast something of type point to text?

db=# select '(1,2)'::point::text;
ERROR: cannot cast type point to text
db=# select text('(1,2)'::point);
ERROR: function text(point) does not exist
HINT: No function matches the given name and argument types. You may need to
add explicit type casts.

the only way i have been able to achieve it is to write a plpgsql function:
create function to_s(point) returns text as 'begin return $1; end;' language
plpgsql;

while this appears to work fine - I am wondering if I am missing something
fundamental - specifically whether or not there is an inbuilt way to do it
(which I guess there must be for the plpgsql function to work)?

thanks for your help
Martin
---------------------------(end of broadcast)---------------------------
TIP 8: explain analyze is your friend

Nov 12 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Martin Hart <ma****@zsdfherg.com> writes:
db=# select '(1,2)'::point::text;
ERROR: cannot cast type point to text the only way i have been able to achieve it is to write a plpgsql function:
while this appears to work fine - I am wondering if I am missing something
fundamental - specifically whether or not there is an inbuilt way to do it
(which I guess there must be for the plpgsql function to work)?


plpgsql is effectively doing

regression=# select textin(point_out('(1,2)'::point));
textin
--------
(1,2)
(1 row)

There is not a one-step cast function for this. (Not for any
fundamental reason, just a lack of round tuits.)

regards, tom lane

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

http://archives.postgresql.org

Nov 12 '05 #2

P: n/a
On Tuesday 09 December 2003 14:56, Tom Lane wrote:
plpgsql is effectively doing

regression=# select textin(point_out('(1,2)'::point));
textin
--------
(1,2)
(1 row)

There is not a one-step cast function for this. (Not for any
fundamental reason, just a lack of round tuits.)

regards, tom lane


thanks for the info. Is this the sort of thing that the core team will accept
patches for (missing casts etc)? If so, and it is easy enough for me to get
my head round :-) I'll work on it.

Cheers,
Martin
---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
(send "unregister YourEmailAddressHere" to ma*******@postgresql.org)

Nov 12 '05 #3

P: n/a
Martin Hart <ma****@zsdfherg.com> writes:
thanks for the info. Is this the sort of thing that the core team will accept
patches for (missing casts etc)? If so, and it is easy enough for me to get
my head round :-) I'll work on it.


Go for it. There might be some resistance if you proposed adding
implicit or automatic casts, but I can't see anyone objecting to
providing more explicit casts.

regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
(send "unregister YourEmailAddressHere" to ma*******@postgresql.org)

Nov 12 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.