PostgreSQL query with function gen_random_uuid() not working on Windows

AnkitG picture AnkitG · Oct 27, 2015 · Viewed 10.3k times · Source

I have the following query for creating a table,

CREATE TABLE IF NOT EXISTS company (
    id uuid CONSTRAINT companyid PRIMARY KEY DEFAULT gen_random_uuid(),
    name varchar(128) NOT NULL,
    db_uri varchar(255) NOT NULL,
    c_uri varchar(255) NOT NULL,
    date_c timestamp DEFAULT now(),
    date_m timestamp DEFAULT now()
    ) WITH (fillfactor=90);

I am getting the following error when I run it through pgAdminIII.

ERROR:  function gen_random_uuid() does not exist
HINT:  No function matches the given name and argument types. You might need to add explicit type casts.
********** Error **********
ERROR: function gen_random_uuid() does not exist
SQL state: 42883
Hint: No function matches the given name and argument types. You might need to add explicit type casts.

I have created an extension pgcrypto as that contains gen_random_uuid() function definition but that also did not help.

I ran the same scripts on a MAC and it all worked fine.

I am using PostgreSQL 9.3.

Answer

AnkitG picture AnkitG · Oct 27, 2015

The issue was with Version of PostgreSQL.

It is in PostgreSQL 9.4 up that, pgcrypto has the gen_random_uuid() function.

Got the new version installed and it was all good!

http://www.postgresql.org/docs/9.3/static/pgcrypto.html

http://www.postgresql.org/docs/9.4/static/pgcrypto.html