473,406 Members | 2,620 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,406 software developers and data experts.

\COPY in plpgsql function

Hi there,

I've been trying to execute \COPY from within a plpsql function and keep getting an error. Any hints at where I'm going wrong would be great.

I'm using \COPY with a backslash because the database is owned by a different user to the file I'm writing to and COPY on its own gives a 'Permission denied' error

Thanks!

CREATE or REPLACE FUNCTION printentries() RETURNS VOID AS $$
DECLARE STATEMENT TEXT;
BEGIN
FOR Y IN 7..11 LOOP
DROP TABLE M1;
CREATE TEMP TABLE M1 AS
SELECT daynumber,startl,endl,numb
FROM batchentries
WHERE (EXTRACT('year' FROM date)=Y);
STATEMENT := E'\\COPY M1 TO \'/Users/ellen/my_data/batchentries' || Y || E'.txt\' DELIMITER \' \'; ';
EXECUTE STATEMENT;
END LOOP;
RETURN;
END;
$$ LANGUAGE plpgsql;


SELECT printentries();
ERROR: syntax error at or near "\"
LINE 1: \COPY M1 TO '/Users/ellen/my_data/batchent...
^
QUERY: \COPY M1 TO '/Users/ellen/my_data/batchentries7.txt' DELIMITER ' ';
CONTEXT: PL/pgSQL function "printentries" line 11 at EXECUTE statement
Aug 16 '11 #1
0 2619

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Julie May | last post by:
I have 90% of my function working and I know to get the next 10% it is justa matter of getting the quotations and the escaping quotations correct. Here is the portion that does work: <working...
10
by: lnd | last post by:
After copied pg database from one PC to another -I could not find plpgsql function(s) in the copied database. -had to instal plpgsql language handler again -whilst tables and data moved...
6
by: Jim Steinberger | last post by:
Hey all - my inaugural post, I have a Java web application on Tomcat 5 using pg73jdbc3.jar to connect to PostgreSQL 7.3.4 running on the same server (Red Hat Linux ). I have a Perl...
2
by: Mark Cave-Ayland | last post by:
Hi everyone, I'm trying to write a recursive plpgsql function in PostgreSQL 7.4.2 that given a tree node id (ictid) will return all the nodes below it in the tree, one row per node. When I try...
1
by: chinni | last post by:
Hey guys I have written a plpgsql function which takes anyelement as argument. If I pass a string as input It gives an error "invalid input for integer" . Cant I pass any datatype for anyelement
9
by: Karl O. Pinc | last post by:
I want to return multiple values, but not a set, only a single row, from a plpgsql function and I can't seem to get it to work. (I suppose I'd be happy to return a set, but I can't seem to make...
1
by: Timothy Perrigo | last post by:
(PostgreSQL 8.0 beta 4 on Mac OS X 10.3.6) I'm working on a function which creates and populates a temporary table, then returns the number of records it has inserted. I'm getting an error,...
6
by: twinklyblue | last post by:
Hi team, I'm new in Postgres and I tried creating a stored procedure which performs numerous update procedure. As I compiled it, I was given the following error: psql:storedproc.sql:33: ERROR: ...
2
by: twinklyblue | last post by:
Hi team, I am creating a function that would accept an array of integer as its parameter. I have a table where one of its column is declared as an array. This is an excerpt from the script that...
1
by: Irrigho5 | last post by:
i have the open file function just need help with the copy file function and main Ask for a source filename and a target filename. Then copy the source file to the target file using the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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...
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.