pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Mario Splivalo <mario.splivalo@megafon.hr>
To: landsharkdaddy <ldodd@landsharksoftware.com>
Cc: pgsql-sql@postgresql.org
Subject: Re: Query with Parameters and Wildcards
Date: Mon, 27 Apr 2009 13:40:59 +0200
Message-ID: <49F599CB.9000701@megafon.hr> (raw)
In-Reply-To: <23250153.post@talk.nabble.com>
References: <23248274.post@talk.nabble.com>
	<dcc563d10904262154n19dd9f77pe81fe23eebeeac2e@mail.gmail.com>
	<23250153.post@talk.nabble.com>

landsharkdaddy wrote:
> I have not tried that but I will in the morning. The @ in SQL is used to
> indicate a parameter passed to the query. In PostgreSQL it seems that the :
> is the same as the @ in SQL Server. I tried something like:
> 
> SELECT * FROM Customers WHERE FirstName LIKE :custfirst + '%'; 
> 
> And it told me that the + could not be used. Not sure the exact message but
> I will check again tomorrow and see what it was and post the results.

T-SQL defines that variables need to start with @ (like, for instance, 
in PHP they star with $).

In postgres you have positional parametars, $1, for instance.

You could, for instance, write SQL function in postgres that would do 
what you need:

CREATE FUNCTION get_customers_with_like (a_name_part character varying)
RETURNS SETOF customers
AS
$$
SELECT * FROM customers WHERE firstname LIKE $1 || '%';
$$
LANGUAGE 'sql';


In postgres, you use '||' for string concatenation (instead of '+' in 
T-SQL).

	Mario



view thread (10+ messages)  latest in thread

Message-ID: <49F599CB.9000701@megafon.hr>
Permalink:  ../49F599CB.9000701@megafon.hr/
Also on:    postgresql.org/message-id/49F599CB.9000701@megafon.hr

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: mario.splivalo@megafon.hr, ldodd@landsharksoftware.com
  Subject: Re: Query with Parameters and Wildcards
  In-Reply-To: <49F599CB.9000701@megafon.hr>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

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