Last active
June 6, 2021 04:44
-
-
Save JAForbes/994e5c6e4478c555dd93 to your computer and use it in GitHub Desktop.
Table literal in SQLite
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
select * from ( | |
-- define the column names | |
select 0 as a, 0 as b | |
-- join the definition row with all the values | |
union | |
-- define the values | |
values | |
(4,5), | |
(5,6), | |
(6,7), | |
(7,8), | |
(9,10), | |
(11,12) | |
) | |
-- skip the definition row | |
limit -1 offset 1; | |
--> /* | |
"a" "b" | |
=== === | |
"4" "5" | |
"5" "6" | |
"6" "7" | |
"7" "8" | |
"9" "10" | |
"11" "12" | |
*/ |
To create multiple rows, keep appending tuples:
sqlite> SELECT * FROM (VALUES (1, 'hi'), (2, 'there'));
column1 column2
------- -------
1 hi
2 there
Found this in the grammar for SELECT
https://www.sqlite.org/lang_select.html
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Stumbled across this and it helped increase my understanding. I learned that a SELECT can just be VALUES, I think, meaning that
select * from ( values(1,2) );
produces1|2
. Next, I think I learned that I can get the column headings I want with Common Table Expression, like:which produces
Which may be completely irrelevant to what you were doing, but helped me get where I was going, so thanks for this gist!