Internal Functions

one day, you will need them

Order of execution of SQL statements

  1. FROM

  2. WHERE

  3. SELECT

  4. ORDER BY

Concatenation Operator

select concat(first_name,last_name) as full_name 
    from directors limit 10;
    
   full_name    
----------------
 TomasAlfredson
 PaulAnderson
 WesAnderson

select concat_ws(' ',first_name,last_name) as full_name 
    from directors limit 3;

    full_name    
-----------------
 Tomas Alfredson
 Paul Anderson
 Wes Anderson
  • if you can have a null value in column, always use concat_ws because it will place nothing in that and and also not place the spacer like | or a space

Type Conversion

Type of Conversion
Notes

Implicit

data conversion is done AUTOMATICALLY

Explicit

data conversion is done via 'conversion functions' eg. CAST or ::

Casting

Formatting Functions

https://www.postgresql.org/docs/12/functions-formatting.html

to_char()

Refer to the documentation

  • https://www.postgresqltutorial.com/postgresql-to_char/

to_number()

  • https://www.postgresqltutorial.com/postgresql-to_number/

to_date()

  • https://www.postgresqltutorial.com/postgresql-to_date/

to_timestamp()

  • https://www.postgresqltutorial.com/postgresql-to_timestamp/

String Functions

  • Upper(string)

  • Lower(string)

  • INITCAP(string)

  • REVERSE(string)

  • LPAD(string)

  • RPAD(string)

  • LENGTH(string)

  • CHAR_LENGTH(string) : Same as Length

  • POSITION( string in string )

  • STRPOS ( , < substring > )

  • SUBSTRING (string , length)

  • REPLACE (string, from_string, to_string)

Last updated

Was this helpful?