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 example:

%%sql
SELECT
    payment_id, customer_id + rental_id AS new_id
FROM payment
ORDER BY payment_id
LIMIT 10;
 * postgresql://bob:***@localhost:5432/dvdrental
10 rows affected.
payment_id new_id
17503 1861
17504 2119
17505 2190
17506 3170
17507 3471
17508 3723
17509 2532
17510 3256
17511 3423
17512 1890