Skip to content

Commit 3c9d091

Browse files
committed
sql ordered bt column
1 parent 4a9a640 commit 3c9d091

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

files/ddl.sql

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
CREATE TABLE BBBBBB
2+
(
3+
ID bigint NOT NULL
4+
NAME varchar(50)
5+
CURRENCY varchar(3)
6+
SYS_START timestamp NOT NULL
7+
SYS_END timestamp NOT NULL
8+
TS_ID timestamp NOT NULL
9+
EXPORT int
10+
)
11+
12+
CREATE TABLE AA
13+
(
14+
ID bigint NOT NULL
15+
SYS_START timestamp NOT NULL
16+
SYS_END timestamp NOT NULL
17+
TS_ID timestamp NOT NULL
18+
NAME varchar(100) NOT NULL
19+
)
20+

sql_order.awk

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# SQL order just want columns inside the brackets.
2+
# Example: awk -f sql_order.awk files/ddl.sql
3+
4+
BEGIN{
5+
PROCINFO["sorted_in"] = "@ind_str_asc"
6+
f=1
7+
}
8+
/^\(/{f=0;print;next}
9+
/^\)/{for (i in a){
10+
print a[i]
11+
}
12+
delete a
13+
print
14+
f=1
15+
next}
16+
!f{a[$1]=$0}
17+
f{print}

0 commit comments

Comments
 (0)