SqlDataInspector icon indicating copy to clipboard operation
SqlDataInspector copied to clipboard

Support for Postgres

Open Aklil opened this issue 3 years ago • 3 comments

Hi Devs,

It would be awesome if support for Postgres is added.

Thank you

Aklil avatar Feb 15 '22 12:02 Aklil

Hi @Aklil the support for Postgres is not that simple now. I see that there is a dedicated extension for connecting to Postgres databases, so I need to investigate on this topic.

ernstc avatar May 17 '22 10:05 ernstc

The analysis of the extension below can be useful for the implementation of this feature: https://github.com/microsoft/azuredatastudio-postgresql

ernstc avatar Jan 11 '24 15:01 ernstc

Queries for retrieving metadata about schemas, tables and columns.

-- Get the list of schemas
select * from information_schema.schemata where schema_owner = 'pg_database_owner';

-- Get the list of tables
select * from information_schema.tables where table_schema = 'public';

-- Get the list of columns
select * from information_schema.columns where table_schema = 'public' and table_name = 'test';

-- Get the list of table columns with their data types and primary keys
select
    c.ordinal_position,
    c.column_name,
    c.udt_name,
    character_maximum_length,
    is_nullable,
    case when kcu.column_name is not null then 'yes' else 'no' end as is_primary_key
from
    information_schema.columns as c
    left join (
        select
            kcu.column_name,
            kcu.ordinal_position
        from
            information_schema.table_constraints as tc
            join information_schema.key_column_usage as kcu
            on tc.constraint_name = kcu.constraint_name
        where
            tc.constraint_type = 'PRIMARY KEY'
            and tc.table_schema = 'public'
            and tc.table_name = 'test'
    ) as kcu
    on c.column_name = kcu.column_name
where
    c.table_schema = 'public'
    and c.table_name = 'test';

ernstc avatar Apr 02 '24 18:04 ernstc

Feature implemented in version 0.8.0.

ernstc avatar Aug 23 '24 20:08 ernstc