Skip site navigation (1) Skip section navigation (2)

Re: Function Syntax involving pipes and ' marks?

From: Bricklen Anderson <banderson(at)presinet(dot)com>
To: Ruben Gouveia <rubes7202(at)gmail(dot)com>
Cc: pgsql-sql <pgsql-sql(at)postgresql(dot)org>
Subject: Re: Function Syntax involving pipes and ' marks?
Date: 2008-09-10 18:24:16
Message-ID: 48C810D0.3070900@presinet.com (view raw or flat)
Thread:
Lists: pgsql-sql
Ruben Gouveia wrote:
>     v_where varchar(256) := 'where m.jb_date < '||p_date + integer '1'||
>                             ' and m.jb_date >='||p_date||'';

Try wrapping your p_date in a quote_literal like
...
'where m.jb_date < '||quote_literal(p_date+INTEGER '1')||' and ...

eg.

CREATE OR REPLACE FUNCTION fcn_job(p_date date, p_type varchar,p_jobid 
numeric) RETURNS numeric AS $$
DECLARE
     v_job numeric := 0;
     v_stmt varchar(1024);
     v_where varchar(256) := 'where m.jb_date < '||quote_literal(p_date 
+ integer '1')||' and m.jb_date >='||quote_literal(p_date);
BEGIN
     v_stmt := fcn_gen_statement(p_type, v_where, p_newonly);
     execute v_stmt into v_job;
     RAISE NOTICE 'sql looks like this: % . ',v_stmt;
     return v_job;
END;
$$ LANGUAGE plpgsql;

In response to

Responses

pgsql-sql by date

Next:From: Bricklen AndersonDate: 2008-09-10 18:36:41
Subject: Re: Function Syntax involving pipes and ' marks?
Previous:From: Tom LaneDate: 2008-09-10 16:04:21
Subject: Re: FW: Help- post gress sql error

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group