I'm trying to use the RIGHT()
function it so it will only display the last 4 digits of a credit card number pulled from the customer table. This is what I have so far:
create function get_customer(text) returns setof cusinfo as
$$
select upper(first_name)||' '||upper(last_name) as full_name, upper(address), upper(city)||', '||upper(state)||' '||zip as citystatezip, email, '************'||right(cc_number,4), cc_name
from customer
where customer_id = $1;
$$ language sql;
The error I am being given is:
psql:finalproject.sql:273: ERROR: function right(text, integer) does not exist LINE 3: ...|' '||zip as citystatezip, email, '****'||right(cc_n...
Any ideas as to why this is happening? I tried only using RIGHT()
by itself and putting in something like RIGHT('Help me', 2)
, but I get the same error.
All messages emitted by the PostgreSQL server are assigned five-character error codes that follow the SQL standard's conventions for “SQLSTATE” codes. Applications that need to know which error condition has occurred should usually test the error code, rather than looking at the textual error message.
Using parameter notation here ( %s ) will cause the inserted name value to be the provided string ( "my_name'); DROP TABLE my_table;" ), rather than allowing that string to execute arbitrary SQL in the database.
:= is the assignment operator in PL/pgSQL. The expression searchsql:= searchsql || ' WHERE 1=1 ' ; appends the string ' WHERE 1=1 ' to the current value of the variable searchsql. See the manual for details: http://www.postgresql.org/docs/current/static/plpgsql-statements.html#PLPGSQL-STATEMENTS-ASSIGNMENT.
I'm assuming psql
is PostgreSQL. If that's the case, you should read the PostgreSQL documentation describing the string functions that are available to you.
right
is not one of them.
Try substring(cc_number from char_length(cc_number) - 3)
.
In future you may want to use Google to help answer questions like this. Google is a search engine; you can use search engines to find documentation; documentation tells you how to use a product.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With