microsoft / azuredatastudio-postgresql

azuredatastudio-postgresql is an extension for Azure Data Studio that enables you to work with PostgreSQL databases
Other
198 stars 37 forks source link

'list' object has no attribute 'encode' #497

Open LSIND opened 9 months ago

LSIND commented 9 months ago

Describe the bug Faced an error Unhandled exception while executing query: 'list' object has no attribute 'encode' when querying columns of type aclitem (catalog representation of access privileges).

To Reproduce

  1. SELECT-statements to system tables which query column of type aclitem (limit for short output):
    
    -- column relacl 
    SELECT relname, relacl 
    FROM pg_class 
    WHERE relacl IS NOT NULL LIMIT 2;

-- column attacl SELECT attrelid::regclass, attname, attoptions, attacl FROM pg_attribute WHERE attacl IS NOT NULL LIMIT 2;

2. Error (same for both queries, result is exactly two rows)

SELECT 2 Unhandled exception while executing query: 'list' object has no attribute 'encode'


**Expected behavior**
psql (13.6) produces correct results (your output can be different based on privileges and roles in your system):
``` sql 
SELECT relname, relacl 
FROM pg_class 
WHERE relacl IS NOT NULL LIMIT 2;
relname relacl
users_depts {postgres=arwdDxt/postgres,alice=r/postgres,bob=r/postgres}
revenue {postgres=arwdDxt/postgres,alice=r/postgres,bob=r/postgres}
SELECT attrelid::regclass,  attname, attoptions, attacl
FROM pg_attribute
WHERE attacl IS NOT NULL LIMIT 2;
attrelid attname attoptions attacl
pg_subscription subdbid {=r/postgres}
pg_subscription subname {=r/postgres}

Desktop (please complete the following information):

ADS:

Additional context As a temporary solution I use function pg_catalog.array_to_string(array, delimiter) to convert each array element of aclitem type to its text representation:

SELECT relname, pg_catalog.array_to_string(relacl, ', ') as relacl
FROM pg_class 
WHERE relacl IS NOT NULL LIMIT 2;
-- or just cast to text

SELECT relname, relacl::text as relacl
FROM pg_class 
WHERE relacl IS NOT NULL LIMIT 2;
relname relacl
users_depts postgres=arwdDxt/postgres, alice=r/postgres, bob=r/postgres
revenue postgres=arwdDxt/postgres, alice=r/postgres, bob=r/postgres
craftzneko commented 3 months ago

I have the same issue when running this query

SELECT * 
FROM pg_class
WHERE relname = 'MYTABLENAME';