Thread: Casting numeric to text

Casting numeric to text

From
Hans-Jürgen Schönig
Date:
Is there any possibility to cast numeric to text in Postgres 7.0.3?

shop=# select cast(price as text) from products;
ERROR:  Cannot cast type 'numeric' to 'text'
   Hans



Re: Casting numeric to text

From
Peter Eisentraut
Date:
Hans-Jürgen Schönig writes:

> Is there any possibility to cast numeric to text in Postgres 7.0.3?
>
> shop=# select cast(price as text) from products;
> ERROR:  Cannot cast type 'numeric' to 'text'

Use the to_char() function.

-- 
Peter Eisentraut      peter_e@gmx.net       http://yi.org/peter-e/



Re: Casting numeric to text

From
Cedar Cox
Date:

On Sun, 8 Apr 2001, Peter Eisentraut wrote:

> Hans-Jürgen Schönig writes:
> 
> > Is there any possibility to cast numeric to text in Postgres 7.0.3?
> >
> > shop=# select cast(price as text) from products;
> > ERROR:  Cannot cast type 'numeric' to 'text'
> 
> Use the to_char() function.

When would one want to use cast()?  What is the difference between cast
and :: ?  After a quick look in the documentation I couldn't find
anything..

-Cedar



Re: Casting numeric to text

From
Peter Eisentraut
Date:
Cedar Cox writes:

> When would one want to use cast()?  What is the difference between cast
> and :: ?  After a quick look in the documentation I couldn't find
> anything..

cast() is SQL, :: is traditional Postgres.  :: may go away in the distant
future to make room for the SQL feature that is supposed to use ::.  (It
escapes me at the moment what that was.)

-- 
Peter Eisentraut      peter_e@gmx.net       http://yi.org/peter-e/



Re: Casting numeric to text

From
"Ross J. Reedstrom"
Date:
On Mon, Apr 09, 2001 at 05:57:45PM +0200, Peter Eisentraut wrote:
> Cedar Cox writes:
> 
> > When would one want to use cast()?  What is the difference between cast
> > and :: ?  After a quick look in the documentation I couldn't find
> > anything..
> 
> cast() is SQL, :: is traditional Postgres.  :: may go away in the distant
> future to make room for the SQL feature that is supposed to use ::.  (It
> escapes me at the moment what that was.)


FYI, I can't find an occurance of '::' that's not part of '::=' in either
SQL1992.txt or the ansi-iso-[sql]-1999.txt files I've got.

But Peter's answer's still correct: CAST( <value> AS <type> ) is SQL
standard, '::' is not.

Ross


Re: Casting numeric to text

From
Peter Eisentraut
Date:
Ross J. Reedstrom writes:

> FYI, I can't find an occurance of '::' that's not part of '::=' in either
> SQL1992.txt or the ansi-iso-[sql]-1999.txt files I've got.

SQL 1999 6.12

<static method invocation> ::=    <user-defined type> <double colon> <method name> [ <SQL argument list> ]

That syntax even makes sense...

-- 
Peter Eisentraut      peter_e@gmx.net       http://yi.org/peter-e/



Re: Casting numeric to text

From
"Ross J. Reedstrom"
Date:
On Mon, Apr 09, 2001 at 06:53:13PM +0200, Peter Eisentraut wrote:
> Ross J. Reedstrom writes:
> 
> > FYI, I can't find an occurance of '::' that's not part of '::=' in either
> > SQL1992.txt or the ansi-iso-[sql]-1999.txt files I've got.
> 
> SQL 1999 6.12
> 
> <static method invocation> ::=
>      <user-defined type> <double colon> <method name> [ <SQL argument list> ]
> 

Ah, right: My grep excluded the ::= cases, so I missed:

<double colon> ::= ::

> That syntax even makes sense...

No, how could it be? Someone must have failed to run the Babelizer on that part.

Ross