From: Tom Lane <tgl@sss.pgh.pa.us>
To: Peter Stamfest <peter.stamfest@eunet.at>
Cc: pgsql-sql@postgreSQL.org
Subject: Re: [SQL] text -> char
Date: Sat, 26 Feb 2000 16:27:06 -0500
Message-ID: <3855.951600426@sss.pgh.pa.us> (raw)
In-Reply-To: <Pine.LNX.4.10.10002130046150.1021-100000@peter.stamf.pr.at>
References: <Pine.LNX.4.10.10002130046150.1021-100000@peter.stamf.pr.at>
Peter Stamfest <peter.stamfest@eunet.at> wrote a couple weeks ago:
> create view three as select CAST(substr(descr, 2, 4) as char(8)) as
> d from one;
That should work, and as of today it does work in current sources:
regression=# create view three as select CAST(substr(descr, 2, 4) as char(8))
regression-# as d from one;
CREATE 278003 1
regression=# \d three
View "three"
Attribute | Type | Modifier
-----------+---------+----------
d | char(8) |
View definition: SELECT (substr(one.descr, 2, 4))::char(8) AS d FROM one;
Releases before 7.0 had a tendency to just discard casts :-( in a lot
of corner cases, and this is one of 'em. I've cleaned up the cast
problems I know about, but there may be some left...
> 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"
That's not a bug. CHAR is an SQL reserved word for a type --- the
parser is expecting a type length indicator, like "char(8)", when it
sees CHAR(.
While there is a function named "char", you can only get at it by
double-quoting the name so it no longer looks like a keyword:
select "char"(substr(descr, 2, 4)) as d from one;
Also note that this converts to the internal single-byte char type,
which is presumably not what you wanted anyway.
regards, tom lane
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-sql@postgresql.org
Cc: tgl@sss.pgh.pa.us, peter.stamfest@eunet.at
Subject: Re: [SQL] text -> char
In-Reply-To: <3855.951600426@sss.pgh.pa.us>
References: <Pine.LNX.4.10.10002130046150.1021-100000@peter.stamf.pr.at> <3855.951600426@sss.pgh.pa.us>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox