Re: cannot create table using pl/perl

From: Michael Fuhr <mike(at)fuhr(dot)org>
To: Jim Bryan <gooddayarizona(at)yahoo(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: cannot create table using pl/perl
Date: 2006-08-13 14:10:57
Message-ID: 20060813141057.GA27347@winnie.fuhr.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Sat, Aug 12, 2006 at 02:04:42PM -0700, Jim Bryan wrote:
> Installed latest postgresql 8 on windows xp,
> everything works fine with pl/pgsql; problems creating
> a table with perl however:
>
> CREATE OR REPLACE FUNCTION datetable() RETURNS integer
> AS $$
> CREATE TABLE tabletest
> (
> dayofmonth int4,
> monthofyear int4,
> theyear int4
> )
> $$
> LANGUAGE 'plperlu' ;

That function body isn't Perl code; to execute SQL commands you'll
need to use spi_exec_query or spi_query(). Here's an example that
uses a here-document; note also "RETURNS void" since the function
doesn't return anything useful:

CREATE OR REPLACE FUNCTION datetable() RETURNS void AS $$
spi_exec_query(<<END_OF_SQL);
CREATE TABLE tabletest
(
dayofmonth int4,
monthofyear int4,
theyear int4
)
END_OF_SQL
$$
LANGUAGE plperl;

--
Michael Fuhr

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Jorge Godoy 2006-08-13 14:20:39 Re: Best approach for a "gap-less" sequence
Previous Message Thomas Kellerer 2006-08-13 13:16:05 Re: Migrating PostgreSQL database to MySQL/MS Access