Re: error on line 1 trying to execute a script using psql

Lists: pgsql-sql
From: Steven Dahlin <pgdb(dot)sldahlin(at)gmail(dot)com>
To: pgsql-sql(at)postgresql(dot)org
Subject: error on line 1 trying to execute a script using psql
Date: 2010-06-20 21:53:40
Message-ID: AANLkTikpLjmRR79VVEMH49RZTHzgEJcS-6sclTSmYP4O@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-sql

I am attempting to generate a temporary function to execute some dml with
the following script:

create or replace function setuplicense() returns integer as $$
declare
hwcustid integer := 0;
retval integer := 0;
begin
insert into license.customer
( customer_id ) values ( hwcustid );
commit;
return retval;
end;
$$
LANGUAGE plpgsql;

select setuplicense();

When running this with psql I get the following:

Error: syntax error at or near "create"

Does anyone have a suggestion as to what is causing this?

Thanks


From: Tim Landscheidt <tim(at)tim-landscheidt(dot)de>
To: pgsql-sql(at)postgresql(dot)org
Subject: Re: error on line 1 trying to execute a script using psql
Date: 2010-06-21 21:44:56
Message-ID: m3ocf42h7r.fsf@passepartout.tim-landscheidt.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-sql

Steven Dahlin <pgdb(dot)sldahlin(at)gmail(dot)com> wrote:

> I am attempting to generate a temporary function to execute some dml with
> the following script:

> create or replace function setuplicense() returns integer as $$
> declare
> hwcustid integer := 0;
> retval integer := 0;
> begin
> insert into license.customer
> ( customer_id ) values ( hwcustid );
> commit;
> return retval;
> end;
> $$
> LANGUAGE plpgsql;

> select setuplicense();

> When running this with psql I get the following:

> Error: syntax error at or near "create"

> Does anyone have a suggestion as to what is causing this?

Your editor prepends the file with a byte-order mark ("BOM")
that PostgreSQL chokes on (bug #5398). This will be fixed in
9.0 (cf.
<URI:http://developer.postgresql.org/pgdocs/postgres/release-9-0.html#AEN99331>);
until then you either have to configure your editor not to
save the BOM or chop off the first three bytes yourself
(with tail, sed, Perl & Co.).

Tim


From: "A(dot) Kretschmer" <andreas(dot)kretschmer(at)schollglas(dot)com>
To: pgsql-sql(at)postgresql(dot)org
Subject: Re: error on line 1 trying to execute a script using psql
Date: 2010-06-22 05:08:04
Message-ID: 20100622050803.GA13356@a-kretschmer.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-sql

In response to Tim Landscheidt :
> Steven Dahlin <pgdb(dot)sldahlin(at)gmail(dot)com> wrote:
>
> > I am attempting to generate a temporary function to execute some dml with
> > the following script:
>
> > create or replace function setuplicense() returns integer as $$
> > declare
> > hwcustid integer := 0;
> > retval integer := 0;
> > begin
> > insert into license.customer
> > ( customer_id ) values ( hwcustid );
> > commit;
> > return retval;
> > end;
> > $$
> > LANGUAGE plpgsql;
>
> > select setuplicense();
>
> > When running this with psql I get the following:
>
> > Error: syntax error at or near "create"
>
> > Does anyone have a suggestion as to what is causing this?
>
> Your editor prepends the file with a byte-order mark ("BOM")
> that PostgreSQL chokes on (bug #5398). This will be fixed in
> 9.0 (cf.
> <URI:http://developer.postgresql.org/pgdocs/postgres/release-9-0.html#AEN99331>);
> until then you either have to configure your editor not to
> save the BOM or chop off the first three bytes yourself
> (with tail, sed, Perl & Co.).

Additional error: you can't do a COMMIT inside a function.

Regards, Andreas
--
Andreas Kretschmer
Kontakt: Heynitz: 035242/47150, D1: 0160/7141639 (mehr: -> Header)
GnuPG: 0x31720C99, 1006 CCB4 A326 1D42 6431 2EB0 389D 1DC2 3172 0C99