Postgres Inline Data
Last updated: January 18, 2021
Here are some ways to define data inside a .sql
file with Postgres:
As part of query
with some_inline_data as
(select *
from
(values
(1, 'a'),
(2, 'b'),
(3, 'c'),
(4, 'd')
) as i(id, value)
)
select *
from some_inline_data
Temporary tables
drop table if exists some_temp_table;
create temp table some_temp_table(id, value) as
values
(1::int, 'a'::varchar(12)),
(2, 'b'),
(3, 'c'),
(4, 'd')
;
select * from some_temp_table;