Re: Need help in spi_prepare errors

From: paresh masani <masaniparesh(at)gmail(dot)com>
To: Alvaro Herrera <alvherre(at)commandprompt(dot)com>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, pgsql-general(at)postgresql(dot)org
Subject: Re: Need help in spi_prepare errors
Date: 2009-10-08 04:07:46
Message-ID: a9d94e070910072107h3e757c51wbf2c87fab2fbcc1b@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

You were correct below trigger worked. Giving reference for others.

CREATE OR REPLACE FUNCTION init() RETURNS TEXT AS $$
my $raw_row = "(\"col1\", \"col2\")";
my @new_row = ('5', '6');
my @col_types = ("integer", "character varying");
my $query = "INSERT INTO mytable $raw_row VALUES (\$1, \$2)";
my $prepared = spi_prepare($query, @col_types);
spi_exec_prepared($prepared, @new_row);
return "success";
$$ LANGUAGE plperl;

Thanks, Paresh

On 10/7/09, Alvaro Herrera <alvherre(at)commandprompt(dot)com> wrote:
> Tom Lane escribió:
>
>> I'm not much of a Perl hacker, but I seem to recall that it's possible
>> to pass an array to a function in a way that will make the array
>> elements look like separate arguments. If you really need a dynamic
>> list of types and values, maybe there's some solution in that direction.
>
> Actually any time you pass an array as a parameter, the list is
> flattened and the function sees it as a plain list. If that doesn't
> seem to make sense, consider that if you pass two lists they will be
> flattened to a single list and you won't be able to tell where one
> ends and the other starts.
>
> If you really want two separate lists, you need to pass them as array
> references (i.e. \(at)myarray). I guess you could also pass an element
> count but that's not very perlish.
>
> --
> Alvaro Herrera http://www.CommandPrompt.com/
> PostgreSQL Replication, Consulting, Custom Development, 24x7 support
>

In response to

Browse pgsql-general by date

  From Date Subject
Next Message A. Kretschmer 2009-10-08 05:31:51 Re: Using complex PRIMARY KEY
Previous Message Kynn Jones 2009-10-07 20:59:01 Re: How to troubleshoot authentication failure?