Re: Query with Parameters and Wildcards - Mailing list pgsql-sql

From Mario Splivalo
Subject Re: Query with Parameters and Wildcards
Date
Msg-id 49F599CB.9000701@megafon.hr
Whole thread Raw
In response to Re: Query with Parameters and Wildcards  (landsharkdaddy <ldodd@landsharksoftware.com>)
List pgsql-sql
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


pgsql-sql by date:

Previous
From: Jasen Betts
Date:
Subject: Re: varchar value comparisons not working?
Next
From: landsharkdaddy
Date:
Subject: Re: Query with Parameters and Wildcards