PostgreSQL查询失败了SQL Server的PGNP提供程序

时间:2013-07-19 18:51:06

标签: sql-server oledb linked-server

此查询在SQL Server中通过PGNP提供程序失败:

SELECT      1 AS x
FROM        pg_catalog.pg_attribute a
LEFT OUTER JOIN pg_catalog.pg_index i
        ON (i.indrelid = a.attrelid 
            AND a.attnum = i.indkey[a.attnum-1])

这是返回的错误消息:

链接服务器“XXX”的OLE DB提供程序“PGNP”表示该对象没有列,或者当前用户没有该对象的权限。

如果我使用pgAdmin直接在PostgreSQL服务器上运行此查询,则返回结果。此外,如果我删除子句“a.attnum = i.indkey [a.attnum-1]”,则查询将在PGNP提供程序上运行。 (我在原始查询中需要这个子句来识别哪个表的列是主键。)

问题是什么,如何解决?

对于记录,这是我正在执行的完整查询,上面的查询摘录自:

SELECT      c.relname as table_name, a.attname as column_name
        ,   t.typname as type_name
        ,   i.indisunique AS is_unique_key
        ,   i.indisprimary AS is_primary_key 
        ,   CASE t.typname
            WHEN 'bpchar' THEN 'char('+CAST(atttypmod - 4 AS VARCHAR)+')'
            WHEN 'numeric' THEN 'numeric('+CAST((atttypmod - 4)/65536 AS VARCHAR)
                            +','+CAST((atttypmod - 4)%65536 AS VARCHAR)
                            +')'
            WHEN 'text' THEN 'varchar(max)'
            WHEN 'varchar' THEN 'varchar('+CASE atttypmod WHEN -1 THEN 'max' ELSE CAST(atttypmod-4 AS VARCHAR) END+')'
            ELSE t.typname
            END as type_name_1          
        ,   CAST(CASE atttypmod WHEN -1 THEN NULL ELSE atttypmod - 4 END AS INT4) AS type_precision_scale
FROM        pg_catalog.pg_attribute a
    JOIN    pg_catalog.pg_class c on ( a.attrelid = c.oid)
    JOIN    pg_catalog.pg_namespace n on (c.relnamespace = n.oid)
    JOIN    pg_catalog.pg_type t on (a.atttypid = t.oid)
LEFT OUTER JOIN pg_catalog.pg_index i
        ON (c.oid = i.indrelid 
            AND i.indrelid = a.attrelid
            AND a.attnum = i.indkey[a.attnum-1])
WHERE       c.relkind = 'r' and a.attnum > 0
     AND    n.nspname = 'public'

0 个答案:

没有答案