liveBook · Manning

Insert

As explained in Build Python Web Apps with Streamlit

INSERT INTO is a SQL statement that adds one or more rows to a table.

INSERT INTO adds one or more rows to a table. Name the table, list the destination columns, and provide matching values in the same order. section 8.2.4

Add a user

INSERT INTO users (username, password_hash) VALUES ('alice', 'Pass_word&34'); adds one row to users. The listed columns make the value mapping explicit. section 8.2.4

Add a haiku

INSERT INTO haikus (author, text) VALUES ('alice', E'Two foxes leap high\nOne lands safely on the earth\nWhere is the other?'); inserts selected columns while the database supplies haiku_id and the default created_at timestamp. section 8.2.4

When inserting rows:

  • Match each value to the corresponding column in the column list. section 8.2.4
  • Omit columns when defaults or automatically generated values should be used. section 8.2.4
  • Supply an author that already exists when a foreign key constraint requires it. section 8.2.4

How Build Python Web Apps with Streamlit covers it

How deep it goes
Explains syntax, column mapping, defaults, escape strings, and foreign-key requirements through worked inserts.
Examples
Uses users and haikus, including Alice's account and two multiline haiku rows.
What it assumes
Assumes tables and their columns already exist, while demonstrating insertion from the column definitions.
What you can do after
Builds populated users and haikus tables with explicit values and database-generated fields.
How it connects
Connects SQL tables with DEFAULT values, SERIAL identifiers, timestamps, escape strings, and foreign key constraints.

Also explained in

Compare how 2 books explain insert →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Build Python Web Apps with Streamlit. The section links point to the parts of the book it draws on.