pg.ddx.io pgsql-sql@postgresql.org mailing list archive
help / color / mirror / Atom feedTypecasting within sql statement.
3+ messages / 2 participants
[nested] [flat]
* Typecasting within sql statement.
@ 1998-07-03 18:14 Colin Dick <cdick@mail.ocis.net>
0 siblings, 0 replies; 3+ messages in thread
From: Colin Dick @ 1998-07-03 18:14 UTC (permalink / raw)
To: pgsql-sql
Hi there,
I have a need to create a field value from a function. The
problem I have is that the field and the return of the function are of
different types. Any ideas how one would do the following?
update table set varchar=func(int4);
I have tried update table set varchar=varchar(func(int4));
but I get an error "function varchar(int4) does not exist"
There must be a way to do it without writing the varchar function. Can
anyone help me out? Thanks.
--
Colin Dick
On Call Internet Services
cdick@mail.ocis.net
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: [SQL] Typecasting within sql statement.
@ 1998-07-03 19:11 Richard Lynch <lynch@lscorp.com>
1998-07-03 19:25 ` Re: [SQL] Typecasting within sql statement. Colin Dick <cdick@mail.ocis.net>
0 siblings, 1 reply; 3+ messages in thread
From: lynch@lscorp.com @ 1998-07-03 19:11 UTC (permalink / raw)
To: pgsql-sql
Try something like this:
update myTable set field = 42::text::varchar;
I think the int4 --> text converter is written, and text --> varchar is
written, but int4 --> varchar is not.
Basically, anytime you need to go from one type to another that doesn't
seem to have a converter, look for a more general intermediate type.
At least, that's my understanding after one fight with this. :-)
--
--
-- "TANSTAAFL" Rich lynch@lscorp.com
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: [SQL] Typecasting within sql statement.
1998-07-03 19:11 Re: [SQL] Typecasting within sql statement. Richard Lynch <lynch@lscorp.com>
@ 1998-07-03 19:25 ` Colin Dick <cdick@mail.ocis.net>
0 siblings, 0 replies; 3+ messages in thread
From: Colin Dick @ 1998-07-03 19:25 UTC (permalink / raw)
To: Richard Lynch <lynch@lscorp.com>; +Cc: pgsql-sql
> update myTable set field = 42::text::varchar;
>
> I think the int4 --> text converter is written, and text --> varchar is
> written, but int4 --> varchar is not.
Well,
It seems you understand what I am looking for but this did not
work. I get an error of:
WARN:parser: parse error at or near "::"
Do you think my fastest solution would be to write a func (inttochar)
which accepts and int and returns a char. Should only take a minute. I
think that is what I will do. Thanks for your help.
If anyone else knows an easier solution, let me know and I will dump my
function. Have a good weekend.
--
Colin Dick
On Call Internet Services
cdick@mail.ocis.net
^ permalink raw reply [nested|flat] 3+ messages in thread
end of thread, other threads:[~1998-07-03 19:25 UTC | newest]
Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
1998-07-03 18:14 Typecasting within sql statement. Colin Dick <cdick@mail.ocis.net>
1998-07-03 19:11 Re: [SQL] Typecasting within sql statement. Richard Lynch <lynch@lscorp.com>
1998-07-03 19:25 ` Colin Dick <cdick@mail.ocis.net>
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