Re: Query with Parameters and Wildcards
От | Mario Splivalo |
---|---|
Тема | Re: Query with Parameters and Wildcards |
Дата | |
Msg-id | 49F599CB.9000701@megafon.hr обсуждение исходный текст |
Ответ на | Re: Query with Parameters and Wildcards (landsharkdaddy <ldodd@landsharksoftware.com>) |
Список | 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 по дате отправления: