From: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
---|---|
To: | Thiemo Kellner <thiemo(at)thiam(dot)ch> |
Cc: | pgGeneral pgGeneral <pgsql-general(at)postgresql(dot)org>, pgNovice(at)thiam(dot)ch |
Subject: | Re: Error >>syntax error<< at >>$1<< at character 53 |
Date: | 2004-08-09 00:27:05 |
Message-ID: | 23679.1092011225@sss.pgh.pa.us |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general pgsql-novice |
Thiemo Kellner <thiemo(at)thiam(dot)ch> writes:
> I try to code a PL/pgSQL function, but always get to an execution error, I =
> am=20
> unable to solve:
> create or replace function GET_SUMMARY() returns integer as '
> declare
> STR_SOURCE_NAME constant pg_catalog.pg_views.viewname%type
> :=3D \'BUCHUNGEN\';
> STR_OBJEKTVIEW constant pg_catalog.pg_views.viewname%type
^^^^^^^^^^^^^^
> :=3D \'OBJEKTHIERARCHIE\';
> R_OBJEKTHIERARCHIE record;
> TXT text;
> begin
> for R_OBJEKTHIERARCHIE in
> select
> OBJEKTKATEGORIE,
> OBJEKTGRUPPE,
> OBJEKT
> from
> STR_OBJEKTVIEW
^^^^^^^^^^^^^^
> loop
Don't use plpgsql variables named the same as tables or fields that you
need to reference in queries inside the function. plpgsql will think it
ought to substitute the variable value as a parameter.
8.0devel generates a more useful error message from this function:
regression=# select get_summary();
ERROR: syntax error at or near "$1" at character 53
QUERY: select OBJEKTKATEGORIE, OBJEKTGRUPPE, OBJEKT from $1
CONTEXT: PL/pgSQL function "get_summary" line 9 at for over select rows
LINE 1: select OBJEKTKATEGORIE, OBJEKTGRUPPE, OBJEKT from $1
^
Here you can actually see the query string fed to the SQL engine,
and see that STR_OBJEKTVIEW got replaced by a parameter symbol,
which of course is not going to work.
regards, tom lane
From | Date | Subject | |
---|---|---|---|
Next Message | Dino Nardini | 2004-08-09 01:22:41 | Re: pg jdbc driver |
Previous Message | Clodoaldo Pinto Neto | 2004-08-09 00:15:07 | How copy a new line char to a file? |
From | Date | Subject | |
---|---|---|---|
Next Message | A Gilmore | 2004-08-09 03:44:07 | Re: Design question regarding arrays |
Previous Message | Tom Lane | 2004-08-08 20:26:10 | Re: Multiple return 'columns' from postgre pl/pgsql |