import sqlalchemy
engine = sqlalchemy.create_engine('postgresql://bob:1234@localhost:5432/dvdrental')
engine.execution_options(isolation_level="AUTOCOMMIT")
%load_ext sql
%sql $engine.url
'Connected: bob@dvdrental'

String functions#

Postgres has support for a lot of string functions and operators. Most of them work as you would expect, most of the times it’s about checking the documentation to see what’s available. Let’s see some basic examples, starting with string concatenation:

%%sql
SELECT
    first_name || ' ' || last_name AS full_name, char_length(first_name || last_name) AS char_count
FROM customer
LIMIT 10;
 * postgresql://bob:***@localhost:5432/dvdrental
10 rows affected.
full_name char_count
Jared Ely 8
Mary Smith 9
Patricia Johnson 15
Linda Williams 13
Barbara Jones 12
Elizabeth Brown 14
Jennifer Davis 13
Maria Miller 11
Susan Wilson 11
Margaret Moore 13