Skip to content

Commit

Permalink
fix: linting SQL with sqlfluff
Browse files Browse the repository at this point in the history
  • Loading branch information
gvwilson committed Feb 4, 2024
1 parent 8dd7e61 commit 8e59be2
Show file tree
Hide file tree
Showing 42 changed files with 88 additions and 100 deletions.
4 changes: 2 additions & 2 deletions out/aggregate_join.out
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
CREATE TABLE job(
CREATE TABLE job (
name text not null,
billable real not null
);
CREATE TABLE work(
CREATE TABLE work (
person text not null,
job text not null
);
4 changes: 2 additions & 2 deletions out/aggregate_left_join.out
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
CREATE TABLE job(
CREATE TABLE job (
name text not null,
billable real not null
);
CREATE TABLE work(
CREATE TABLE work (
person text not null,
job text not null
);
2 changes: 1 addition & 1 deletion out/autoincrement.out
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
| 1 | mik |
| 2 | po |
| 3 | tay |
Runtime error near line 13: UNIQUE constraint failed: person.ident (19)
Runtime error near line 12: UNIQUE constraint failed: person.ident (19)
4 changes: 2 additions & 2 deletions out/backing_up.out
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
CREATE TABLE job(
CREATE TABLE job (
name text not null,
billable real not null
);
CREATE TABLE work(
CREATE TABLE work (
person text not null,
job text not null
);
4 changes: 2 additions & 2 deletions out/coalesce.out
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
CREATE TABLE job(
CREATE TABLE job (
name text not null,
billable real not null
);
CREATE TABLE work(
CREATE TABLE work (
person text not null,
job text not null
);
4 changes: 2 additions & 2 deletions out/cross_join.out
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
CREATE TABLE job(
CREATE TABLE job (
name text not null,
billable real not null
);
CREATE TABLE work(
CREATE TABLE work (
person text not null,
job text not null
);
4 changes: 2 additions & 2 deletions out/delete_rows.out
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
CREATE TABLE job(
CREATE TABLE job (
name text not null,
billable real not null
);
CREATE TABLE work(
CREATE TABLE work (
person text not null,
job text not null
);
6 changes: 3 additions & 3 deletions out/drop_table.out
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
CREATE TABLE job(
CREATE TABLE job (
ident integer primary key autoincrement,
name text not null,
billable real not null
);
CREATE TABLE sqlite_sequence(name,seq);
CREATE TABLE person(
CREATE TABLE person (
ident integer primary key autoincrement,
name text not null
);
CREATE TABLE IF NOT EXISTS "work"(
CREATE TABLE IF NOT EXISTS "work" (
person_id integer not null,
job_id integer not null,
foreign key(person_id) references person(ident),
Expand Down
4 changes: 2 additions & 2 deletions out/inner_join.out
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
CREATE TABLE job(
CREATE TABLE job (
name text not null,
billable real not null
);
CREATE TABLE work(
CREATE TABLE work (
person text not null,
job text not null
);
4 changes: 2 additions & 2 deletions out/insert_values.out
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
CREATE TABLE job(
CREATE TABLE job (
name text not null,
billable real not null
);
CREATE TABLE work(
CREATE TABLE work (
person text not null,
job text not null
);
Expand Down
4 changes: 2 additions & 2 deletions out/left_join.out
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
CREATE TABLE job(
CREATE TABLE job (
name text not null,
billable real not null
);
CREATE TABLE work(
CREATE TABLE work (
person text not null,
job text not null
);
4 changes: 2 additions & 2 deletions out/negate_incorrectly.out
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
CREATE TABLE job(
CREATE TABLE job (
name text not null,
billable real not null
);
CREATE TABLE work(
CREATE TABLE work (
person text not null,
job text not null
);
4 changes: 2 additions & 2 deletions out/set_membership.out
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
CREATE TABLE job(
CREATE TABLE job (
name text not null,
billable real not null
);
CREATE TABLE work(
CREATE TABLE work (
person text not null,
job text not null
);
8 changes: 4 additions & 4 deletions out/show_work_job.out
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
CREATE TABLE job(
CREATE TABLE job (
name text not null,
billable real not null
);
CREATE TABLE work(
CREATE TABLE work (
person text not null,
job text not null
);
CREATE TABLE job(
CREATE TABLE job (
name text not null,
billable real not null
);
CREATE TABLE work(
CREATE TABLE work (
person text not null,
job text not null
);
4 changes: 2 additions & 2 deletions out/subquery_set.out
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
CREATE TABLE job(
CREATE TABLE job (
name text not null,
billable real not null
);
CREATE TABLE work(
CREATE TABLE work (
person text not null,
job text not null
);
4 changes: 2 additions & 2 deletions out/update_rows.out
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
CREATE TABLE job(
CREATE TABLE job (
name text not null,
billable real not null
);
CREATE TABLE work(
CREATE TABLE work (
person text not null,
job text not null
);
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ pandas
polars
pyarrow
ruff
sqlfluff
sqlmodel
sqlparse
5 changes: 2 additions & 3 deletions src/all_jobs.sql
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
create table job(
create table job (
name text not null,
billable real not null
);
insert into job values
('calibrate', 1.5),
('clean', 0.5)
;
('clean', 0.5);
select * from job;
4 changes: 2 additions & 2 deletions src/all_jobs_check.sql
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
create table job(
create table job (
name text not null,
billable real not null,
check(billable > 0.0)
check (billable > 0.0)
);
insert into job values ('calibrate', 1.5);
insert into job values ('reset', -0.5);
Expand Down
10 changes: 4 additions & 6 deletions src/alter_tables.sql
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
create table job(
create table job (
name text not null,
billable real not null
);
insert into job values
('calibrate', 1.5),
('clean', 0.5)
;
create table work(
('clean', 0.5);
create table work (
person text not null,
job text not null
);
Expand All @@ -16,8 +15,7 @@ insert into work values
('mik', 'complain'),
('po', 'clean'),
('po', 'complain'),
('tay', 'complain')
;
('tay', 'complain');

-- start
alter table job
Expand Down
5 changes: 2 additions & 3 deletions src/autoincrement.sql
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
create table person(
create table person (
ident integer primary key autoincrement,
name text not null
);
insert into person values
(null, 'mik'),
(null, 'po'),
(null, 'tay')
;
(null, 'tay');
select * from person;
insert into person values (1, "prevented");
2 changes: 1 addition & 1 deletion src/backing_up.sql
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
.read src/create_work_job.sql

-- start
create table backup(
create table backup (
person text not null,
job text not null
);
Expand Down
3 changes: 1 addition & 2 deletions src/blob.sql
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ insert into images(name, content) values
("crush", readfile("img/crush.png")),
("fire", readfile("img/fire.png")),
("radioactive", readfile("img/radioactive.png")),
("tripping", readfile("img/tripping.png"))
;
("tripping", readfile("img/tripping.png"));
-- end

select name, length(content) from images;
4 changes: 2 additions & 2 deletions src/compare_individual_aggregate.sql
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
select body_mass_g
from penguins
where body_mass_g > (
select avg(body_mass_g)
from penguins
select avg(body_mass_g)
from penguins
)
limit 5;
2 changes: 1 addition & 1 deletion src/correlated_subquery.sql
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ from department
where exists (
select 1
from staff
where dept == department.ident
where dept = department.ident
)
order by name;
4 changes: 2 additions & 2 deletions src/create_work_job.sql
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
-- start
create table job(
create table job (
name text not null,
billable real not null
);
create table work(
create table work (
person text not null,
job text not null
);
Expand Down
4 changes: 2 additions & 2 deletions src/data_range_sequence.sql
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
create table temp(
create table temp (
num integer not null
);
insert into temp values (1), (5);
select value from generate_series(
select value from generate_series (
(select min(num) from temp),
(select max(num) from temp)
);
8 changes: 4 additions & 4 deletions src/drop_table.sql
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
create table job(
create table job (
ident integer primary key autoincrement,
name text not null,
billable real not null
);

create table person(
create table person (
ident integer primary key autoincrement,
name text not null
);

create table work(
create table work (
person text not null,
job text not null
);

create table new_work(
create table new_work (
person_id integer not null,
job_id integer not null,
foreign key(person_id) references person(ident),
Expand Down
2 changes: 1 addition & 1 deletion src/except.sql
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
select personal, family, dept, age
from staff
where dept == 'mb'
where dept = 'mb'
except
select personal, family, dept, age from staff
where age < 50
Expand Down
17 changes: 7 additions & 10 deletions src/insert_select.sql
Original file line number Diff line number Diff line change
@@ -1,24 +1,22 @@
create table job(
create table job (
ident integer primary key autoincrement,
name text not null,
billable real not null
);
insert into job values
(null, 'calibrate', 1.5),
(null, 'clean', 0.5)
;
(null, 'clean', 0.5);

create table person(
create table person (
ident integer primary key autoincrement,
name text not null
);
insert into person values
(null, 'mik'),
(null, 'po'),
(null, 'tay')
;
(null, 'tay');

create table work(
create table work (
person text not null,
job text not null
);
Expand All @@ -32,7 +30,7 @@ insert into work values
;

-- start
create table new_work(
create table new_work (
person_id integer not null,
job_id integer not null,
foreign key(person_id) references person(ident),
Expand All @@ -45,7 +43,6 @@ select
job.ident as job_id
from
(person join work on person.name = work.person)
join job on job.name = work.job
;
join job on job.name = work.job;
select * from new_work;
-- end
Loading

0 comments on commit 8e59be2

Please sign in to comment.