Re: Insert UUID GEN 4 Value

From: C GG <cgg0007(at)gmail(dot)com>
To: tango ward <tangoward15(at)gmail(dot)com>
Cc: 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 12:36:36
Message-ID: CAJXW-z8WRRP6Y87gbEPjRSD+jxu_a-HFVpJtXxTurX4wjFpdDQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Thu, May 31, 2018 at 12:45 AM, tango ward <tangoward15(at)gmail(dot)com> wrote:

> On Thu, May 31, 2018 at 12:06 PM, Rob Sargent <robjsargent(at)gmail(dot)com>
> wrote:
>
>>
>>
>> On May 30, 2018, at 9:57 PM, tango ward <tangoward15(at)gmail(dot)com> wrote:
>>
>> On Thu, May 31, 2018 at 11:53 AM, tango ward <tangoward15(at)gmail(dot)com>
>> wrote:
>>
>>> On Thu, May 31, 2018 at 11:51 AM, Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at
>>> > wrote:
>>>
>>>> tango ward wrote:
>>>> > I found this:
>>>> >
>>>> > CREATE EXTENSION IF NOT EXISTS "uuid-ossp";
>>>> > SELECT uuid_generate_v4();
>>>> >
>>>> > My problem is I have a table like this:
>>>> > CREATE TABLE enrollmentinfo (
>>>> > id integer NOT NULL,
>>>> > created timestamp with time zone NOT NULL,
>>>> > modified timestamp with time zone NOT NULL,
>>>> > secure_id uuid NOT NULL,
>>>> > relationship character varying(50) NOT NULL,
>>>> > tuition_bill character varying(255) NOT NULL
>>>> > );
>>>> >
>>>> > Now I need to insert data into this table, I just don't know if I can
>>>> use something like this
>>>> > "INSERT INTO enrollmentinfo (current_timestamp, current_timestamp,
>>>> uuid_generate_v4(), '', '');
>>>> > I haven't tried this but also not sure if I can call the function
>>>> inside INSERT.
>>>>
>>>> Why didn't you try it?
>>>>
>>>> I see no problem with that.
>>>>
>>>> Yours,
>>>> Laurenz Albe
>>>> --
>>>> Cybertec | https://www.cybertec-postgresql.com
>>>>
>>>>
>>>
>>> Okay I will try it.
>>>
>>
>> When I tried it, I am getting an error: Invalid input syntax for UUID:
>> uuid_generate_v4(),
>>
>> What do you get from
>> Select uuid_generate_v4();
>>
>
> If I try these in psql, CREATE EXTENSION IF NOT EXISTS "uuid-ossp"; SELECT
> uuid_generate_v4();
>
> I am getting the generated code but I dunno how to use this in INSERT
> statement. I am getting an error of invalid input systex for UUID.
>

Hello,

Using INSERT (..) VALUES (..) won't execute functions. It expects literal
values. Instead do something like

INSERT INTO enrollmentinfo (id, created, modified, secure_id, relationship,
tuition_bill) SELECT your_id_returning_function_or_a_literal_value(),
current_timestamp, current_timestamp, uuid_generate_v4(), 'some
relationship', 'some tuition bill text';

...modified with real values, of course...

That should get you over the hump. Good luck on your project!

CG

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Fabio Pardi 2018-05-31 12:58:40 Re: Long running DDL statements blocking all queries
Previous Message Ashu Pachauri 2018-05-31 12:26:19 Re: Long running DDL statements blocking all queries