pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Re: Syntax Error in COPY when “create function”
2+ messages / 2 participants
[nested] [flat]

* Re: Syntax Error in COPY when “create function”
@ 2007-02-27 17:04  Osvaldo Rosario Kussama <osvaldo_kussama@yahoo.com.br>
  0 siblings, 1 reply; 2+ messages in thread

From: Osvaldo Rosario Kussama @ 2007-02-27 17:04 UTC (permalink / raw)
  To: hongliu zou <zouhongliu@gmail.com>; pgsql-sql

hongliu zou escreveu:

> Am I forgetting some limitation? 
> 
> I get " ERROR: syntax error at or near "$1"
> 
> SQL state: 42601 "with this
> 
> CREATE FUNCTION Import1() RETURNS text AS $$
> DECLARE
>             path Char(100);
> BEGIN
>             path = 'C:/zhl/hjs/anc_area.att';
>             COPY anc_areaAtt FROM path CVS;
> 

Try:
	EXECUTE 'COPY anc_areaAtt FROM ' || path || ' CVS;';

>  
>             RETURN path;
> END;
> $$ LANGUAGE plpgsql;
> 
> SELECT  Import1() ;
> 
>   
> But COPY can work well when I just put the string in the command:
> 
> CREATE FUNCTION Import2() RETURNS text AS $$
> DECLARE
>             path Char(100);
> BEGIN
>             COPY anc_areaAtt FROM 'C:/zhl/hjs/anc_area.att' CSV;
>             return path;
> END;
> $$ LANGUAGE plpgsql;
> 
> SELECT  Import2() ;
> 
> 
> |Does this mean the "filename" in COPY command can not be a variable?|
> 


Look Executing Dynamic Commands at:
http://www.postgresql.org/docs/8.2/interactive/plpgsql-statements.html#PLPGSQL-STATEMENTS-EXECUTING-...

[]s
Osvaldo

	
	
		
_______________________________________________________ 
Yahoo! Mail - Sempre a melhor opção para você! 
Experimente já e veja as novidades. 
http://br.yahoo.com/mailbeta/tudonovo/



^ permalink  raw  reply  [nested|flat] 2+ messages in thread

* Re: Syntax Error in COPY when “create function”
@ 2007-02-27 17:25  Tom Lane <tgl@sss.pgh.pa.us>
  parent: Osvaldo Rosario Kussama <osvaldo_kussama@yahoo.com.br>
  0 siblings, 0 replies; 2+ messages in thread

From: Tom Lane @ 2007-02-27 17:25 UTC (permalink / raw)
  To: Osvaldo Rosario Kussama <osvaldo_kussama@yahoo.com.br>; +Cc: hongliu zou <zouhongliu@gmail.com>; pgsql-sql

Osvaldo Rosario Kussama <osvaldo_kussama@yahoo.com.br> writes:
>> |Does this mean the "filename" in COPY command can not be a variable?|

Got it in one.

You can use EXECUTE to put together commands that require a variable
in places where PG doesn't allow one.

			regards, tom lane



^ permalink  raw  reply  [nested|flat] 2+ messages in thread


end of thread, other threads:[~2007-02-27 17:25 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2007-02-27 17:04 Re: Syntax Error in COPY when “create function” Osvaldo Rosario Kussama <osvaldo_kussama@yahoo.com.br>
2007-02-27 17:25 ` Tom Lane <tgl@sss.pgh.pa.us>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox