Skip to content

Instantly share code, notes, and snippets.

@saltcod
Created May 10, 2024 16:35
Show Gist options
  • Save saltcod/17e5f9b84317d4c1618c7dfd410a8139 to your computer and use it in GitHub Desktop.
Save saltcod/17e5f9b84317d4c1618c7dfd410a8139 to your computer and use it in GitHub Desktop.
CREATE VIEW
public.countries_view AS
SELECT
*
FROM
public.countries;
CREATE MATERIALIZED VIEW
public.countries_materialized_view AS
SELECT
*
FROM
public.countries;
create schema privato
CREATE VIEW
privato.countries_view_privato AS
SELECT
*
FROM
public.countries;
CREATE MATERIALIZED VIEW
privato.countries_materialized_view_privato AS
SELECT
*
FROM
public.countries;
create extension if not exists wrappers with schema extensions;
create foreign data wrapper stripe_wrapper
handler stripe_fdw_handler
validator stripe_fdw_validator;
create server stripe_server
foreign data wrapper stripe_wrapper
options (
api_key 'XXXXXXXXXXXX',
api_url 'https://api.stripe.com/v1/'
);
create schema stripe;
create foreign table stripe.accounts (
id text,
business_type text,
country text,
email text,
type text,
created timestamp,
attrs jsonb
)
server stripe_server
options (
object 'accounts'
);
create foreign table stripe.customers (
id text,
email text,
name text,
description text,
created timestamp,
attrs jsonb
)
server stripe_server
options (
object 'customers',
rowid_column 'id'
);
create foreign table stripe.products (
id text,
name text,
active bool,
default_price text,
description text,
created timestamp,
updated timestamp,
attrs jsonb
)
server stripe_server
options (
object 'products',
rowid_column 'id'
);
create foreign table stripe.subscriptions (
id text,
customer text,
currency text,
current_period_start timestamp,
current_period_end timestamp,
attrs jsonb
)
server stripe_server
options (
object 'subscriptions',
rowid_column 'id'
);
@saltcod
Copy link
Author

saltcod commented May 24, 2024

-- View with SECURITY INVOKER
CREATE VIEW public.view_countries_invoker
WITH (security_invoker = on) AS
SELECT
id,
name,
iso2,
iso3,
local_name,
continent
FROM
public.countries;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment