Postgres Syntax Error At Or Near Raise
Contents |
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack
Raise Exception Postgresql Examples
Overflow the company Business Learn more about hiring developers or posting ads with us raise notice in postgresql function Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a postgresql raise notice not working community of 6.2 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up How to execute PostgreSQL RAISE command dynamically up vote 5 down vote favorite 2 How
Postgresql Raise Notice Multiple Variables
to raise error from PostgreSQL SQL statement if some condition is met? I tried code below but got error. CREATE OR REPLACE FUNCTION "exec"(text) RETURNS text AS $BODY$ BEGIN EXECUTE $1; RETURN $1; END; $BODY$ LANGUAGE plpgsql VOLATILE; -- ERROR: syntax error at or near "raise" -- LINE 1: raise 'test' SELECT exec('raise ''test'' ') WHERE TRUE In real application TRUE is replaced by some condition. Update I tried to extend
Postgres Raise Notice Log File
answer to pass exception message parameters. Tried code below but got syntax error. How to pass message parameters ? CREATE OR REPLACE FUNCTION exec(text, variadic ) RETURNS void LANGUAGE plpgsql AS $BODY$ BEGIN RAISE EXCEPTION $1, $2; END; $BODY$; SELECT exec('Exception Param1=% Param2=%', 'param1', 2 ); postgresql exception-handling plpgsql share|improve this question edited Aug 12 '12 at 7:19 asked Aug 11 '12 at 19:02 Andrus 6,38928103197 1 Repost of PostgreSQL mailing list message archives.postgresql.org/message-id/… . Andrus, please don't post in both places without saying you've done so. Link to the SO article when posting to the Pg list. –Craig Ringer Aug 12 '12 at 5:07 add a comment| 1 Answer 1 active oldest votes up vote 13 down vote accepted You cannot call RAISE dynamically (with EXECUTE) in PL/pgSQL - that only works for SQL statements, and RAISE is a PL/pgSQL command. Use this simple function instead: CREATE OR REPLACE FUNCTION f_exec(text) RETURNS void LANGUAGE plpgsql AS $BODY$ BEGIN RAISE EXCEPTION '%', $1; END; $BODY$; Call: SELECT f_exec('My message is empty!'); I wrote more in this related answer on dba.SE: explanation, links, more options for the function, context (including line number) from the function call etc. Additional answer to comment CREATE OR REPLACE FUNCTION f_exec1(VARIADIC text[]) RETURNS void LANGUAGE p
pgsql-announce pgsql-bugs pgsql-docs pgsql-general pgsql-interfaces pgsql-jobs pgsql-novice pgsql-performance pgsql-php pgsql-sql pgsql-students Developer lists Regional pgadmin raise notice lists Associations User groups Project lists Inactive lists IRC
Postgresql Print Message
Local User Groups Featured Users International Sites Propaganda Resources Weekly News Re: How to client_min_messages raise error from PostgreSql SQL statement if some condition is met From: Pavel Stehule
♦ Locked 8 messages Andrus Moor Reply | Threaded Open this post in threaded view ♦ ♦ | Report Content as Inappropriate ♦ ♦ How to raise error from PostgreSql SQL statement if some condition is met http://postgresql.nabble.com/How-to-raise-error-from-PostgreSql-SQL-statement-if-some-condition-is-met-td5719585.html I’m looking for a way to raise error from sql select if some condition is met. Tried code below to got error shown in comment. How to fix ? Andrus CREATE OR REPLACE FUNCTION "exec"(text) RETURNS text AS $BODY$ BEGIN EXECUTE $1; RETURN $1; END; $BODY$ LANGUAGE plpgsql VOLATILE; -- ERROR: syntax error at or near "raise" -- LINE raise notice 1: raise 'test' select exec('raise ''test'' ') where true -- in real application true is replaced by some condition Pavel Stehule Reply | Threaded Open this post in threaded view ♦ ♦ | Report Content as Inappropriate ♦ ♦ Re: How to raise error from PostgreSql SQL statement if some condition is met Hello You can execute only SQL statements - RAISE is plpgsql statement, not SQL statement, so you cannot postgresql raise notice execute it. why you don't use just CREATE OR REPLACE FUNCTION raise_exception(text) RETURNS void AS $$ BEGIN RAISE EXCEPTION '%', $1; END; $$ LANGUAGE plpgsql; SELECT raise_exception('bubu'); Regards Pavel Stehule 2012/8/11 Andrus <[hidden email]>: > I’m looking for a way to raise error from sql select if some condition is > met. > Tried code below to got error shown in comment. > How to fix ? > > Andrus > > CREATE OR REPLACE FUNCTION "exec"(text) > RETURNS text AS > $BODY$ > BEGIN > EXECUTE $1; > RETURN $1; > END; > $BODY$ > LANGUAGE plpgsql VOLATILE; > > -- ERROR: syntax error at or near "raise" > -- LINE 1: raise 'test' > > select exec('raise ''test'' ') where true -- in real application true is > replaced by some condition - Sent via pgsql-general mailing list ([hidden email]) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-general Craig Ringer-2 Reply | Threaded Open this post in threaded view ♦ ♦ | Report Content as Inappropriate ♦ ♦ Re: How to raise error from PostgreSql SQL statement if some condi