Okay
  Public Ticket #1941207
SQL queries (postgresql)
Closed

Comments

  • bmwork started the conversation

    Hello,

    I've tried to enter query syntax to import data from PostgreSql. Query is fine for sure, it works under pgAdmin query tool. 

    Once I've pasted it into wpdatatables, an error occured. I re-write a query with 'ROW_NUMBER' instead of 'GROUP BY' and then it works.

    Wpdatatables plugin does not support 'GROUP BY' query syntax? Please find below exact error info.

    BR,

    Marek

    Error

    unknown [expr_type] = const in "GROUP" [0]


  •  2,572
    Aleksandar replied

    Hello Marek.

    We have a lot of customers use the GROUP BY syntax without any issues.

    Can you show me the full query?

    Also, if at all possible, can you please provide me a temporary WP-admin login for your site where this happens, so we could log in and take a look ‘from the inside’ as that’s the most efficient way to see and resolve the issue. We do not interfere with any data or anything else except for the plugin (in case that’s a production version of the site), and of course we do not provide login data to third party. You can write credentials here just check Private Reply so nobody can see them except us.

    Also, please make sure to tell me what's the table ID, so I know where to look.

    Best regards.

    Kind Regards, 

    Aleksandar Vuković
    [email protected]

    Rate my support

    wpDataTables: FAQ | Facebook | Twitter | InstagramFront-end and back-end demo | Docs

    Amelia: FAQ | Facebook | Twitter | InstagramAmelia demo sites | Docs | Discord Community

    You can try wpDataTables add-ons before purchasing on these sandbox sites:

    Powerful Filters | Gravity Forms Integration for wpDataTables | Formidable Forms Integration for wpDataTables | Master-Detail Tables

  • bmwork replied

    Hello Aleksandar,

    thanks for the reply. My PostgreSQL query looks as follows:

     SELECT tab."ID",
        tab."dStart",
        tab."dEnd",
        date_part('day'::text, tab."dEnd" - tab."dStart") AS "dDiff"
       FROM ( SELECT "vAdInfo"."ID",
                min("vAdInfo"."DownloadDate") AS "dStart",
                max("vAdInfo"."DownloadDate") AS "dEnd"
               FROM oto."vAdInfo"
              GROUP BY "vAdInfo"."ID") tab;

    When I store it on db server with 'CREATE VIEW' and paste just SELECT * FROM result_view, it works fine.


  •   bmwork replied privately
  •  2,572
    Aleksandar replied

    Hello again Marek.

    I tried to select just this part:

    SELECT vAdInfo."ID",
                min(vAdInfo."DownloadDate") AS "dStart",
                max(vAdInfo."DownloadDate") AS "dEnd"
               FROM vAdInfo

    but it said the table was either empty or non-existent. So, then I tried to select only from vAdInfo, but it also came back with the same error.

    Tell me, is vAdInfo located in a different database, sice I see you put the "oto" infront of it?

    If you try to create a table using the query generator for POSTGRESQL DB (the last option when creating the table), you'll see that it's not showing any tables, but I was able to create a table from `tab`, and that also leads me to believe the vAdInfo is located in a different DB.

    Also, is there a possibility to provide me with the database access, so I can log in and take a look?

    Best regards.

    Kind Regards, 

    Aleksandar Vuković
    [email protected]

    Rate my support

    wpDataTables: FAQ | Facebook | Twitter | InstagramFront-end and back-end demo | Docs

    Amelia: FAQ | Facebook | Twitter | InstagramAmelia demo sites | Docs | Discord Community

    You can try wpDataTables add-ons before purchasing on these sandbox sites:

    Powerful Filters | Gravity Forms Integration for wpDataTables | Formidable Forms Integration for wpDataTables | Master-Detail Tables

  • bmwork replied

    Aleksandar,

    Please consider 2 sql scripts. Both runs directly on PostgreSQL database (via PgAdmin4).

    Script 1:

    SELECT tab."ID",
        tab."dStart",
        tab."dEnd"
    FROM ( 
        SELECT "ID",
            min("DownloadDate") AS "dStart",
            max("DownloadDate") AS "dEnd"
        FROM oto."vAdInfo"
        GROUP BY "ID"
        ) tab
    

    Script 2:

    SELECT tmin.*, tmax."dEnd"
    FROM (
        SELECT "ID", "DownloadDate" as "dStart"
        FROM (
            SELECT "ID", "DownloadDate",
                ROW_NUMBER() OVER(PARTITION BY "ID" ORDER BY "DownloadDate" ASC) AS rn
            FROM oto."vAdInfo") tab
            WHERE tab.rn=1
        ) tmin
    JOIN (
        SELECT "ID", "DownloadDate" as "dEnd"
        FROM (
            SELECT "ID", "DownloadDate",
                ROW_NUMBER() OVER(PARTITION BY "ID" ORDER BY "DownloadDate" DESC) AS rn
            FROM oto."vAdInfo"
        ) tab
        WHERE tab.rn=1) tmax ON tmax."ID"=tmin."ID"
    

    Only Script 2 runs through wpDataTables plugin. Don't you think it's strange? ;)

    Prefix 'oto' means database schema. All the tables are in the same database but there are multiple schemas thus pure table name ("vAdInfo") it's not sufficient for querying. There is only 1 table named "vAdInfo" in whole database but prefix 'oto' is still mandatory (at least in pgAdmin4).

    I regret to inform you that at the moment direct DB access for you it's not possible. Tommorow we'll try to figure out a workaround for this.

    BR,

    Marek

  •   bmwork replied privately
  •  2,572
    Aleksandar replied

    Hello guys.

    Sorry for the late reply.

    I've been in for about an hour, trying to figure out what's going on here, but I must say that I'm at a loss.

    I see script 2 works without any issues, but what's puzzling, though, is that if I try to include all entries from `tab` or `tmin` it says the tables are empty and that we need to enter some data before continuing. The only thing that comes back with some results is SELECT * FROM oto."vAdInfo".

    At this point, DB connection would be very helpful, to see how it looks there. I'll call in one of my developers later in the day. Maybe he'll have some more ideas as to what's going on here.

    Best regards.

    Kind Regards, 

    Aleksandar Vuković
    [email protected]

    Rate my support

    wpDataTables: FAQ | Facebook | Twitter | InstagramFront-end and back-end demo | Docs

    Amelia: FAQ | Facebook | Twitter | InstagramAmelia demo sites | Docs | Discord Community

    You can try wpDataTables add-ons before purchasing on these sandbox sites:

    Powerful Filters | Gravity Forms Integration for wpDataTables | Formidable Forms Integration for wpDataTables | Master-Detail Tables

  • bmwork replied

    Hello Aleksandar,

    nice to see you again :)

    Please don't worry on those queries as it's pretty easy to find a workaround of such problems. I've posted it to help other customers by showing possible limitations of wpdatatables. And to help you as you probably have some QA or other test of your software.

    BR

    Marek

  •  2,572
    Aleksandar replied

    Ah, good to know Marek.

    Thank you.

    I'll ask you to keep the credentials for us so our developer can remote in and take a look after all.

    Thanks in advance.

    Best regards.

    Kind Regards, 

    Aleksandar Vuković
    [email protected]

    Rate my support

    wpDataTables: FAQ | Facebook | Twitter | InstagramFront-end and back-end demo | Docs

    Amelia: FAQ | Facebook | Twitter | InstagramAmelia demo sites | Docs | Discord Community

    You can try wpDataTables add-ons before purchasing on these sandbox sites:

    Powerful Filters | Gravity Forms Integration for wpDataTables | Formidable Forms Integration for wpDataTables | Master-Detail Tables