From: Adrian Klaver <adrian.klaver@aklaver.com>
To: C GG <cgg0007@gmail.com>
To: tango ward <tangoward15@gmail.com>
Cc: Rob Sargent <robjsargent@gmail.com>
Cc: Laurenz Albe <laurenz.albe@cybertec.at>
Cc: pgsql-generallists.postgresql.org <pgsql-general@lists.postgresql.org>
Subject: Re: Insert UUID GEN 4 Value
Date: Thu, 31 May 2018 06:11:24 -0700
Message-ID: <cf450e00-3e92-4d25-c34e-5d208edfc64c@aklaver.com> (raw)
In-Reply-To: <CAJXW-z8WRRP6Y87gbEPjRSD+jxu_a-HFVpJtXxTurX4wjFpdDQ@mail.gmail.com>
References: <CAA6wQLK1MLj6gL9wQYLNZD541_xJjbv9X5EzVADOtMhQnifc9w@mail.gmail.com>
<1527738102.2400.1.camel@cybertec.at>
<CAA6wQLJr6fjzx+ZK6N4yiViZYdFuGGkMT27zsp-mR1SjAzbGEg@mail.gmail.com>
<1527738710.2400.4.camel@cybertec.at>
<CAA6wQLLwGQC=szWF46ye+yh6dhuAUtgkwNhM6K5UmUc0M3B97Q@mail.gmail.com>
<CAA6wQLJ_tpazkwPOuO6yuqaVYaqDK0c1ZPkdp7vQtY0h6xm15Q@mail.gmail.com>
<74277212-DEDF-4A35-B0BB-25A92088B2A1@gmail.com>
<CAA6wQL+8TmzT9T7jwkOuBd7ZH22C=Y44Cje7Zt3pMYnx7V6i5w@mail.gmail.com>
<CAJXW-z8WRRP6Y87gbEPjRSD+jxu_a-HFVpJtXxTurX4wjFpdDQ@mail.gmail.com>
On 05/31/2018 05:36 AM, C GG wrote:
>
> On Thu, May 31, 2018 at 12:45 AM, tango ward <tangoward15@gmail.com
> <mailto:tangoward15@gmail.com>> wrote:
>
> On Thu, May 31, 2018 at 12:06 PM, Rob Sargent <robjsargent@gmail.com
> <mailto:robjsargent@gmail.com>> wrote:
>
>
>
> On May 30, 2018, at 9:57 PM, tango ward <tangoward15@gmail.com
> <mailto:tangoward15@gmail.com>> wrote:
>
>> On Thu, May 31, 2018 at 11:53 AM, tango ward
>> <tangoward15@gmail.com <mailto:tangoward15@gmail.com>> wrote:
>>
>> On Thu, May 31, 2018 at 11:51 AM, Laurenz Albe
>> <laurenz.albe@cybertec.at
>> <mailto:laurenz.albe@cybertec.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
>>
>> <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
That is not the case:
https://www.postgresql.org/docs/10/static/sql-insert.html
"VALUES ( { expression | DEFAULT } [, ...] ) [, ...] | query }
...
expression
An expression or value to assign to the corresponding column.
"
\d ts_tsz_test
Table "public.ts_tsz_test"
Column | Type | Collation | Nullable | Default
--------+-----------------------------+-----------+----------+---------
fld_1 | timestamp without time zone | | |
fld_2 | timestamp with time zone | | |
fld_3 | integer | | |
CREATE OR REPLACE FUNCTION public.test_fnc()
RETURNS integer
LANGUAGE plpgsql
AS $function$
BEGIN
RETURN 2;
END;
$function$
insert into ts_tsz_test values (localtimestamp(2), current_timestamp(2),
test_fnc());
INSERT 0 1
select * from ts_tsz_test ;
fld_1 | fld_2 | fld_3
------------------------+---------------------------+-------
2018-05-31 06:06:39.71 | 2018-05-31 06:06:39.71-07 | 2
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(),"
Namely the output of the function is not meeting the input syntax for
the uuid field.
>
> 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
>
>
>
>
>
--
Adrian Klaver
adrian.klaver@aklaver.com
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-general@postgresql.org
Cc: adrian.klaver@aklaver.com, cgg0007@gmail.com, tangoward15@gmail.com, robjsargent@gmail.com, laurenz.albe@cybertec.at
Subject: Re: Insert UUID GEN 4 Value
In-Reply-To: <cf450e00-3e92-4d25-c34e-5d208edfc64c@aklaver.com>
References: <CAA6wQLK1MLj6gL9wQYLNZD541_xJjbv9X5EzVADOtMhQnifc9w@mail.gmail.com> <1527738102.2400.1.camel@cybertec.at> <CAA6wQLJr6fjzx+ZK6N4yiViZYdFuGGkMT27zsp-mR1SjAzbGEg@mail.gmail.com> <1527738710.2400.4.camel@cybertec.at> <CAA6wQLLwGQC=szWF46ye+yh6dhuAUtgkwNhM6K5UmUc0M3B97Q@mail.gmail.com> <CAA6wQLJ_tpazkwPOuO6yuqaVYaqDK0c1ZPkdp7vQtY0h6xm15Q@mail.gmail.com> <74277212-DEDF-4A35-B0BB-25A92088B2A1@gmail.com> <CAA6wQL+8TmzT9T7jwkOuBd7ZH22C=Y44Cje7Zt3pMYnx7V6i5w@mail.gmail.com> <CAJXW-z8WRRP6Y87gbEPjRSD+jxu_a-HFVpJtXxTurX4wjFpdDQ@mail.gmail.com> <cf450e00-3e92-4d25-c34e-5d208edfc64c@aklaver.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox