From: | Jon Lapham <lapham(at)extracta(dot)com(dot)br> |
---|---|
To: | Stephan Szabo <sszabo(at)megazone23(dot)bigpanda(dot)com> |
Cc: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: How to cast a char[] to varchar? |
Date: | 2002-01-07 18:03:31 |
Message-ID: | 3C39E2F3.3020301@extracta.com.br |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
Stephan Szabo wrote:
> On Mon, 7 Jan 2002, Jon Lapham wrote:
>
>
>>I have a column defined as "char(3)[]" which I would like to copy into a
>>different column defined as "varchar(255)".
>>
>>I've tried to cast the char(3)[] field using "CAST( ... as varchar)" but
>>I get an error message, "Cannot cast type '_bpchar' to 'varchar'".
>>
>>Any suggestions?
>>
>
> What are you trying to get out? You've got a char(3) array, what do you
> want the varchar to have in the end?
>
>
Assuming "category" is the char(3)[] column, and "cat2" is the desired
varchar(255) column, I would like the following:
main_v0_8=# select peopleid, category, cat2 from people where
peopleid=100010;
peopleid | category | cat2
----------+---------------+---------
100010 | {"col","dep"} | col dep
(1 row)
However, in the real database the char(3) array "category" may contain
anywhere from 0 to 10 items.
PS: It would be fine if the things in "cat2" contained the braces and
quotes, it does not need to be cleaned-up.
--
-**-*-*---*-*---*-*---*-----*-*-----*---*-*---*-----*-----*-*-----*---
Jon Lapham
Extracta Moléculas Naturais, Rio de Janeiro, Brasil
email: lapham(at)extracta(dot)com(dot)br web: http://www.extracta.com.br/
***-*--*----*-------*------------*--------------------*---------------
From | Date | Subject | |
---|---|---|---|
Next Message | Linh Luong | 2002-01-07 18:04:11 | Restart postgres in php as nobody |
Previous Message | Tom Lane | 2002-01-07 17:57:56 | Re: Turning off transactions completely. |