PostgreSQL type Conversion

Source: Internet
Author: User
Tags postgresql

1.int Pack String

Select CAST (1234 as text)

Select to_char (1234, '9 ')

2.string Turn int
Cast (asNUMERIC)


--5 attached: PostgreSQL type conversion function

Function Return Type Description Example


To_char
(Timestamp, text

)


Text
Convert time stamp to string
To_char (Current_timestamp, ' HH12:MI:SS ')

to_char

interval, text

Text
convert interval to string
to_char (interval ' 15h 2m 12s ', ' HH24:MI:SS ')

to_char

int, Text

text
convert integer to String
to_char ("999")


to_char
(
double

precision
, text
)


text
convert real/double precision to string
to_char (125.8::real, ' 999d9 ')

To_char
(
numeric, text
)

Text
Convert numeric to String
To_char ( -125.8, ' 999d99s ')

To_date
(Text, text
)

Date
Convert String to date
To_date (' Dec ', ' DD Mon YYYY ')

to_number

text, Text

numeric
convert string to numeric
to_number (' 12,454.8-', ' 99g999d9s ')

to_timestamp

text, Text

timestamp With time zone
convert string to time stamp Br>to_timestamp (' 05 dec 2000 ', ' dd mon yyyy ')

To_timestamp
(
Double precision
)

Timestamp with time zone
Convert Unix epoch to time stamp
To_timestamp (1284352323)

PostgreSQL type Conversion

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.