Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PostgreSQL throwing error on RAISE NOTICE with || operator

Getting the following error with the following line of code:

RAISE NOTICE '*** Rolling back job run id ' || CONVERT(varchar, v_job_run_id)
             || ' for table ' || v_table_name || '***';

Error:

ERROR: syntax error at or near "|" LINE 43: RAISE NOTICE '*
Rolling back job run id ' || CONVERT(var...

like image 497
mlevit Avatar asked Aug 10 '12 03:08

mlevit


People also ask

What does || do in Postgres?

Description. The PostgreSQL || operator allows you to concatenate 2 or more strings together.

What is raise exception in PostgreSQL?

RAISE EXCEPTION in PostgreSQL is basically used to raise the warning and error message. It is very useful and important. There are six levels of raise exception is available in PostgreSQL, i.e. notice, log, debug, warning info and exception. It is used in various parameters.

What is $$ in PostgreSQL?

In PostgreSQL, the dollar-quoted string constants ($$) is used in user-defined functions and stored procedures. In PostgreSQL, you use single quotes for a string constant like this: select 'String constant'; When a string constant contains a single quote ('), you need to escape it by doubling up the single quote.


1 Answers

A message string in RAISE XXXX statement should be literal constant - expression is not allowed there. It is similar to format string in printf like functions.

RAISE NOTICE 'my table has name %', tablename;

Second issue should be "CONVERT", that is not supported in Pg - use CAST instead or nothing, any parameter of RAISE statement is converted to text automatically.

like image 198
Pavel Stehule Avatar answered Sep 27 '22 15:09

Pavel Stehule