text -> char

From: Peter Stamfest <peter(dot)stamfest(at)eunet(dot)at>
To: pgsql-sql(at)postgresql(dot)org
Subject: text -> char
Date: 2000-02-12 23:57:04
Message-ID: Pine.LNX.4.10.10002130046150.1021-100000@peter.stamf.pr.at
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql


I want to extract portions of a TEXT column into a CHAR(8) column:

> create table one (descr text);
> create view two as select substr(descr, 2, 4) as d from one;
> \d two
View = two
Query = SELECT "substr"("one"."descr", '2'::"int4", '4'::"int4") AS
"d" FROM "one";
+-----------------------+------------------------------+-------+
| Field | Type | Length|
+-----------------------+------------------------------+-------+
| d | text | var |
+-----------------------+------------------------------+-------+

> create view three as select CAST(substr(descr, 2, 4) as char(8)) as
d from one;
> \d three
View = three
Query = SELECT "substr"("one"."descr", '2'::"int4", '4'::"int4") AS
"d" FROM "one";
+-----------------------+------------------------------+-------+
| Field | Type | Length|
+-----------------------+------------------------------+-------+
| d | text | var |
+-----------------------+------------------------------+-------+

SELECT INTO behaves the same way. It seems impossible to cast a TEXT into
a CHAR.

The char() function works neither:

> create view four as select char(substr(descr, 2, 4)) as d from one;
ERROR: parser: parse error at or near "substr"

Any ideas?
This is 6.5.2 (RH Linux 6.1)

Thanks in advance

peter

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message tjk@tksoft.com 2000-02-13 00:31:25 Re: [SQL] Type casting bool?
Previous Message om 2000-02-12 08:30:27 Re: [SQL] Techniques for quickly finding words in a phrase...