Unix Technical Forum

=?WINDOWS-1252?Q?Syntax_Error_in_COPY_when_=93create_functio n=94?=

This is a discussion on =?WINDOWS-1252?Q?Syntax_Error_in_COPY_when_=93create_functio n=94?= within the pgsql Sql forums, part of the PostgreSQL category; --> Am I forgetting some limitation? I get " ERROR: syntax error at or near "$1" SQL state: 42601 "with ...


Go Back   Unix Technical Forum > Database Server Software > PostgreSQL > pgsql Sql

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-19-2008, 03:09 PM
hongliu zou
 
Posts: n/a
Default =?WINDOWS-1252?Q?Syntax_Error_in_COPY_when_=93create_functio n=94?=

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;



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?



By the way, my OS is windowXP.


Thanks and Regards,
Hongliu

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 04-19-2008, 03:09 PM
Osvaldo Rosario Kussama
 
Posts: n/a
Default Re: Syntax Error in COPY when =?windows-1252?Q?=93create_?==?windows-1252?Q?function=94?=

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/i...-EXECUTING-DYN

[]s
Osvaldo




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

---------------------------(end of broadcast)---------------------------
TIP 6: explain analyze is your friend

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 04-19-2008, 03:09 PM
Tom Lane
 
Posts: n/a
Default Re: Syntax Error in COPY when =?windows-1252?Q?=93create_?= =?windows-1252?Q?function=94?=

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

---------------------------(end of broadcast)---------------------------
TIP 4: Have you searched our list archives?

http://archives.postgresql.org

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 11:32 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com