Hacker News new | comments | show | ask | jobs | submit login

This is a huge win for improving the usability of foreign data wrappers. The initial setup today is a bit pain and convenience tools as this will get many more people using them. Though as 9.5 is at minimum a full year a way you could get some similar result of this from the query below. The query will create SQL to run on the one you're trying to create the foreign table to, to establish all tables in the DB as foreign ones.

    SELECT
            'CREATE FOREIGN TABLE '
            || quote_ident('#{prefix}_' || c.relname)
            || '(' || array_to_string(array_agg(quote_ident(a.attname) || ' ' || t.typname), ', ') || ') '
            || ' SERVER #{prefix}_db OPTIONS'
            || ' (schema_name ''' || quote_ident(n.nspname) || ''', table_name ''' || quote_ident(c.relname) || ''');'
          FROM
            pg_class     c,
            pg_attribute a,
            pg_type      t,
            pg_namespace n
          WHERE
            a.attnum > 0
            AND a.attrelid = c.oid
            AND a.atttypid = t.oid
            AND n.oid = c.relnamespace
            AND c.relkind in ('r', 'v')
            AND n.nspname <> 'pg_catalog'
            AND n.nspname <> 'information_schema'
            AND n.nspname !~ '^pg_toast'
            AND pg_catalog.pg_table_is_visible(c.oid)
          GROUP BY c.relname, n.nspname
          ORDER BY c.relname



Guidelines | FAQ | Support | API | Security | Lists | Bookmarklet | DMCA | Apply to YC | Contact

Search: