Received: from malur.postgresql.org ([2a02:16a8:dc51::56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fONMg-0005md-BT for pgsql-general@arkaria.postgresql.org; Thu, 31 May 2018 13:11:38 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1fONMf-0005IP-0H for pgsql-general@arkaria.postgresql.org; Thu, 31 May 2018 13:11:37 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fONMd-0005I0-5w for pgsql-general@lists.postgresql.org; Thu, 31 May 2018 13:11:36 +0000 Received: from out1-smtp.messagingengine.com ([66.111.4.25]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fONMX-00077O-7T for pgsql-general@lists.postgresql.org; Thu, 31 May 2018 13:11:34 +0000 Received: from compute6.internal (compute6.nyi.internal [10.202.2.46]) by mailout.nyi.internal (Postfix) with ESMTP id CB26621C19; Thu, 31 May 2018 09:11:26 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute6.internal (MEProxy); Thu, 31 May 2018 09:11:26 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aklaver.com; h= cc:content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-me-sender :x-me-sender:x-sasl-enc; s=fm3; bh=dOy2IcU2L0EE3bPB6QiZP4O4jj3qT UbAvLc1mPwvZzE=; b=qu5QcNq+Pv3I+9nCF0X2L+ojK9zSed6Ex9QqBVWSXAvJJ Xq8o48p8blEkXUkWfXmcxPJcfwVBdCHYGgLy6izwaX5LpLjZszPIWqCVhenMwkPv Uwilb6o6wTdyeDrhPdqYj9y0GfF6Gfyp4gDTl9dEKJw3wrAviioZDJNpJKhm5cw0 epbciI8RO6DKre01nR78Qgcn1D0fiz/9FDE4r5FMPIlz1WqvwAGu7eAzTS0fYKyR yTyt9pA+qRxX1AJQ5BR+VJBysIHX9scirFaOw7VcQbZPG5pmS8L0hz1KEUVQbcCb g63QU9qTLu0f/VaqCbccAnyNohH6MVx4D6SzPAnVg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-sender:x-me-sender:x-sasl-enc; s=fm2; bh=dOy2Ic U2L0EE3bPB6QiZP4O4jj3qTUbAvLc1mPwvZzE=; b=fpZlNvSU0AOTE05n64WbNA nVKdEcK0bYIhGed4qsIb5xxGer35gLxZJ9jMBoHenu1wuToAlAZsfzSiwlevCUkd hpNIMwEesfPOAu5xLt+GFIQolVq9PzDf1WkZmxjBYTRoKBI/SnEtYyCXNjPQSnnJ KlODU8gKJ0nylltDuLqRC8W96O0eALpj587MuE7/9yYG6T7WztdTsax5s80lgPHv aN91GTT0/ko8NzgqzJwiEFyg3ODb99Mk44Ew6xTMQuxlGHHxew7olZSUJWO0Xzef 4OWm2jGfQ0XYZSmSp8n8mH/ydI8TxD1mzERduvvhTGNomUpsF8d3C6ldUiNQ/8dQ == X-ME-Proxy: X-ME-Proxy: X-ME-Proxy: X-ME-Proxy: X-ME-Proxy: X-ME-Proxy: X-ME-Sender: Received: from [192.168.1.3] (unknown [71.212.159.209]) by mail.messagingengine.com (Postfix) with ESMTPA id BA05D102E9; Thu, 31 May 2018 09:11:25 -0400 (EDT) Subject: Re: Insert UUID GEN 4 Value To: C GG , tango ward Cc: Rob Sargent , Laurenz Albe , "pgsql-generallists.postgresql.org" References: <1527738102.2400.1.camel@cybertec.at> <1527738710.2400.4.camel@cybertec.at> <74277212-DEDF-4A35-B0BB-25A92088B2A1@gmail.com> From: Adrian Klaver Message-ID: Date: Thu, 31 May 2018 06:11:24 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.8.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 05/31/2018 05:36 AM, C GG wrote: > > On Thu, May 31, 2018 at 12:45 AM, tango ward > wrote: > > On Thu, May 31, 2018 at 12:06 PM, Rob Sargent > wrote: > > > > On May 30, 2018, at 9:57 PM, tango ward > wrote: > >> On Thu, May 31, 2018 at 11:53 AM, tango ward >> > wrote: >> >> On Thu, May 31, 2018 at 11:51 AM, Laurenz Albe >> > > 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 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