Postgres Inline Data

Last updated: July 18, 2020

Here are some ways to define data inside a .sql file with Postgres:

As part of query

with some_inline_data as
(select *
         (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
(1::int, 'a'::varchar(12)),
(2, 'b'),
(3, 'c'),
(4, 'd')

select * from some_temp_table;