Greetings,

  Please, what am I doing wrong?

chris=# \d phone_prefix
Table "phone_prefix"
-[ RECORD 1 ]----------------------------------------------------------
Attribute | number
Type      | integer
Modifier  | not null default nextval('"phone_prefix_number_seq"'::text)
-[ RECORD 2 ]----------------------------------------------------------
Attribute | prefix
Type      | text
Modifier  |
 
Index: phone_prefix_number_key 

chris=#  select phone_prefix.prefix order by random() limit 1;
 prefix
--------
 384
(1 row)

Wonderful, works exactly as expected.

chris=# select  lpad((random()*10000)::int, 4, '0')::text as "Number";
 Number
--------
 2958
(1 row)

ditto

But attempting to concatenate the two is a disaster.

chris=# select phone_prefix.prefix order by random() limit 1 || '-' || 
lpad((random()*10000)::int, 4, '0')::text as "Phone Number";
ERROR:  parser: parse error at or near "||"
chris=# 

What am i doing wrong?

chris=# select version();
                                version
------------------------------------------------------------------------
 PostgreSQL 7.1beta3 on i586-pc-linux-gnu, compiled by GCC egcs-2.91.66
(1 row)                                                                    
                                                
Thanks a 10^6

p.s. imho it would be a terrific help, especially for new-comers to SQL 
like me, if the parser could be persuaded to utter just a tiny glimmer of 
a hint as to what it thinks one's mistake is instead of the rather 
enigmatic "ERROR:  parser: parse error at or near".
Is it possible for mere mortals to help?

-- 
Sincerely etc.,

 NAME       Christopher Sawtell
 CELL PHONE 021 257 4451
 ICQ UIN    45863470
 EMAIL      csawtell @ xtra . co . nz
 CNOTES     ftp://ftp.funet.fi/pub/languages/C/tutorials/sawtell_C.tar.gz

 -->> Please refrain from using HTML or WORD attachments in e-mails to me 
<<--

Reply via email to