Created
February 28, 2011 11:47
-
-
Save alf239/847216 to your computer and use it in GitHub Desktop.
I love write-only languages
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
A very special SQL file - actually, a configuration for the exporter | |
the exporter is in the where.clause.awk script, | |
which is called as follows: | |
awk -v table=$TABLE_NAME -f where_clause.awk Schema/public_data.sql | |
NB: We have slightly weird syntax for comments here: a line containing / and * | |
will be completely ignored; so will the line containing */ | |
/* | |
That means while one-line comments are completely possible, | |
they are not allowed in the end of the string | |
*/ | |
SELECT * FROM A2_EXPERIMENT e | |
WHERE e.releasedate IS NOT NULL; | |
SELECT * FROM A2_ASSAY a | |
WHERE EXISTS (SELECT * FROM A2_EXPERIMENT e | |
WHERE e.experimentid = a.experimentid AND e.releasedate IS NOT NULL); | |
SELECT * FROM A2_ASSAYPV apv WHERE EXISTS (SELECT * FROM A2_ASSAY a JOIN A2_EXPERIMENT e | |
ON e.experimentid = a.experimentid | |
WHERE a.ASSAYID = apv.assayid AND e.releasedate IS NOT NULL); | |
SELECT * FROM A2_ASSAYPVONTOLOGY apvo WHERE EXISTS (SELECT * FROM A2_ASSAYPV apv JOIN A2_ASSAY a ON a.assayid = apv.assayid JOIN A2_EXPERIMENT e | |
ON e.experimentid = a.experimentid | |
WHERE apvo.assaypvid = apv.assaypvid AND e.releasedate IS NOT NULL); | |
SELECT * FROM A2_ASSAYSAMPLE asmpl WHERE EXISTS (SELECT * FROM A2_ASSAY a JOIN A2_EXPERIMENT e | |
ON e.experimentid = a.experimentid | |
WHERE a.ASSAYID = asmpl.assayid AND e.releasedate IS NOT NULL); | |
SELECT * FROM A2_EXPRESSIONANALYTICS ea | |
WHERE EXISTS (SELECT * FROM A2_EXPERIMENT e | |
WHERE e.experimentid = ea.experimentid AND e.releasedate IS NOT NULL); | |
SELECT * FROM A2_SAMPLE s WHERE EXISTS (SELECT * FROM A2_ASSAYSAMPLE asmpl JOIN A2_ASSAY a ON a.assayid = asmpl.assayid JOIN A2_EXPERIMENT e | |
ON e.experimentid = a.experimentid | |
WHERE asmpl.sampleid = s.sampleid AND e.releasedate IS NOT NULL); | |
SELECT * FROM A2_SAMPLEPV spv WHERE EXISTS (SELECT * FROM A2_SAMPLE s JOIN A2_ASSAYSAMPLE asmpl ON s.SAMPLEID = asmpl.SAMPLEID JOIN A2_ASSAY a ON a.assayid = asmpl.assayid JOIN A2_EXPERIMENT e | |
ON e.experimentid = a.experimentid | |
WHERE asmpl.sampleid = s.sampleid AND e.releasedate IS NOT NULL); | |
SELECT * FROM A2_SAMPLEPVONTOLOGY spvo WHERE EXISTS (SELECT * FROM A2_SAMPLEPV spv JOIN A2_SAMPLE s on s.sampleid = spv.sampleid JOIN A2_ASSAYSAMPLE asmpl ON s.SAMPLEID = asmpl.SAMPLEID JOIN A2_ASSAY a ON a.assayid = asmpl.assayid JOIN A2_EXPERIMENT e | |
ON e.experimentid = a.experimentid | |
WHERE spvo.samplepvid = spv.samplepvid AND e.releasedate IS NOT NULL); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
BEGIN { | |
comment = 0; | |
desired = table; | |
table = ""; | |
sql = ""; | |
} | |
/\/\*/ { comment = 1 } | |
/^SELECT \* FROM A2_/ { | |
name = $4; | |
sub(/A2_/, "", name); | |
table = name; | |
} | |
!comment && tolower(table) == tolower(desired) { | |
if (!sql) { | |
sql = substr($0, index($0, "A2_" table) + length("A2_" table) + 1); | |
} else { | |
sql = sql $0; | |
} | |
} | |
/\;$/ && sql { | |
table = ""; | |
gsub(/[[:space:]\r\n;]+/, " ", sql); | |
print sql; | |
sql = 0; | |
} | |
/\*\// { comment = 0 } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment