Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.92) (envelope-from ) id 1j8Lfa-00062L-Sf for pgsql-sql@arkaria.postgresql.org; Sun, 01 Mar 2020 10:17:59 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1j8LfZ-0004AH-EH for pgsql-sql@arkaria.postgresql.org; Sun, 01 Mar 2020 10:17:57 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1j8LfY-0004A8-SX for pgsql-sql@lists.postgresql.org; Sun, 01 Mar 2020 10:17:57 +0000 Received: from sonic311-13.consmr.mail.bf2.yahoo.com ([74.6.131.123]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1j8LfW-0006fc-Jh for pgsql-sql@lists.postgresql.org; Sun, 01 Mar 2020 10:17:56 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1583057872; bh=Zh7AXmlubQN0FqOtRSNlYuED+wGyYtzGg1fMXPuh/GE=; h=Date:From:To:Subject:References:From:Subject; b=VBFs84HSfosubg7FOnx7R/UvAqy9ahbyyYYUhQ64cgpmYQhOxk7uz4dpSvO8LoqqdDcBvTphZNqHCecpCleZCHsNzm4C/WJZS1LGpmaVnEj0Ij/3qTPZlvLhdHN9oO9ZZ+rTL8BvSulZT7PqRdjxeRHeULPo20j+guKzDMA4OnbTgE3xoXe0hAIAVN18yOfMp1VeZOYgjo2R81vgz90rVCevH981YMq35CyqzXAbg2Xy6HByWHls4LuzoIFqMhcOy6YkEnBF0WQzvtRASc39GftIYr/desHEH54QrfnCT7K8k6v4GgK0tk40FghCvDt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n8H0Ir9RvafjkB66JIkqx4ycu w1lU2PvFE5AHjr9gglhq7iLbgRxwy8EMZ4ZK3_Mlz9ERrMo42U0Dtu3rEFa1ZJponEj9cqOSHuo. _Zus3020FSwK4PqaS9wJwrheNwaLRMb.pDYbd3KxU4ocUMddUHYh2XMyb8Wpj12LBvuvFKEYs9Y_ hdLrlowNWSGxtjMQ2jC0HWZZaQIIl511TN1ASe1_sifNFWr9gYIayimxPzatRWcm4RWTIbthAlUR 0aNW9UhG9Swpqg7HZktAm932CkCraUFCff3qh9tDJreFplTmfhNFT0XyY70ke_Wcfefhmtjnu_KF xqVYkHw-- Received: from sonic.gate.mail.ne1.yahoo.com by sonic311.consmr.mail.bf2.yahoo.com with HTTP; Sun, 1 Mar 2020 10:17:52 +0000 Date: Sun, 1 Mar 2020 10:17:48 +0000 (UTC) From: Karen Goh To: pgsql-sql@lists.postgresql.org Message-ID: <1063179739.1806448.1583057868061@mail.yahoo.com> Subject: What is the right syntax for retrieving the last_insert_id() in Postgresql ? MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit References: <1063179739.1806448.1583057868061.ref@mail.yahoo.com> X-Mailer: WebService/1.1.15302 YMailNodin Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:73.0) Gecko/20100101 Firefox/73.0 Content-Length: 2061 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Hi, I hope I am posting on the right forum. I googled but I can't find any solution pertaining to my problem. Could someone know what is the syntext for last_insert_id() in Postgresql for me to insert into my sql execute query? public int getTutorById() { openConnection(); int tutor_id = 0; try { Statement stmt3 = connection.createStatement(); ResultSet rs = stmt3.executeQuery("SELECT last_insert_id() from xtutor"); { while (rs.next()) { tutor_id = rs.getInt(1); } } } catch (SQLException e) { e.printStackTrace(); } return tutor_id; } org.postgresql.util.PSQLException: ERROR: function last_insert_id() does not exist Hint: No function matches the given name and argument types. You might need to add explicit type casts. Position: 8 at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2440) at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:2183) at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:308) at org.postgresql.jdbc.PgStatement.executeInternal(PgStatement.java:441) at org.postgresql.jdbc.PgStatement.execute(PgStatement.java:365) at org.postgresql.jdbc.PgStatement.executeWithFlags(PgStatement.java:307) at org.postgresql.jdbc.PgStatement.executeCachedSql(PgStatement.java:293) at org.postgresql.jdbc.PgStatement.executeWithFlags(PgStatement.java:270) at org.postgresql.jdbc.PgStatement.executeQuery(PgStatement.java:224) at daoMySql.tutorDAOImpl.getTutorById(tutorDAOImpl.java:202) at daoMySql.tutorDAOImpl.getAlltutors(tutorDAOImpl.java:161) at business.manager.getAlltutors(manager.java:99) The generated id is successfully generated by JDBC. The errors when I tested in out using PGAdmin4 is ERROR: function last_insert_id() does not exist LINE 1: SELECT last_insert_id() from xtutor; ^ HINT: No function matches the given name and argument types. You might need to add explicit type casts. SQL state: 42883 Character: 8 Postgresql 11, Windows 11 Thanks.