[SQL] pg_dump error - Permission denied

2003-11-03 Thread Kumar



Dear friends, 
 
I am working with Postgres 7.3.4 on RH Linux 7.3.
 
I could manage to take a backup using the following command 
and as the user 'postgres'.
 $ pg_dump -h 192.168.2.51 -v -u -f 
/home/db_repository/test20031103.sql test
 
But while I try to execute the same command with the user 
'kumar', it gives me the following error
>>
pg_dump: query to get data of sequence "clients_client_id_seq" 
failed: ERROR:  clients_client_id_seq: permission deniedpg_dump: *** 
aborted because of error
 
But as the user 'kumar' I could manage to get the next value 
of the sequence with the following command
select nextval('test.clients_client_id_seq');
 
Previously, user 'postgres' is the owner of the database and I 
have changed that to 'kumar' via the following command
UPDATE pg_database SET datdba = 105 where datname = 
'test';
 
Even though I am the owner of the sequence, why I am getting 
this error. Anybody could shed some light, pls.
 
Regards
Kumar



[SQL] 'invalid' value in timestamp with timezone.

2003-11-03 Thread Stef
Hi all,

I've noticed for the first time in some 7.1.2 databases that
I use, that somebody/something managed to insert a literal
alpha value of 'invalid' into 'timestamp with timezone' columns.

I tested it myself, and it worked :
test712=# create table bob (field timestamp);
CREATE
test712=# \d bob 
   Table "bob"
 Attribute |   Type   | Modifier 
---+--+--
 field | timestamp with time zone | 

test712=# insert into bob values('invalid');
INSERT 3885934 1

On 7.3.4 it gives me :
test734=> insert into bob2 values('invalid');
ERROR:  TIMESTAMP WITH TIME ZONE 'invalid' no longer supported

but other strings gave me the same error on both db's :
test734=> insert into bob2 values('valid');
ERROR:  Bad timestamp external representation 'valid'

I looked in the documentation and on the net, but cannot find
much reference to this "ex-feature"

I'm 80% sure no one actually inserted these 'invalid' values into tables,
and what I need to know is : 
What else can insert a value of 'invalid' into a 7.1.2 
"timestamp with timezone" type column.

Was there a function or something similar?

Regards 
Stef


pgp0.pgp
Description: PGP signature


Re: [SQL] Help on update that subselects other records in table, uses joins

2003-11-03 Thread Jeff Kowalczyk
Josh Berkus wrote:
> You may only UPDATE one table at a time, you can't update a JOIN. So when 
> selecting from another table to filter or calculate your update, the form is:
> UPDATE orderchanges 
> SET orderchargesbilled = {expression}
> FROM orders
> WHERE orders.orderid = ordercharges.orderid
> AND etc.

Thanks for the suggestions everyone, however I'm still at the same
underlying stopping point: the subselect in the SET clause returns
multiple rows, and I don't know how to make it 'iterate' on each orderid
in the specified customerinvoiceid without using a JOIN, which is itself
apparently either not directly possible or complex.

UPDATE ordercharges
SET orderchargeasbilled = (expression)
WHERE
  ordercharges.orderchargecode = 'S&H' and
  ordercharges.orderid=(SELECT orderid   (tried IN(SELECT...) as well)
 FROM orders
 WHERE customerinvoiceid = '54321');

'expression' needs to get the orderchargeasbilled for the current orderid
only, not the three rows of the sample. This is why I tried JOINs of
incorrect design *outside* the subselect.

SELECT .065 * orderchargeasbilled
FROM ordercharges, orders
WHERE ordercharges.orderid = orders.orderid AND
orders.customerinvoiceid = '54321' AND
ordercharges.orderchargecode = 'SALE'

(returns the same result (3 rows) as:

SELECT .065 * orderchargeasbilled
FROM ordercharges INNER JOIN orders
ON ordercharges.orderid = orders.orderid
WHERE orders.customerinvoiceid = '54321' AND
ordercharges.orderchargecode = 'SALE'

I'm attaching a small postgres sql dump of a sample testupdates1 database,
if anyone has an idea and wants to take a shot at it.

psql -U postgres -d testupdates1 -f testupdates1.sql

pg_dump --file=testupdates1.sql --format=p -c -o -U postgres testupdates1

[ordercharges]-
orderchargeid | orderid | orderchargecode | orderchargeasbilled
---
1   123456SALE  10.00
2   123456S&H   (update from 1)
3   123457SALE  15.00
4   123457EXPEDITE   5.00
5   123457S&H   (update from 3) 
6   123458SALE  20.00
7   123458S&H   (update from 6)
8   123459SALE  10.00
9   123459S&H   (update from 8)
---

[orders]---
orderid | customerinvoiceid
---
12345654321
12345754321
12345854321
12345955543
---

[testupdates1.sql]-
--
-- PostgreSQL database dump
--

\connect - postgres

SET search_path = public, pg_catalog;

ALTER TABLE ONLY public.ordercharges DROP CONSTRAINT ordercharges_pkey;
ALTER TABLE ONLY public.orders DROP CONSTRAINT orders_pkey;
DROP TABLE public.ordercharges;
DROP TABLE public.orders;

--
-- TOC entry 2 (OID 0)
-- Name: Max OID; Type: ; Schema: -; Owner: 
--

CREATE TEMPORARY TABLE pgdump_oid (dummy integer);
COPY pgdump_oid WITH OIDS FROM stdin;
409083  0
\.
DROP TABLE pgdump_oid;

--
-- TOC entry 3 (OID 409056)
-- Name: orders; Type: TABLE; Schema: public; Owner: postgres
--

CREATE TABLE orders (
orderid character varying(30) NOT NULL,
customerinvoiceid character varying(30)
);

--
-- TOC entry 4 (OID 409062)
-- Name: ordercharges; Type: TABLE; Schema: public; Owner: postgres
--

CREATE TABLE ordercharges (
orderchargeid serial NOT NULL,
orderid character varying(30),
orderchargecode character varying(15),
orderchargeasbilled numeric(18,4)
);

--
-- Data for TOC entry 8 (OID 409056)
-- Name: orders; Type: TABLE DATA; Schema: public; Owner: postgres
--

COPY orders (orderid, customerinvoiceid) WITH OIDS FROM stdin;
409067  123456  54321
409068  123457  54321
409069  123458  54321
409070  123459  55543
\.

--
-- Data for TOC entry 9 (OID 409062)
-- Name: ordercharges; Type: TABLE DATA; Schema: public; Owner: postgres
--

COPY ordercharges (orderchargeid, orderid, orderchargecode, orderchargeasbilled)
WITH OIDS FROM stdin;
409072  2   123456  S&H \N
409075  5   123457  S&H \N
409077  7   123458  S&H \N
409079  9   123459  S&H \N
409071  1   123456  SALE10.
409073  3   123457  SALE15.
409074  4   123457  EXPEDITE5.
409076  6   123458  SALE20.
409078  8   123459  SALE10.
\.

--
-- TOC entry 6 (OID 409058)
-- Name: orders_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY orders
ADD CONSTRAINT orders_pkey PRIMARY KEY (orderid);

--
-- TOC entry 7 (OID 409065)
-- Name: ordercharges_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY ordercharges
ADD CONSTRAINT ordercharges_pkey PRIMARY KEY (orderchargeid);

--
-- TOC entry 5 (OID 409060)
-- Name: ordercharges_o