Re: Insert UUID GEN 4 Value

From: Adrian Klaver <adrian(dot)klaver(at)aklaver(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: C GG <cgg0007(at)gmail(dot)com>, tango ward <tangoward15(at)gmail(dot)com>, Rob Sargent <robjsargent(at)gmail(dot)com>, Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>, "pgsql-generallists(dot)postgresql(dot)org" <pgsql-general(at)lists(dot)postgresql(dot)org>
Subject: Re: Insert UUID GEN 4 Value
Date: 2018-05-31 14:23:43
Message-ID: 67869175-6d10-9ac0-4e71-2fcb996f313d@aklaver.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 05/31/2018 06:39 AM, Tom Lane wrote:
> Adrian Klaver <adrian(dot)klaver(at)aklaver(dot)com> writes:
>> My suspicion is it had to do with this from a post upstream:
>> "When I tried it, I am getting an error: Invalid input syntax for UUID:
>> uuid_generate_v4(),"
>
> Yeah. We haven't seen the actual query yet, but I'm betting the OP
> really wrote
>
> INSERT ... , 'uuid_generate_v4()', ...
>
> not
>
> INSERT ... , uuid_generate_v4(), ...
>
> There might be some layers of client-side parameter mangling obscuring
> what's actually happening.

I would tend to agree:

\d uuid_test
Table "public.uuid_test"
Column | Type | Collation | Nullable | Default
----------+------+-----------+----------+---------
uuid_fld | uuid |

insert into uuid_test values (uuid_generate_v4());
INSERT 0 1

select * from uuid_test ;
uuid_fld
--------------------------------------
f4bc853b-0c05-437b-904a-825cc6d3ea7b

In Python(using psycopg2) which is what the OP is using;

cur.execute("INSERT INTO uuid_test values(uuid_generate_v4())")

con.commit()

cur.execute("SELECT uuid_fld FROM uuid_test")

rs = cur.fetchall()

rs
[('f4bc853b-0c05-437b-904a-825cc6d3ea7b',),
('9e55f5ea-c504-4847-8674-05202ec499c6',)]

From this post:

https://www.postgresql.org/message-id/CAA6wQLLVpjtxAhPy3K1f63WtvqjK4QrzBLKjeh0PDUOyCvbT2Q%40mail.gmail.com

the OP seems to be on the right track. So something else is happening.

>
> regards, tom lane
>

--
Adrian Klaver
adrian(dot)klaver(at)aklaver(dot)com

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Adrian Klaver 2018-05-31 14:33:32 Re: Insert UUID GEN 4 Value
Previous Message Dennis Gearon 2018-05-31 14:22:00 Re: Insert UUID GEN 4 Value