Обсуждение: How to write in Postgres

Поиск
Список
Период
Сортировка

How to write in Postgres

От
Дата:
<table align=3D"center" style=3D"empty-cells: show;" bgcolor=3D"#ffffff" bo=
rder=3D"0" cellpadding=3D"0" cellspacing=3D"0" width=3D"100%"><td style=
=3D"text-align: left; background-repeat: no-repeat;" align=3D"left"; height=
=3D"72" colspan=3D"1" background=3D"cid:top@2d09f79b45a0399ec444c52bf160b4d=
e"<div style=3D"padding: 5=
px; overflow-x: auto;"><span style=3D=
"font-family:Verdana; color:#000000; font-size:10pt;"> I have a S=
QL statement that I'm trying to convert from a SQL Anywhere function, but I=
'm getting a error.  Can't seem to figure out why.  Is the substr=
ing usage incorrect and if it is how do I accomplish this.  I'm trying=
 to step through the item 1 character at a time so that I can reformat the =
input correctly.
 
This is inside a WHILE loop (While idx < 11 loop. idx has been init=
ialized to 1 and is declared as a integer.

set chr =3D substr(lfeid,idx,1);
 
 

How do I convert this to PostGres. I'm getting a error

ERROR: syntax error at or near "("LINE 23: set chr =3D substr(lfei=
d,idx,1);
 
Michael Gould
Intermodal Software Solutions, LLC
904-226-0978</d=
iv>=

Re: How to write in Postgres

От
Alban Hertroys
Дата:
On 7 February 2012 15:03, <mgould@isstrucksoftware.net> wrote:
How do I convert this to PostGres. I'm getting a error
ERROR: syntax error at or near "("
LINE 23: set chr = substr(lfeid,idx,1);

Assuming you are writing this as pl/pgsql code, the way you do your variable assignments is wrong on two accounts. Find some time to read the chapter on pl/pgsql if possible ;)

Anyway, that line should read:
chr := substr(lfeid,idx,1);

--
If you can't see the forest for the trees,
Cut the trees and you'll see there is no forest.

Re: How to write in Postgres

От
Merlin Moncure
Дата:
On Tue, Feb 7, 2012 at 8:03 AM, <mgould@isstrucksoftware.net> wrote:
>
>  I have a SQL statement that I'm trying to convert from a SQL Anywhere function, but I'm getting a error.  Can't seem
tofigure out why.  Is the substring usage incorrect and if it is how do I accomplish this.  I'm trying to step through
theitem 1 character at a time so that I can reformat the input correctly. 
>
> This is inside a WHILE loop (While idx < 11 loop. idx has been initialized to 1 and is declared as a integer.
> set chr = substr(lfeid,idx,1);

in plpgsql:

WHILE idx < 11
LOOP
  chr := substr(lfeid,idx,1);
END LOOP;

http://www.postgresql.org/docs/current/static/plpgsql-control-structures.html

I could probably help you work it into a single query if you provided
some more detail.

merlin