SQL#

The {exec} sql block allows executing SQL directly in the browser. Each block is executed in a new, empty database.

Database definition#

A database can be defined as a named {exec} sql block, to be referenced in the :after: option of other blocks.

create table countries (
  country text not null,
  country_code text not null,
  dial_code text not null,
  capital text not null,
  population int not null,
  food text
);
insert into countries values
  ('Switzerland', 'CH', '+41', 'Bern', 8776000, 'fondue!'),
  ('France', 'FR', '+33', 'Paris', 67970000, null),
  ('Germany', 'DE', '+49', 'Berlin', 83800000, null),
  ('Italy', 'IT', '+39', 'Rome', 58940000, null),
  ('Austria', 'AT', '+43', 'Vienna', 9042000, 'Kaiserschmarrn'),
  ('Lichtenstein', 'LI', '+423', 'Vaduz', 39327, null);

Queries#

The results of the first select statement in each {exec} sql block of the :after: and :then: sequence are displayed as tables.

select * from countries;

The SQL code can be hidden by adding :class: hidden.

Empty results#

select * from countries where false;

Wide results#

select * from wide;

Mutations#

update countries set food = 'baguette' where country_code = 'FR';
select * from countries where country_code = 'FR';

SQL errors#

select * from unknown_table;