Pricing
Log in

BY RUDDERSTACK TEAM

Queries for Casting - PostgreSQL

String to Date and Timestamp

  • String to Date and Timestamp
  • String to numeric

Try RudderStack for free

Sign up for RudderStack for free.

Sign Up For Free And Start Sending Data

Test out our event stream, ELT, and reverse-ETL pipelines. Use our HTTP source to send data in less than 5 minutes, or install one of our 12 SDKs in your website or app.

String to Date and Timestamp

The TO_DATE function in PostgreSQL is used to converting strings into dates. Its syntax is TO_DATE(text, text) and the return type is date.

The TO_TIMESTAMP function converts string data into timestamps with timezone. Its syntax is to_timestamp(text, text).

Usage examples:

String to numeric

In PostgreSQL strings can be converted to integer or double using CAST function or the :: annotation. Both are equivalent and you can choose whichever you like.

Usage example:

If a column contains money data you should keep in mind that floating point numbers should not be used to handle money due to the potential for rounding errors.

A money value can be cast to numeric without loss of precision. Conversion to other types could potentially lose precision, and must also be done in two stages:

Number::moneyAvoid converting it to float due to potential rounding errors

Sign Up For Free And Start Sending Data

Test out our event stream, ELT, and reverse-ETL pipelines. Use our HTTP source to send data in less than 5 minutes, or install one of our 12 SDKs in your website or app.

Get Started Image

Get started today

Start building smarter customer data pipelines today with RudderStack. Our solutions engineering team is here to help.

Customer Data Platform for Developers | RudderStack
HIPPA Compliant
SOC 2 TYPE 2Users love RudderStack on G2