Received: from magus.postgresql.org (magus.postgresql.org [87.238.57.229]) by mail.postgresql.org (Postfix) with ESMTP id 5745616D90F8 for ; Tue, 27 Mar 2012 13:13:04 -0300 (ADT) Received: from cerberus.pinpointresearch.com ([66.7.238.130] helo=polaris.pinpointresearch.com) by magus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1SCZ13-00034y-7f for pgsql-sql@postgresql.org; Tue, 27 Mar 2012 16:13:02 +0000 Received: from betelgeuse.pinpointresearch.com (betelgeuse.pinpointresearch.com [192.168.1.179]) by polaris.pinpointresearch.com (Postfix) with ESMTP id 2FADCE00EC83; Tue, 27 Mar 2012 09:12:47 -0700 (PDT) Message-ID: <4F71E6FF.6060204@pinpointresearch.com> Date: Tue, 27 Mar 2012 09:12:47 -0700 From: Steve Crawford User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.27) Gecko/20120216 Lightning/1.0b2 Thunderbird/3.1.19 MIME-Version: 1.0 To: Rehan Saleem CC: sql pgsql Subject: Re: how to concatenate in PostgreSQL References: <1332589439.54415.YahooMailNeo@web121601.mail.ne1.yahoo.com> <4F709481.30503@pinpointresearch.com> <1332859717.73799.YahooMailNeo@web121606.mail.ne1.yahoo.com> In-Reply-To: <1332859717.73799.YahooMailNeo@web121606.mail.ne1.yahoo.com> Content-Type: multipart/alternative; boundary="------------030904060800040606020005" X-Pg-Spam-Score: -0.9 (/) X-Archive-Number: 201203/80 X-Sequence-Number: 36475 This is a multi-part message in MIME format. --------------030904060800040606020005 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit On 03/27/2012 07:48 AM, Rehan Saleem wrote: > well i am quite sure its PostgreSQL forum and it is obvious, i am > asking this to concatenate in plpgsql. > ------------------------------------------------------------------------ > *From:* Steve Crawford > *To:* pgsql-sql@postgresql.org > *Sent:* Monday, March 26, 2012 9:08 PM > *Subject:* Re: [SQL] how to concatenate in PostgreSQL > > On 03/24/2012 04:43 AM, Rehan Saleem wrote: >> hi , >> how can we concatinate these lines and execute sql command > In what? Psql? A PL/pgSQL function. C/Java/PHP/Python/Perl/Erlang/Lua? >> setsql = 'select user,username, firstname ' >> set sql += ' lastname, cardno from table1 where userid=' + 5 >> exec(sqi) >> where 5 is the userid from table1 >> thanks >> > Cheers, > Steve > > Yes, after about a decade of PostgreSQL use and forum participation I think I know which forum this is. Sarcasm and biting at people who want to help you is not a good way to make friends and get help on the forums. If you meant PL/pgSQL then say it. It is not the same as SQL though the syntax is generally similar. Look at DECLARE and BEGIN for starters. I've seen too many threads get reset back to the start once some incorrect assumptions get corrected to feel that up-front clarification is a waste of time. http://wiki.postgresql.org/wiki/Guide_to_reporting_problems is more oriented to problem reporting than general questions but has helpful advice nonetheless. Back to the issue at hand...others have pointed out the || operator and the issue with NULL. It appears you are doing a lot of conversion requiring writing of PL/pgSQL functions. Spend a few minutes skimming: http://www.postgresql.org/docs/current/static/plpgsql.html As to the topic of executing the command including many examples see: http://www.postgresql.org/docs/current/static/plpgsql-statements.html#PLPGSQL-STATEMENTS-EXECUTING-DYN If you are writing functions that must use dynamically generated table and column names, become familiar with the quote_ident, quote_literal and quote_nullable functions. Cheers, Steve --------------030904060800040606020005 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit On 03/27/2012 07:48 AM, Rehan Saleem wrote:
well i am quite sure its PostgreSQL forum and it is obvious, i am asking this to concatenate in plpgsql.

From: Steve Crawford <scrawford@pinpointresearch.com>
To: pgsql-sql@postgresql.org
Sent: Monday, March 26, 2012 9:08 PM
Subject: Re: [SQL] how to concatenate in PostgreSQL

On 03/24/2012 04:43 AM, Rehan Saleem wrote:
hi ,
how can we concatinate these lines and execute sql command
In what? Psql? A PL/pgSQL function. C/Java/PHP/Python/Perl/Erlang/Lua?
 
       set sql = 'select user,username, firstname '
      set sql += ' lastname, cardno from table1 where userid=' + 5
      exec(sqi)
     where 5 is the userid from table1
thanks
 

 
Cheers,
Steve


Yes, after about a decade of PostgreSQL use and forum participation I think I know which forum this is. Sarcasm and biting at people who want to help you is not a good way to make friends and get help on the forums.

If you meant PL/pgSQL then say it. It is not the same as SQL though the syntax is generally similar. Look at DECLARE and BEGIN for starters. I've seen too many threads get reset back to the start once some incorrect assumptions get corrected to feel that up-front clarification is a waste of time. http://wiki.postgresql.org/wiki/Guide_to_reporting_problems is more oriented to problem reporting than general questions but has helpful advice nonetheless.

Back to the issue at hand...others have pointed out the || operator and the issue with NULL. It appears you are doing a lot of conversion requiring writing of PL/pgSQL functions. Spend a few minutes skimming:
http://www.postgresql.org/docs/current/static/plpgsql.html

As to the topic of executing the command including many examples see:
http://www.postgresql.org/docs/current/static/plpgsql-statements.html#PLPGSQL-STATEMENTS-EXECUTING-DYN

If you are writing functions that must use dynamically generated table and column names, become familiar with the quote_ident, quote_literal and quote_nullable functions.

Cheers,
Steve

--------------030904060800040606020005--