pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Quotes and spaces
4+ messages / 3 participants
[nested] [flat]

* Quotes and spaces
@ 2001-10-05 22:28  Oleg Lebedev <olebedev@waterford.org>
  0 siblings, 2 replies; 4+ messages in thread

From: Oleg Lebedev @ 2001-10-05 22:28 UTC (permalink / raw)
  To: Stephan Szabo <sszabo@megazone23.bigpanda.com>; +Cc: Marat Khairullin <xmm@rambler.ru>; pgsql-sql

Hi,
I looked through PL/pgSQL tutorial, but I can't get quotes and spaces to
work in queries executed from Pl/pgSQl. Here is an example:

create procedure get_name(varchar)
...
BEGIN
    query := ''SELECT first_name || '''' '''' || last_name FROM user'';
    EXECUTE query;
...
END;
...

Basically I want to get full name, i.e. first name separated with space from
the last name. If I follow the PL/pgSQL manual as shown above, I get parse
error.
What am I doing wrong?
thanks,

Oleg





^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: Quotes and spaces
@ 2001-10-05 22:51  Josh Berkus <josh@agliodbs.com>
  parent: Oleg Lebedev <olebedev@waterford.org>
  1 sibling, 0 replies; 4+ messages in thread

From: Josh Berkus @ 2001-10-05 22:51 UTC (permalink / raw)
  To: Oleg Lebedev <olebedev@waterford.org>; Stephan Szabo <sszabo@megazone23.bigpanda.com>; +Cc: Marat Khairullin <xmm@rambler.ru>; pgsql-sql

Oleg,

I'm assuming that this is just a hypothetical example, as the below is
far from the fastest way to get something as simple as a name.

> BEGIN
>     query := ''SELECT first_name || '''' '''' || last_name FROM
> user'';
>     EXECUTE query;
> ...
> END;
> ...

I'm pretty sure your quotes are correct.  However, I believe "query" is
a reserved word.  Try using a different variable name.

-Josh

______AGLIO DATABASE SOLUTIONS___________________________
                                       Josh Berkus
  Complete information technology      josh@agliodbs.com
   and data management solutions       (415) 565-7293
  for law firms, small businesses        fax 621-2533
    and non-profit organizations.      San Francisco







^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: Quotes and spaces
@ 2001-10-05 23:31  Stephan Szabo <sszabo@megazone23.bigpanda.com>
  parent: Oleg Lebedev <olebedev@waterford.org>
  1 sibling, 1 reply; 4+ messages in thread

From: Stephan Szabo @ 2001-10-05 23:31 UTC (permalink / raw)
  To: Oleg Lebedev <olebedev@waterford.org>; +Cc: Marat Khairullin <xmm@rambler.ru>; pgsql-sql

On Fri, 5 Oct 2001, Oleg Lebedev wrote:

> Hi,
> I looked through PL/pgSQL tutorial, but I can't get quotes and spaces to
> work in queries executed from Pl/pgSQl. Here is an example:
> 
> create procedure get_name(varchar)
> ...
> BEGIN
>     query := ''SELECT first_name || '''' '''' || last_name FROM user'';
>     EXECUTE query;
> ...
> END;
> ...
> 
> Basically I want to get full name, i.e. first name separated with space from
> the last name. If I follow the PL/pgSQL manual as shown above, I get parse
> error.
> What am I doing wrong?

Odd, a script like the following works for me on both 7.1 and 7.2devel:

drop table aa;
drop function fgn(varchar);
create table aa(a varchar);
insert into aa values ('d');
create function fgn(varchar) returns text as '
DECLARE
 query text;
 rec record;
BEGIN
 query := ''SELECT a || '''' '''' || a as bar from aa;'';
 RAISE NOTICE ''%'', query;
 FOR rec in EXECUTE query LOOP
  return rec.bar;
 END LOOP;
END;'
language 'plpgsql';
select fgn('f');





^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: Quotes and spaces
@ 2001-10-05 23:54  Oleg Lebedev <olebedev@waterford.org>
  parent: Stephan Szabo <sszabo@megazone23.bigpanda.com>
  0 siblings, 0 replies; 4+ messages in thread

From: Oleg Lebedev @ 2001-10-05 23:54 UTC (permalink / raw)
  To: Stephan Szabo <sszabo@megazone23.bigpanda.com>; +Cc: pgsql-sql

I just upgraded to 7.1 and the query works for me now.
thanks,

Oleg

Stephan Szabo wrote:

> On Fri, 5 Oct 2001, Oleg Lebedev wrote:
>
> > Hi,
> > I looked through PL/pgSQL tutorial, but I can't get quotes and spaces to
> > work in queries executed from Pl/pgSQl. Here is an example:
> >
> > create procedure get_name(varchar)
> > ...
> > BEGIN
> >     query := ''SELECT first_name || '''' '''' || last_name FROM user'';
> >     EXECUTE query;
> > ...
> > END;
> > ...
> >
> > Basically I want to get full name, i.e. first name separated with space from
> > the last name. If I follow the PL/pgSQL manual as shown above, I get parse
> > error.
> > What am I doing wrong?
>
> Odd, a script like the following works for me on both 7.1 and 7.2devel:
>
> drop table aa;
> drop function fgn(varchar);
> create table aa(a varchar);
> insert into aa values ('d');
> create function fgn(varchar) returns text as '
> DECLARE
>  query text;
>  rec record;
> BEGIN
>  query := ''SELECT a || '''' '''' || a as bar from aa;'';
>  RAISE NOTICE ''%'', query;
>  FOR rec in EXECUTE query LOOP
>   return rec.bar;
>  END LOOP;
> END;'
> language 'plpgsql';
> select fgn('f');




^ permalink  raw  reply  [nested|flat] 4+ messages in thread


end of thread, other threads:[~2001-10-05 23:54 UTC | newest]

Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2001-10-05 22:28 Quotes and spaces Oleg Lebedev <olebedev@waterford.org>
2001-10-05 22:51 ` Josh Berkus <josh@agliodbs.com>
2001-10-05 23:31 ` Stephan Szabo <sszabo@megazone23.bigpanda.com>
2001-10-05 23:54   ` Oleg Lebedev <olebedev@waterford.org>

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