Gähn
Code:
select trunc(x, -log(x)::int + 2)
Demo
Code:
WITH vals(x) AS (
VALUES(123456789), (123.456), (1.23456), (0.0000123456)
)
SELECT trunc(x, -log(x)::int + 2) FROM vals
------------------------------------------------
123000000
123
1.23
0.0000123 
Zitat von
akretschmer
Eine Typumwandlung. So ist z.B. '123' ein String. Doch schaue selber:
Code:
test=*# select '123';
?column?
----------
123
(1 row)
test=*# select cast('123' as int);
int4
------
123
(1 row)
test=*# select '123'::int;
int4
------
123
(1 row) Das cast(...) ist SQL.Spec, das ..int ist eine Vereinfachung von PG und nicht portabel.
Andreas
Lesezeichen