pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Susan Hurst <susan.hurst@brookhurstdata.com>
To: pgsql-general@lists.postgresql.org
Subject: array must have even number of elements
Date: Thu, 20 Sep 2018 12:55:05 -0500
Message-ID: <c0c90d03d4c8554045cb0e77bb81adf9@mail.brookhurstdata.net> (raw)


Why must an array have an even number of elements?  I need to use a 
trigger function on any table, some of which may have an odd number of 
columns that I want to cleanse before inserting/updating.


Is there a workaround for this?


ERROR: array must have even number of elements

SQL state: 2202E

Context: SQL statement "SELECT ($1 #= 
hstore(array[trim(replace(regexp_replace($1.c,'( ){2,}',' ','g'),' ',' 
')),trim(replace(regexp_replace($1.vc,'( ){2,}',' ','g'),' ',' 
')),trim(replace(regexp_replace($1.t,'( ){2,}',' ','g'),' ',' '))])).*" 
PL/pgSQL function store.trim_string_before_dml() line 44 at EXECUTE



--  my test table
create table dm.trg_test (c character(8), vc varchar(16), t text);
insert into dm.trg_test (c,vc,t) values ('ctest','   vctest  ','       
ttest       ');


-- code snippet that produced the error.
-- new will be substituted for $1 during execution with using clause
l_query_string := 'select ($1 #= hstore(array[' || l_column_list || 
'])).*';
execute format(l_query_string) using  new into   new;
return new;


Thanks for your help!

-- 
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Susan E Hurst
Principal Consultant
Brookhurst Data LLC
Email: susan.hurst@brookhurstdata.com
Mobile: 314-486-3261




view thread (4+ messages)  latest in thread

Message-ID: <c0c90d03d4c8554045cb0e77bb81adf9@mail.brookhurstdata.net>
Permalink:  ../c0c90d03d4c8554045cb0e77bb81adf9@mail.brookhurstdata.net/
Also on:    postgresql.org/message-id/c0c90d03d4c8554045cb0e77bb81adf9@mail.brookhurstdata.net

 · 

reply

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: susan.hurst@brookhurstdata.com
  Subject: Re: array must have even number of elements
  In-Reply-To: <c0c90d03d4c8554045cb0e77bb81adf9@mail.brookhurstdata.net>
  References: <c0c90d03d4c8554045cb0e77bb81adf9@mail.brookhurstdata.net>

* 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