Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Value of type 'Any' has no member 'int'. Unable to fetch count of rows from PostgresClientKit

I am trying to fetch the count of rows from the PostgreSQL database using PostgresClientKit but I am getting the following error
Value of type ‘Any’ has no member ‘int’.

This is the code

let rows = fetchSQL(statement: "SELECT count(*) FROM ag_graph WHERE name='" + graphName + "'", connection: connection);
        
        let row_counts = rows[0] as! [Any];
        let count = try row_counts[0].int();
        if count < 1{
            // My Code
        }

I have tried printing the rows. It is

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

[[1]]

The definition of fetchSQL function is as follow

func fetchSQL(statement:String, connection:Connection)-> [Any]{
    var rows:[Any] = [];
    do{
        let statement = try connection.prepareStatement(text: statement)
        defer { statement.close() }
        
        let cursor = try statement.execute()
        defer { cursor.close() }

        for row in cursor {
            rows.append(try row.get().columns);
        }
    }catch{
        print(error)
    }
    
    return rows;
}

>Solution :

Try this way . It will probably help.

 let rows = fetchSQL(statement: "SELECT count(*) FROM ag_graph WHERE name='" + graphName + "'", connection: connection);
            print(rows)
            let row_counts = rows[0] as! [PostgresValue];
            let count = try row_counts[0].int();
            if count < 1{
                // your code
            }
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading