473,387 Members | 3,801 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

error creating sql function

I was trying to create a sql function today (see below) using
postgresql 7.3.3. I don't see how to get around this error, anyone
have any suggestions?

Thanks much,

Matthew

tocr=# CREATE OR REPLACE FUNCTION public.update_dncl(bpchar, bpchar)
tocr-# RETURNS void AS
tocr-# '
tocr'# begin;
tocr'# update area_codes
tocr'# set last_updated = now()
tocr'# where code = $1;
tocr'# DELETE from do_not_call_list
tocr'# where area_code = $1;
tocr'# copy do_not_call_list (area_code, number) from $2 with delimiter
as \',\';
tocr'# commit;
tocr'# '
tocr-# LANGUAGE 'sql' VOLATILE;
ERROR: parser: parse error at or near "$2" at character 178
tocr=# COMMENT ON FUNCTION public.update_dncl(bpchar, bpchar) IS 'Will
be used to update an area code in the DNCL tables.';
COMMENT

tocr=# SELECT version();

version
---------------------------------------------------------------------------------------------------------
PostgreSQL 7.3.3 on i686-pc-linux-gnu, compiled by GCC gcc (GCC) 3.2
20020903 (Red Hat Linux 8.0 3.2-7)
(1 row)
---------------------------(end of broadcast)---------------------------
TIP 4: Don't 'kill -9' the postmaster

Nov 22 '05 #1
2 2276
Matthew T. O'Connor wrote:
I was trying to create a sql function today (see below) using
postgresql 7.3.3. I don't see how to get around this error, anyone
have any suggestions?

Thanks much,

Matthew

tocr=# CREATE OR REPLACE FUNCTION public.update_dncl(bpchar, bpchar)
tocr-# RETURNS void AS
tocr-# '
tocr'# begin;
tocr'# update area_codes
tocr'# set last_updated = now()
tocr'# where code = $1;
tocr'# DELETE from do_not_call_list
tocr'# where area_code = $1;
tocr'# copy do_not_call_list (area_code, number) from $2 with delimiter
as \',\';
tocr'# commit;
tocr'# '
tocr-# LANGUAGE 'sql' VOLATILE;
ERROR: parser: parse error at or near "$2" at character 178
tocr=# COMMENT ON FUNCTION public.update_dncl(bpchar, bpchar) IS 'Will
be used to update an area code in the DNCL tables.';
COMMENT
Quick reply ... I haven't tested this, and it's only a theory, so treat
it as such.

The copy command should have '' around the filename, so possibly:
copy do_not_call_list (area_code, number) from ''$2'' with delimiter as \',\';

.... would work?
tocr=# SELECT version();

version
---------------------------------------------------------------------------------------------------------

PostgreSQL 7.3.3 on i686-pc-linux-gnu, compiled by GCC gcc (GCC) 3.2
20020903 (Red Hat Linux 8.0 3.2-7)
(1 row)
---------------------------(end of broadcast)---------------------------
TIP 4: Don't 'kill -9' the postmaster

--
Bill Moran
Potential Technologies
http://www.potentialtech.com
---------------------------(end of broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to ma*******@postgresql.org

Nov 22 '05 #2
"Matthew T. O'Connor" <ma*****@zeut.net> writes:
I was trying to create a sql function today (see below) using
postgresql 7.3.3. I don't see how to get around this error, anyone
have any suggestions? tocr=# CREATE OR REPLACE FUNCTION public.update_dncl(bpchar, bpchar)
...
tocr'# copy do_not_call_list (area_code, number) from $2 with delimiter
...
tocr-# LANGUAGE 'sql' VOLATILE;
ERROR: parser: parse error at or near "$2" at character 178


COPY, like all the other utility commands in Postgres, doesn't support
$n parameters. (Basically, you can only use these where an expression
would be allowed, which is only in SELECT/INSERT/UPDATE/DELETE.)

You can work around this by constructing the desired command as a string
in plpgsql or one of the other PL languages, say

CREATE OR REPLACE FUNCTION public.update_dncl(bpchar, bpchar)
....
execute ''copy do_not_call_list (area_code, number) from '' || quote_literal($2) || '' with delimiter ''
....
LANGUAGE 'plpgsql' VOLATILE;

regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 5: Have you checked our extensive FAQ?

http://www.postgresql.org/docs/faqs/FAQ.html

Nov 22 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: sky2070 | last post by:
Parse error: parse error, unexpected T_OBJECT_OPERATOR, expecting ')' in c:\inetpub\wwwroot\session.php on line 19 can anyone tell me what is wrong with this code??? <? // Define the Session...
5
by: azgoddess1 | last post by:
During the installation I get these error messages: ***** SQL1390C The environment variable DB2Instance is not defined or is invalid An error ocured while loading the command "C:\Program...
20
by: ctyrrell | last post by:
Does anyone have any idea how to recover from a run-time error 3002 which I get after creating a workspace 242 times? Or better yet, avoid getting it in the first place? I am creating a...
2
by: Mary | last post by:
Hello, I am having a problem with the cl compiler. I have written a C class (RegConnect.c) which uses Win32 API functions such as RegOpenKey, RegCloseKey etc. Initially when I was trying to...
8
by: Razak | last post by:
Hi, I have a class which basically do Impersonation in my web application. From MS KB sample:- ++++++++++++++++++++code starts Dim impersonationContext As...
2
by: Ivan | last post by:
Hi, I experienced a problem while upgrading from DB2 UDB LUW Workgroup edition 7.2 FixPak 10a to Workgroup Server edition 8.2 FixPak 12. The install wizard said the upgrade was successful but none...
7
by: The|Godfather | last post by:
Hi everybody, I read Scotte Meyer's "Effective C++" book twice and I know that he mentioned something specific about constructors and destructors that was related to the following...
2
by: f rom | last post by:
----- Forwarded Message ---- From: Josiah Carlson <jcarlson@uci.edu> To: f rom <etaoinbe@yahoo.com>; wxpython-users@lists.wxwidgets.org Sent: Monday, December 4, 2006 10:03:28 PM Subject: Re: ...
8
by: ctiggerf | last post by:
I was hopeing someone could help me out here. Been stumped on this one all day. This function 1. Checks uploaded files. 2. Creates two resized images from each (a full size, and a...
4
by: jk2l | last post by:
Error 10 error LNK2019: unresolved external symbol __imp__glBindTexture@8 referenced in function "public: void __thiscall GLTexture::Use(void)" (?Use@GLTexture@@QAEXXZ) GLTexture.obj Error 11 error...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.