Re: Trying to update a box data type column

From: Michael Fuhr <mike(at)fuhr(dot)org>
To: Yonatan Ben-Nes <yonatan(at)epoch(dot)co(dot)il>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Trying to update a box data type column
Date: 2006-05-23 17:36:44
Message-ID: 20060523173644.GA52042@winnie.fuhr.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Tue, May 23, 2006 at 07:13:08PM +0200, Yonatan Ben-Nes wrote:
> UPDATE treecategory SET box =
> '('||"nleft"||','||"nright"||'),('||"nleft"||','||"nright"||')';
> ERROR: column "box" is of type box but expression is of type text
> HINT: You will need to rewrite or cast the expression.
>
> And if I try to cast type text to box I get:
> ERROR: cannot cast type text to box

Try this:

UPDATE treecategory SET box = box(point(nleft, nright), point(nleft, nright));

A hackish way to convert types where no cast exists is to use the
source and destination types' I/O functions:

UPDATE treecategory SET box = box_in(textout( <text expression> ));

You could create a function that implicitly does the above conversion:

CREATE FUNCTION box(text) RETURNS box AS $$
BEGIN
RETURN $1;
END;
$$ LANGUAGE plpgsql IMMUTABLE STRICT;

UPDATE treecategory SET box = box( <text expression> );

If you need to perform such conversions regularly then you could
use CREATE CAST to create a cast between the types.

--
Michael Fuhr

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2006-05-23 17:40:41 Re: Trying to update a box data type column
Previous Message Yonatan Ben-Nes 2006-05-23 17:13:08 Trying to update a box data type column