3

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.

AnkitG
  • 305
  • 1
  • 4
  • 15
  • If you installed `pgcrypto` in a schema other then `public`, add the schema name to `search_path`. – klin Oct 27 '15 at 07:10
  • Did you try restarting Postgres? – Tim Biegeleisen Oct 27 '15 at 07:10
  • 1
    How did you install the extension? Can you show us your **exact** statement? What does `\dx` show you? Did you maybe forget to `commit` the `create extension` statement? Or did you maybe install it into a different database (extensions are installed per database, not globally) –  Oct 27 '15 at 07:10
  • 2
    I created the extension using `CREATE EXTENSION "pgcrypto";' command. It is showing up in the Extensions in the db in pgAdmin. – AnkitG Oct 27 '15 at 07:49
  • @tim- I restrated, nothing changed. – AnkitG Oct 27 '15 at 07:59
  • @Vivek.S- It was 9.3, on my Mac i recently downloaded the latest 9.4 but on windows I had this since some time and it was 9.3. This function is not under pgcrypto in PostgrSQL 9.3. Thanks! – AnkitG Oct 27 '15 at 08:08
  • CREATE EXTENSION "uuid-ossp"; – justi Jul 10 '17 at 10:51

1 Answers1

5

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

AnkitG
  • 305
  • 1
  • 4
  • 15