[6.2.8 / PostgreSQL] EUniError

Discussion of open issues, suggestions and bugs regarding UniDAC (Universal Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
swierzbicki
Posts: 451
Joined: Wed 19 Jan 2005 09:59

[6.2.8 / PostgreSQL] EUniError

Post by swierzbicki » Wed 07 Oct 2015 08:08

I'm getting an EUniError when opening this query :

Code: Select all

SELECT 'ALTER SEQUENCE '|| quote_ident(MIN(schema_name)) ||'.'|| quote_ident(MIN(seq_name))
       ||' OWNED BY '|| quote_ident(MIN(TABLE_NAME)) ||'.'|| quote_ident(MIN(column_name)) ||';'
FROM (
    SELECT 
        n.nspname AS schema_name,
        c.relname AS TABLE_NAME,
        a.attname AS column_name,
        SUBSTRING(d.adsrc FROM E'^nextval\\(''([^'']*)''(?:::text|::regclass)?\\)') AS seq_name 
    FROM pg_class c 
    JOIN pg_attribute a ON (c.oid=a.attrelid) 
    JOIN pg_attrdef d ON (a.attrelid=d.adrelid AND a.attnum=d.adnum) 
    JOIN pg_namespace n ON (c.relnamespace=n.oid)
    WHERE has_schema_privilege(n.oid,'USAGE')
      AND n.nspname NOT LIKE 'pg!_%' escape '!'
      AND has_table_privilege(c.oid,'SELECT')
      AND (NOT a.attisdropped)
      AND d.adsrc ~ '^nextval'
) seq
GROUP BY seq_name HAVING COUNT(*)=1

UNION ALL
 
SELECT 'SELECT SETVAL(' ||
       quote_literal(quote_ident(PGT.schemaname) || '.' || quote_ident(S.relname)) ||
       ', COALESCE(MAX(' ||quote_ident(C.attname)|| '), 1) ) FROM ' ||
       quote_ident(PGT.schemaname)|| '.'||quote_ident(T.relname)|| ';'
FROM pg_class AS S,
     pg_depend AS D,
     pg_class AS T,
     pg_attribute AS C,
     pg_tables AS PGT
WHERE S.relkind = 'S'
    AND S.oid = D.objid
    AND D.refobjid = T.oid
    AND D.refobjid = C.attrelid
    AND D.refobjsubid = C.attnum
    AND T.relname = PGT.tablename
ORDER BY S.relname;

swierzbicki
Posts: 451
Joined: Wed 19 Jan 2005 09:59

Re: [6.2.8 / PostgreSQL] EUniError

Post by swierzbicki » Thu 08 Oct 2015 07:29

It is easy to reproduce, just cut and paste this SQL Query.

AlexP
Devart Team
Posts: 5530
Joined: Tue 10 Aug 2010 11:35

Re: [6.2.8 / PostgreSQL] EUniError

Post by AlexP » Thu 08 Oct 2015 08:25

Hello,

You are getting a correct error "the table "s" is missing in the FROM statement". To resolve the issue, you should modify your query.

swierzbicki
Posts: 451
Joined: Wed 19 Jan 2005 09:59

Re: [6.2.8 / PostgreSQL] EUniError

Post by swierzbicki » Fri 09 Oct 2015 07:09

Oups, sorry...

What bother me is that individuals scripts are all working without any changes.
When using "UNION ALL", I need to remove the "ORDER BY S.relname;" line !

Anyway, thank you

AlexP
Devart Team
Posts: 5530
Joined: Tue 10 Aug 2010 11:35

Re: [6.2.8 / PostgreSQL] EUniError

Post by AlexP » Fri 09 Oct 2015 08:03

Glad to see that you solved the problem. If you have any other questions, feel free to contact us

Post Reply