pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: daq <daq@ugyvitelszolgaltato.hu>
Cc: Luke Pascoe <luke.p@kmg.co.nz>
Cc: pgsql-sql@postgresql.org
Subject: Re: CAST from VARCHAR to INT
Date: Fri, 24 Jan 2003 10:42:29 -0500
Message-ID: <13400.1043422949@sss.pgh.pa.us> (raw)
In-Reply-To: <21242862808.20030124112835@ugyvitelszolgaltato.hu>
References: <01df01c2c354$2bac5a60$3200000a@K2>
	<21242862808.20030124112835@ugyvitelszolgaltato.hu>

daq <daq@ugyvitelszolgaltato.hu> writes:
> Make your life easier! :) You must write a function like
> this:

> create function "int4"(character varying) returns int4 as '
>        DECLARE
>               input alias for $1;
>        BEGIN
>             return (input::text::int4);
>        END;
> ' language 'plpgsql';

> When you try the cast varchar_field::integer or varchar_field::int4 Postgres call
> the function named int4 and takes varchar type parameter.

Note that as of 7.3 you need to issue a CREATE CAST command; the name of
the function is not what drives this anymore.  (Though following the old
naming convention that function name == return type still seems like a
good idea.)

			regards, tom lane



view thread (7+ messages)  latest in thread

Message-ID: <13400.1043422949@sss.pgh.pa.us>
Permalink:  ../13400.1043422949@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/13400.1043422949@sss.pgh.pa.us

 · 

reply

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 using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: tgl@sss.pgh.pa.us, daq@ugyvitelszolgaltato.hu, luke.p@kmg.co.nz
  Subject: Re: CAST from VARCHAR to INT
  In-Reply-To: <13400.1043422949@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