Skip site navigation (1) Skip section navigation (2)

round() and ||

From: "Graeme Merrall" <gmerrall(at)email(dot)com>
To: <pgsql-sql(at)postgreSQL(dot)org>
Subject: round() and ||
Date: 2000-01-20 02:42:56
Message-ID: 000f01bf62f0$0ebfff00$899d60cb@inspire.net.nz (view raw or flat)
Thread:
Lists: pgsql-sql
Hi.
I'm having a lot of trouble concatenating some fields along witha rounded number. services_cost is a float field field and I want to convert it to 2 decimal places so it appears as money. I could store it as money but mathematical operations are performed on the same field further down the line so I don't want it 'pre-formatted'

SELECT round(services_cost,2) as test_field FROM services
works fine but 
SELECT round(services_cost,2)::text as test_field FROM services
as various other variations does not. 

The reason I need to do this is so join this field and a text field together
SELECT services_type || '|' || round(services_cost,2)  AS services_list FROM services;

but pgsql complains that it can't join a numeric plus a text field obviously. I'm pretty stuck on this one.

Cheers,
 Graeme

Responses

pgsql-sql by date

Next:From: Tom LaneDate: 2000-01-20 06:34:40
Subject: Re: [SQL] round() and ||
Previous:From: Tom LaneDate: 2000-01-20 02:20:09
Subject: Re: [SQL] null and integer field

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group