1

I have below query which works properly but don't know meaning and use of :: in postgresql.

select (
    select ( 
        case when 1 > 0 then 1::float / (
            select count(id) from transactions_products where transaction_id in (
            select id from transactions_transactions tt 
            where status = 3 and fi = 355 
                and (invoice_date >= 1420754400) 
                and (invoice_date <= 1421099999) 
                and (tt.division_id = 107) 
                and (tt.department_id = 210) 
        ) and is_vehicle = 1 
    )::float else 0 end)
 limit 1) as f_4
user1766169
  • 1,932
  • 3
  • 22
  • 44
Sandeep
  • 956
  • 2
  • 9
  • 19

2 Answers2

11

:: is the cast operator for PostgreSQL.

Jay Blanchard
  • 34,243
  • 16
  • 77
  • 119
0

Short, no-hassle answer: It casts the value to a float.

rdiz
  • 6,136
  • 1
  • 29
  • 41
  • You might want to elaborate on your answer. It's not really useful to just say it casts the value. Why would you want to cast a value? Is there a better example of a use case? – Machavity Jan 12 '15 at 13:38
  • I see what you mean, but then the post would just turn into a general discussion of the purpose, pros and cons of typecasting. – rdiz Jan 12 '15 at 13:41
  • 1
    You don't need to go into that level of detail, just explain why you would use one or provide something for the OP to go on. You're assuming that everyone knows what casting is. Note the top answer has a link to more information. – Machavity Jan 12 '15 at 13:44
  • That is indeed a better answer. Thank you for your feedback! – rdiz Jan 12 '15 at 13:44