Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dlToc-0000VS-Os for pgsql-sql@arkaria.postgresql.org; Sat, 26 Aug 2017 05:39:26 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1dlToa-0001yh-Rr for pgsql-sql@arkaria.postgresql.org; Sat, 26 Aug 2017 05:39:24 +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.84_2) (envelope-from ) id 1dlTnc-0000FK-0e for pgsql-sql@postgresql.org; Sat, 26 Aug 2017 05:38:24 +0000 Received: from n3.nabble.com ([162.255.23.22]) by magus.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dlTnT-0008ON-VP for pgsql-sql@postgresql.org; Sat, 26 Aug 2017 05:38:23 +0000 Received: from n3.nabble.com (localhost [127.0.0.1]) by n3.nabble.com (Postfix) with ESMTP id ADE948103A2D for ; Fri, 25 Aug 2017 22:38:13 -0700 (MST) Date: Fri, 25 Aug 2017 22:38:13 -0700 (MST) From: anand086 To: pgsql-sql@postgresql.org Message-ID: <1503725893669-5980234.post@n3.nabble.com> Subject: Execute format Insert sql failing with query string argument of EXECUTE is null for column with timestamp with timezone MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_Part_87168_1250311417.1503725893670" List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-sql Precedence: bulk Sender: pgsql-sql-owner@postgresql.org ------=_Part_87168_1250311417.1503725893670 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit I am a Postgres Newbie and looking for some help on how I can achieve to have null in child table column with "timestamp with time zone" when using EXECUTE format insert sql.I have a range partitioned table by day and want to insert data into the current day's partition. Trigger is available on the master table based on which the data would be directed to current day's partition. But I want to directly insert data into the child table rather than using trigger to have it done.We have a table which maintains the child table names along with its low and high date values.Below is kind of what I am doing -- CREATE OR REPLACE FUNCTION test_tab_func (BIGINT, TIMESTAMP WITH TIME ZONE, TIMESTAMP WITH TIME ZONE)RETURNS booleanAS $BODY$DECLARE _id ALIAS FOR $1; _time ALIAS for $2; _parttime ALIAS for $3; _partition text; _z RECORD;BEGIN SELECT child_table_name into STRICT _partition from child_tables where parent_table_name='test_tab' and part_low=_parttime; FOR _z IN SELECT table_id, analyzed_on FROM test_tab WHERE schemaname = 'app' LOOP EXECUTE format('INSERT INTO dev.%s (id, time, table_id, analyzed_on) VALUES ('||_id|||', '''||_time ||''', '||_z.table_id||', '||_z.analyzed_on||')',_partition); END LOOP; RETURN true;END;$BODY$ LANGUAGE plpgsql; The table "test_tab" has few rows with analyzed_on as null. When I run the function I get the below errorERROR: query string argument of EXECUTE is null.I way which I know is using COALESCE. But how do I achieve null value in my child table using COALESCE. I am not able to figure it out. -- View this message in context: http://www.postgresql-archive.org/Execute-format-Insert-sql-failing-with-query-string-argument-of-EXECUTE-is-null-for-column-with-timee-tp5980234.html Sent from the PostgreSQL - sql mailing list archive at Nabble.com. ------=_Part_87168_1250311417.1503725893670 Content-Type: text/html; charset=us-ascii Content-Transfer-Encoding: 7bit I am a Postgres Newbie and looking for some help on how I can achieve to have null in child table column with "timestamp with time zone" when using EXECUTE format insert sql. I have a range partitioned table by day and want to insert data into the current day's partition. Trigger is available on the master table based on which the data would be directed to current day's partition. But I want to directly insert data into the child table rather than using trigger to have it done. We have a table which maintains the child table names along with its low and high date values. Below is kind of what I am doing --

CREATE OR REPLACE FUNCTION test_tab_func (BIGINT, TIMESTAMP WITH TIME ZONE, TIMESTAMP WITH TIME ZONE)
RETURNS boolean
AS 
$BODY$
DECLARE
  _id ALIAS FOR $1;
  _time ALIAS for $2;
  _parttime ALIAS for $3;
  _partition text;
  _z RECORD;
BEGIN

  SELECT child_table_name into STRICT _partition from child_tables where parent_table_name='test_tab' and part_low=_parttime;

  FOR _z IN SELECT table_id,
                   analyzed_on
              FROM test_tab
             WHERE schemaname = 'app' LOOP
       EXECUTE format('INSERT INTO dev.%s (id,
                                            time,
                                            table_id,
                                            analyzed_on)
                                             VALUES ('||_id|||',
                                                     '''||_time ||''',
                                                     '||_z.table_id||',
                                                     '||_z.analyzed_on||')',_partition);
  END LOOP;
  RETURN true;
END;
$BODY$
   LANGUAGE plpgsql;
The table "test_tab" has few rows with analyzed_on as null. When I run the function I get the below error ERROR: query string argument of EXECUTE is null. I way which I know is using COALESCE. But how do I achieve null value in my child table using COALESCE. I am not able to figure it out.

View this message in context: Execute format Insert sql failing with query string argument of EXECUTE is null for column with timestamp with timezone
Sent from the PostgreSQL - sql mailing list archive at Nabble.com.
------=_Part_87168_1250311417.1503725893670--