PostgreSQL Common functions

Source: Internet
Author: User
Tags postgresql

| | string concatenation
Grammar
string | | String
Example
' Post ' | | ' Gresql '--Return to PostgreSQL

length () string
Grammar
Length (String)
Example
Length (' Odoo ')--return 4

Like pattern matching
Grammar
String like pattern
Example
' abc ' LIKE ' abc '--Return True
' abc ' like ' a% '--Returns True

to_char () converts a timestamp to a string
Grammar
To_char (timestamp, text)
Example
To_char (create_date, ' yyyy/mm/dd ')
To_char (create_date, ' HH12:MI:SS ')

to_date () converts a string to a date
Grammar
To_date (text, text)
Example
To_date (' Jan ', ' DD Mon YYYY ')

To_timestamp () converts a string to a timestamp
Grammar
To_timestamp (text, text)
Example
To_timestamp (' Jan ', ' DD Mon YYYY ')

Case Conditional Expression, similar to If/else in other programming languages
Syntax 1
case when condition and result [when ...] [ELSE result] END
Example 1
case where gender= ' male ' Then ' program Ape ' ELSE ' program Yuan ' END
Syntax 2 (simplified form)
Case expression "When" value then "result [when ...] [ELSE result] END
Example 2
Case gender if ' male ' then ' program Ape ' ELSE ' program Yuan ' END

COALESCE () returns the first non-null argument, NULL is returned when all parameters are null
Grammar
Coalesce (value [, ...])
Example
COALESCE (actual_qty,0) as Actual_qty

nullif () returns null if value1 is equal to value2, otherwise returns value1
Grammar
Nullif (value1, value2)
Example
Nullif (Value, ' (none) ')

ASCII () converts the first character of a parameter to an ASCII code
Grammar
ASCII (String)
Example
ASCII (' x ')--Returns 120

chr () converts ASCII code to characters
Grammar
Chr (int)
Example
Chr (65)--Return a

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

PostgreSQL Common functions

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.