pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Cere Davis <ceremona@gmail.com>
To: Chris Browne <cbbrowne@acm.org>
Cc: pgsql-sql@postgresql.org
Subject: Re: stored procs in postgresql
Date: Sat, 24 Sep 2005 21:10:48 -0700
Message-ID: <c666e3db05092421106c6bab2b@mail.gmail.com> (raw)
In-Reply-To: <60vf0qma14.fsf@dba2.int.libertyrms.com>
References: <op.sxmghwnc1qrx7c@localhost>
	<60vf0qma14.fsf@dba2.int.libertyrms.com>

thanks,

I didn't even know about the string concatination function for this. 
Unfortunately, it was of no help.  Specificly I am trying this, with
the following error:

SQL error:


ERROR:  syntax error at or near "' || $2 || '" at character 110

In statement:


CREATE FUNCTION "getcensusbound" (geometry, character) RETURNS
character AS 'SELECT bound_table.name
   FROM '' || $2 || '' bound_table
  WHERE bound_table.the_geom::bytea != ''null''::bytea AND
contains(geometryn(bound_table.the_geom, 1), $1) = true;' LANGUAGE
"sql"
RETURNS NULL ON NULL INPUT


-Cere


On 9/24/05, Chris Browne <cbbrowne@acm.org> wrote:
> ceremona@gmail.com writes:
> > I have been having some trouble with plsql stored procs in postgres in
> > that I can
> > make a table name a variable in the stored proc.  Is there some
> > special  way to make this happen that I am unaware of?
> >
> > For example, I want to do something like:
> >
> > stored_proc(integer,varchar)
> >
> > SELECT table_name.id
> >     FROM table_name $2
> >    WHERE table_name.id=$1
> >
> > but I get an error about the $2 argument being no good.
> >
> > Does anyone know how I can deal with this?
>
> To do this sort of thing, you need to build up the query as a string,
> and EXECUTE it.
>
> Thus...
>    query := 'select t.id from ' || $2 || ' t where t.id = ' || $1 || ';';
>
> The other vital problem is that the select is in bad form.  The actual
> name of the table needs to come BEFORE the alias, not after.
>
> The following would represent more nearly legitimate SQL...
>
>   SELECT table_name.id
>       FROM $2 table_name
>      WHERE table_name.id=$1
> --
> let name="cbbrowne" and tld="cbbrowne.com" in String.concat "@" [name;tld];;
> http://cbbrowne.com/info/spiritual.html
> And me, with this terrible pain in all the diodes down my left side...
> -- Marvin the Paranoid Android
>
> ---------------------------(end of broadcast)---------------------------
> TIP 1: if posting/reading through Usenet, please send an appropriate
>        subscribe-nomail command to majordomo@postgresql.org so that your
>        message can get through to the mailing list cleanly
>


--
Cere Davis
ceremona@gmail.com
-------------------
GPG Key:  http://staff.washington.edu/cere/pubkey.asc
GPG fingerprint (ID# 73FCA9E6) : F5C7 627B ECBE C735 117B  2278 9A95
4C88 73FC A9E6



view thread (4+ messages)  latest in thread

Message-ID: <c666e3db05092421106c6bab2b@mail.gmail.com>
Permalink:  ../c666e3db05092421106c6bab2b@mail.gmail.com/
Also on:    postgresql.org/message-id/c666e3db05092421106c6bab2b@mail.gmail.com

 · 

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 using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: ceremona@gmail.com, cbbrowne@acm.org
  Subject: Re: stored procs in postgresql
  In-Reply-To: <c666e3db05092421106c6bab2b@mail.gmail.com>

* 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