Re: PL/pgSQL syntax for strings

From: "Edward Grabczewski" <edward(dot)grabczewski(at)btinternet(dot)com>
To: pgsql-sql(at)postgresql(dot)org
Subject: Re: PL/pgSQL syntax for strings
Date: 2001-11-02 03:45:19
Message-ID: 9rt4jd$u4r$1@news.tht.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Sorry about the function not makig sense. It's only half-baked until I get
this string thing sorted out. I left the hard-coded numerical values there
for testing purposes only - so I guess it confused everyone. As it happens
the syntax of the posted function actually works. Even the backslashes! Now
the trick is to incorporate the variables into the string. I've looked at
the documentation a few times and I've experimented but failed to get the
right syntax so far - which is why I thought I'd ask for some help. :-)

Below is what the function will eventually look like when it uses the proper
variables: I guessed that the single quote needs to be double quoted:

''''('' x1 '','' z1 ''), ('' x2 '','' z2 '')''''

or something like that. Should this work?

Eddy

CREATE TABLE rtest (
xz BOX,
yz BOX,
xy BOX);

CREATE INDEX rtest_xz_index ON rtest USING RTREE (xz bigbox_ops);
CREATE INDEX rtest_yz_index ON rtest USING RTREE (yz bigbox_ops);
CREATE INDEX rtest_xy_index ON rtest USING RTREE (xy bigbox_ops);

DROP FUNCTION threedpoint (float,float,float, float,float,float);
CREATE FUNCTION threedpoint (float,float,float,float,float,float)
RETURNS text
AS 'DECLARE
x1 ALIAS FOR $1;
y1 ALIAS FOR $2;
z1 ALIAS FOR $3;
x2 ALIAS FOR $4;
y2 ALIAS FOR $5;
z2 ALIAS FOR $6;
BEGIN
INSERT INTO rtest(xz,yz,xy)
VALUES ( '(x1,z1), (x2,z2)',
'(y1,y2), (y2,z2)',
'(x1,y1), (x2,y2)');
RETURN null;
END;'
LANGUAGE 'plpgsql';

SELECT threedpoint(100,200,300,400,500,600);

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message sharmad 2001-11-02 04:05:06 debugging
Previous Message Bhuvan A 2001-11-02 02:56:33 SELECT statement during transaction