Re: [SQL] Request for builtin function: Double_quote

2002-06-18 Thread Christoph Haller
Josh, I'm not sure what you mean by 'builtin C function'. There is one already size_t PQescapeString (char *to, const char *from, size_t length); Or do you mean a String Function like substring(string [from integer] [for integer]) I would rather call it 'builtin sql function'. Regards, C

Re: [SQL] rowtype and ecpg

2002-06-24 Thread Christoph Haller
What exactly is your problem? Calling a plpgsql function from within a C program or retrieving varchar data within a C program? Regards, Christoph > > I have a function that takes as a parameter ROWTYPE: > > create or replace function test_func(test_table) > returns varchar as ' > declare

Re: [SQL] Double quotes?

2002-07-08 Thread Christoph Haller
The information you gave is not very helpful. An INSERT command, which caused the error, would help. Anyway, did you enclose the text by single quotes? AFAIK, you do not have to escape double quotes. Regards, Christoph > > Hi everyone, > > I have a column with type text and am trying to pu

Re: [SQL] Problem on PostgreSQL (error code, store procedures)

2002-07-10 Thread Christoph Haller
> > I would like to know if there are any global variables > storing the error code or the number of rows affected > after each execution of the SQL statement. You did not mention which interface you are using. In C there are functions available like extern const char *PQcmdTuples(PGresult *r

Re: [SQL] Variables in PSQL

2002-07-10 Thread Christoph Haller
> > I'm trying to declare a variable in PostgreSQL, so I can save some values in > it. After, I want to calculate with this variable. > For example: > > declare vp integer; > select price into :vp from article where anr = 1; > vp := vp + 1; > update article set price = :vp where anr = 1; AFAIK,

Re: [SQL] SQL problem with aggregate functions.

2002-07-11 Thread Christoph Haller
> > I've got a table in which there is a field that can have one amongst 3 > possible values : D, R, X. Is it possible to get in one query the count of > this different values.Please, note that I don't want to have a querry like > this : > "select count (*) from tab group by f1;", cause i want

Re: [SQL] list of tables ?

2002-07-12 Thread Christoph Haller
> > can anyone point me in the right direction ? > > i need to list all the tables in a database. > Steve, Your request reminds me of a similar problem I had. Try the following: CREATE VIEW sesql_usertables AS SELECT UPPER(u.usename) AS tbl_owner, UPPER(c.relname) AS tbl_name, UPPER(a.att

Re: [SQL] How to find out if an index is unique?

2002-07-18 Thread Christoph Haller
Dirk, May be you can use this create view sesql_userindexes as SELECT upper(c.relname) AS TBL_NAME, upper(i.relname) AS IDX_NAME, CASE WHEN x.indisunique=false THEN 0 ELSE 1 END AS UNIQUE_FLAG, 1+ (CASE WHEN x.indkey[1]=0 THEN 0 ELSE 1 END)+(CASE WHEN x.indkey[2]=0 THEN 0 ELSE 1 END)+ (CASE W

Re: [SQL] determine if a table exists

2002-08-01 Thread Christoph Haller
> > how do i determine if a table exists using select statement > i want to find out if it exists if not ill create it if yes then ill do > some editing with it > TIA > do SELECT relname FROM pg_class WHERE relkind='r' AND relname !~ '^pg_' AND relname !~ '^pga_'

Re: [SQL] [GENERAL] CURRENT_TIMESTAMP

2002-09-24 Thread Christoph Haller
> > Christoph Haller wrote: > > Hi pgsql-sql list, > > I did some testing around tables using a column > > timestamp with time zone not null default now(). > > I have noticed a valuable feature: > > As long as being inside a transaction initiated by > &

Re: [SQL] SQL Error

2002-10-10 Thread Christoph Haller
> CREATE TABLE "scheduler_action" ( >"scheduler_action_id" numeric(30) NOT NULL, >"action_type" numeric(4) NOT NULL, >"priority" numeric(4) NOT NULL, >"referenced_id"numeric(30) NOT NULL, >"invocation_date" numeric(30) NOT NULL, >"is_done"

[SQL] if exists (select * from ...

2002-10-25 Thread Christoph Haller
I've seen statements like this if exists (select * from pg_tables where tablename = 'http://archives.postgresql.org

Re: [SQL] Locking that will delayed a SELECT

2002-10-18 Thread Christoph Haller
>Suppose I have a transaction (T1) which executes a > complicated stored procedure. While T1 is executing, > trasaction #2 (T2) begins to execute. > > T1 take more time to execute that T2 in such a way > that T2 finished earlier than T1. The result is that > t2 returns set of data before i

Re: [SQL] 'next' or similar in plpgsql

2002-10-24 Thread Christoph Haller
> > In perl we have 'next' function to skip rest of the statements in the loop > and to start with next iteration. In plpgsql, do we have something > similar? How do we skip rest of the statements in a loop in plpgsql? > The only statement which can be used in a probably tricky way seems to be EXIT

Re: [SQL] Accumulated sums in SQL query

2002-10-28 Thread Christoph Haller
> Which is the simplest way to create an SQL query to get accumulated sums of > records like this (from the table containing the numbers): > > numbersums > --- > 1 1 > 2 3 > 3 6 > 4 10 > SELECT number, SUM(your_sum_column) FROM

Re: [SQL] Accumulated sums in SQL query

2002-10-28 Thread Christoph Haller
> > OK I have a table named bank_account_movements containing two columns = > date and amount: > > date amount (in USD) > - > 2002-10-01 20 > 2002-10-02 30 > 2002-10-03 -15 > 2002

Re: [SQL] query optimization question

2002-11-06 Thread Christoph Haller
Now that I've given your problem more thoughts (and searched for similar stuff), I think what you need is generating a cross table resp. pivot table. Related to this, I am thinking of a query using Conditional Expressions like COUNT ( CASE WHEN ... THEN 1 ELSE NULL) in order to use GROUP BY. Toget

Re: [SQL] query optimization question

2002-11-07 Thread Christoph Haller
> SELECT > project_id, > marketing_name, > COUNT(lots.lot_id) AS def_count, > COUNT(CASE WHEN dt.days_old_start_date < {d '2002-10-07'} > THEN lots.lot_id ELSE NULL END) AS def_count_less_30, > COUNT(CASE WHEN dt.days_old_start_date >= {d '2002-10-07'}

[SQL] Generating a cross tab (pivot table)

2002-11-07 Thread Christoph Haller
Regarding to Terry's request on multiple aggregates and Shahbaz's request for generating a cross tab ( pivot table ) in September, I've found an excellent example on a german inet page http://www.itrain.de/ I've translated it and think it's useful for many who subscribed (I hope so, maybe it was t

Re: [SQL] how to get the source table & field name of a view field

2002-11-07 Thread Christoph Haller
> Could you tell me how to get view field's source table and field name? > another word, how could I know the view field come from? Within psql, use \d to learn about the view's column names and types and the view definition. If you were thinking about querying system tables to get this informa

[SQL] PLpgSQL FOR IN EXECUTE question

2002-11-07 Thread Christoph Haller
Consider the following PLpgSQL code fragment FOR this_record IN EXECUTE ''SELECT '' || quote_ident($1) || ''FROM '' || quote_ident($2) LOOP list := list || '', '' || this_record.$1 ; END LOOP; As expected, accessing a field via this_record.$1 does not work. Can it be d

Re: [SQL] how to get the source table & field name of a view field

2002-11-08 Thread Christoph Haller
> > if I want to write a function for getting the view.field's source > table.field > how could I achieve it? > This sounds like a real challange. Throughout the years I've had to learn it's always a pain to retrieve system catalog information - no matter which DBMS is in use. On the other hand, yo

Re: [SQL] PLpgSQL FOR IN EXECUTE question

2002-11-08 Thread Christoph Haller
Thanks to Josh, Richard, Tom EXECUTE ''SELECT CAST('' || quote_ident($1) || '' AS TEXT) AS foo FROM '' || quote_ident($2) and then list := list || '', '' || this_record.foo ; works perfectly. Regards, Christoph ---(end of broadcast)--

Re: [SQL] query optimization question

2002-11-08 Thread Christoph Haller
> > This is the final query, can anyone see anything wrong with it?: > SELECT projects.project_id, projects.marketing_name, > COUNT(lots.lot_id) AS def_count, > COUNT(CASE WHEN dt.days_old_start_date < {d '2002-10-08'} > THEN lots.lot_id ELSE NULL END >

Re: [SQL] Generating a cross tab (pivot table)

2002-11-11 Thread Christoph Haller
> I saw something that might somewhat a bit more > flexible solution using SQL. I don't know if it works > in PostgreSQL. I saw it at the MySQL site. > > The following is the URL: > http://www.mysql.com/articles/wizard/index.html > > Has anyone tried this on a PostgreSQL database ? No, not

[SQL] Generating a cross tab II (pivot table)

2002-11-11 Thread Christoph Haller
Based on the e-mails on "Generating a cross tab (pivot table)", I can give you a PLpgSQL procedure to automatically generate a cross tab from any relation now. It's my first steps in PLpgSQL. I am pretty sure this is not the best way to implement, but I wanted to get some experience, so I d

Re: [SQL] CREATE VIEW (dynamically)

2002-11-12 Thread Christoph Haller
> CREATE FUNCTION "requests_insert_after" () RETURNS opaque AS ' > DECLARE > view_name text; > BEGIN > view_name := ''request_'' || NEW.id; > CREATE VIEW view_name AS select * from groups; > return NEW; > END' LANGUAGE 'plpgsql'; > > CREATE TRIGGER "requests_insert_aft

Re: [SQL] Output of function into a file

2002-11-12 Thread Christoph Haller
> > I am writing a small function to manipulate records in multiple > tables. Since the function cannot return more than one value, I would > like to get all the outputs of the queries and append them into a text > file. > > Is there any way to do it inside the function. I came across many > pos

Re: [SQL] averaging interval values

2002-11-12 Thread Christoph Haller
> > 1:01:01 > 0:25:15 > 7:09:01 > 8:09:05 > > Is there any way to average or sum those above values using a > function? > > i could not type cast the varchar(40) to interval type. > > How to change the datatype of field from varchar to interval? > Try SELECT CAST(CAST (t2 AS TEXT) AS INTERVAL) FR

Re: [SQL] Passing OLD/NEW as composite type PL/PGSQL

2002-11-13 Thread Christoph Haller
> >Can I pass the the variables OLD and NEW (type > OPAQUE) to another function is expecting a composite > type as parameter? > >Are opaque considered as composite type? > Did you receive any other response? Did you check if it works by simply trying? As far as I understand the documentatio

Re: [SQL] PL/SQL trouble

2002-11-26 Thread Christoph Haller
> I really don't understand following PostgreSQL 7.2.3 behaviour: > > $ psql mydb > mydb=> CREATE FUNCTION MONDAY(timestamp) RETURNS DATE AS ' > DECLARE > var1 date; > BEGIN > select into var1 to_date($1::date-(case when extract(DOW from > timestamp $1) = 0 then 6 else (extract(DOW from times

Re: [SQL] retrieving specific info. from one column and locating it in another

2002-11-28 Thread Christoph Haller
> > I'm trying to retrieve some info from one column and > put it in another. I have a column that has a bunch > of information in it called 'Route'. I don't need to > show all of that information. Instead I need divide > that single column into two seperate columns called > 'Sender' and 'Receiv

Re: [SQL] Big query problem

2002-11-29 Thread Christoph Haller
> > DELETE FROM table WHERE col1='something' AND col2 IN > ('aasdoijhfoisdfsdoif','sdfsdfsdfsadfsdf', ... ); > > In the parantheses I have 6400 names, each about 20 characters. I'm > using libpq from C. This did not work very well, but the result was > very unexpected. > The conditional operator I

Re: [SQL] Query about table and catalog

2002-12-05 Thread Christoph Haller
> I've got a table with several fields. Among others there are the fields > 'soil1', 'soil2', and 'soil3' that are char type. A row can have an empty > value in one of these fields, or the three fields can have valid values: > > cod_grass |suelo1|suelo2 | suel

Re: [SQL] Question

2002-12-11 Thread Christoph Haller
> Can I get a table structure on a function using pgsql?? I think so. What are your intentions? You should be more specific. Regards, Christoph ---(end of broadcast)--- TIP 3: if posting/reading through Usenet, please send an appropriate subscribe

Re: [SQL] sql query

2002-12-11 Thread Christoph Haller
> > Hi I have a problem forming a query > I have 3 tables salary(hrs, clock_in , clock_out) > Break ( date, employe_id, net_time, break_in, break_out) > Employee(employee_id, pay_rate, name) > > I need to get an hourly report till the current time for that day > stating name, hour, no of hours, sal

Re: [SQL] Question II

2002-12-11 Thread Christoph Haller
> > I would like to get all field name of a table within a stored procedure > using pgsql. How to do it?? > SELECT a.attname FROM pg_class c, pg_attribute a WHERE c.relname = '' AND a.attnum > 0 AND a.attrelid = c.oid ORDER BY a.attnum ; gives you the field names of . If you start a psql session

Re: [SQL] Stored Procedure Problem

2002-12-12 Thread Christoph Haller
> CREATE FUNCTION b_function() RETURNS int4 AS ' > DECLARE >an_integer int4; > BEGIN >select emp_id from employee; >return an_integer; > END; > ' > LANGUAGE 'plpgsql'; > Try SELECT INTO an_integer emp_id from employee; Regards, Christoph ---(end of broadcast)-

Re: [SQL] Performance Problems

2002-12-12 Thread Christoph Haller
> >I have performance problems with a huge database > (there a 2 tables with 40 millions of records) and > many users doing updates and queries on it. I 've > perform severals VACUMM on the database with poor > results. >Each table have an unique index and I added other > indexes to improve

Re: [SQL] UPDATE with a SELECT and subSELECT(About comparing dates and non dates data)

2002-12-17 Thread Christoph Haller
> My problem is that I need to fill in the gaps (the available rain data in the > corresponding stations), and this would be a very good output for me. > I've prepared an UPDATE but it doesn't work. Perhaps someone could tell me > where is the error (I've not a very good knowledge of Postgresql). T

Re: [SQL] join and dynamic view

2002-12-17 Thread Christoph Haller
> > is it possible to make a dynamically declare a view based on a table? > Yes, by all means. > > Is it possible to now define a view such that it returns: > > select * from myview; > sid | Name| OPS | MPD > -+-+-+- > 1 | Rod | | 3 > 2 | Jayne | 2 | 5

Re: [SQL] join and dynamic view

2002-12-17 Thread Christoph Haller
> As soon as you or somebody else can tell me how to merge Jayne's two > rows into one, > I'm sure I can write a plpgsql function to dynamically create the view > you're looking for. Ok, got it: SELECT sid, sname, SUM("OPS") AS "OPS", SUM("MPD") AS "MPD" FROM ( SELECT staff.*, CASE dsdesc

Re: [SQL] join and dynamic view

2002-12-17 Thread Christoph Haller
> > I've now started amending your plpgsql script to create this, but as you can > see I've cocked up somewhere. I wonder if you could have a peek at it for > me. > Gary, CREATE OR REPLACE FUNCTION create_users_view() returns integer as ' DECLARE pg_views_rtype pg_views%ROWTYPE; vname_param

Re: [SQL] join and dynamic view

2002-12-17 Thread Christoph Haller
> > Christoph Haller wrote: > > > Tomasz, > > Could you please point out why this is not a good idea. Thanks. > > How often do you change structure of this view? What happens when during > querying this view someone recreates it? > > What happens to your repor

Re: Upgrade question - was Re: [SQL] join and dynamic view

2002-12-17 Thread Christoph Haller
> > That explains it - the server I'm developing on is quite old - I didn't > realise how old. I'm about to do an upgrade from 7.1.3 to 7.2.1-5 over > christmas in fact. > > Will I need to dump/restore the database for this upgrade? > I'm not sure. But I think it's never ever a bad idea to do a du

Re: [SQL] handling error in a function

2002-12-18 Thread Christoph Haller
> > i made desperate efforts with handling errors in a function. > > I am using functions for encapsulating a few sql-statements. Please have a > look at this: > > CREATE FUNCTION sp_fdelce(int4) RETURNS int4 AS ' > DECLARE > id ALIAS FOR $1; > BEGIN >DELETE FROM f_ces WHERE fce_id = id; >

Re: [SQL] Dynamic sql program using libpq

2002-12-18 Thread Christoph Haller
nd my encapsulated library of postgres functions, which I use for all queries resp. commands. Regards, Christoph /*- * * libpq-myfe.h * * * Christoph Haller, D.T.

Re: [SQL] unsubscribe

2002-12-19 Thread Christoph Haller
David and all others on the list, who want to turn off mailing over xmas and new year, please send your unsubscribe to [EMAIL PROTECTED] Otherwise it will not be processed. Regards, Christoph ---(end of broadcast)--- TIP 1: subscribe and unsubs

Re: [SQL] UPDATE with a SELECT and subSELECT(About comparing dates and non dates data)

2002-12-20 Thread Christoph Haller
> > Typing what you told me there was an errror; I' ve changed it slightly an it > seems that this sintax is correct. I say "it seems" because the computer > begins to process the query but doesn't finish it. I've leaved it working for > more than half an hour, before cancel it, with no result. > >

Re: [SQL] plpgsql: return results of a dynamic query

2003-01-29 Thread Christoph Haller
> > I'm trying to retrieve a row count from several tables (40) and would like > to create a function that does this automatically for the 40 and displays > the results. So, I loop through the tables: > > DECLARE > obj RECORD; > BEGIN > FOR obj IN SELECT relname AS name FROM pg_class >

Re: [SQL] double linked list

2003-01-30 Thread Christoph Haller
I've seen CELKO's reply and find it very useful. But I cannot find anything about > BEGIN ATOMIC > DECLARE rightmost_spread INTEGER; > > SET rightmost_spread > = (SELECT rgt > FROM Frammis > WHERE part = 'G'); > ... Is this PostgreSQL at all? Any hints welcome. Regards, Chr

Re: [SQL] double linked list

2003-01-30 Thread Christoph Haller
> > On Thursday 30 January 2003 07:10, Christoph Haller wrote: > > I've seen CELKO's reply and find it very useful. > > But I cannot find anything about > > > > > BEGIN ATOMIC > > > DECLARE rightmost_spread INTEGER; > > > > > &

Re: [SQL] Question about passing User defined types to functions

2003-01-30 Thread Christoph Haller
> > CREATE TYPE dumby_type AS (dumby_id int4, dumby_name text); > > create function kick_dumby(dumby dumby_type) returns INTEGER AS ' > DECLARE > somenumber integer; > BEGIN > return 1; > END; > ' language 'plpgsql'; > > > Is there some way of doing this, because the above doesn't work. > After

Re: [SQL] "function has no parameter $1" - help.

2003-02-07 Thread Christoph Haller
> > I'm trying to create a trigger to enforce a constraint onto two possible > foreign tables > my function is defined as: > > <-- snip --> > CREATE OR REPLACE FUNCTION > sp_check_tranitem_productid(tbl_tranitem.fld_tranitem_id%TYPE, > tbl_tranitem.fld_tranitem_type%TY

Re: [SQL] cannot EXPLAIN query...

2003-02-03 Thread Christoph Haller
> > Sorry Postgresql has really made my VIEWS ugly. > It wasnt' so when i fed them. > > I wish pgsql stores the create view defination some day , > just like it does for indexes (pg_get_indexdef) > Did you ever try SELECT * FROM pg_views ; It definitely has all view definitions. Regards, Christ

Re: [SQL] iceberg queries

2003-02-04 Thread Christoph Haller
> > Does PostgreSQL optimizer handle iceberg queries well? > What do you mean by "iceberg query" ? I've never heard this term. Regards, Christoph ---(end of broadcast)--- TIP 1: subscribe and unsubscribe commands go to [EMAIL PROTECTED]

Re: [SQL] pg_views

2003-02-04 Thread Christoph Haller
> > I'm wondering if PostgreSQL actually reparses the view definition on > each invocation or if it stores the required information in some > accessible place. > The documentation says: Whenever a query against a view (i.e. a virtual table) is made, the rewrite system rewrites the user's query

Re: [SQL] bytea

2003-02-05 Thread Christoph Haller
> > I have a table containing a field of type bytea: > > CREATE TABLE a_table ( > a_field bytea > ); > > How can I import a file in a SQL script? What function I can use? > The documentation says as in PostgreSQL 7.2.1 (I doubt this changed significantly since) Octets of certain values must be

Re: [SQL] bytea

2003-02-05 Thread Christoph Haller
> > Thanks for your reply. But what I want to do is loading a file of a particular path with a sql > statement in psql. Why I need to care about how the file looks like? Thanks. > Because "non-printables" might not be properly escaped. If they are, just use the SQL COPY command as described in the

Re: [SQL] Inserting a tab character

2003-02-05 Thread Christoph Haller
> > --- Luke Pascoe <[EMAIL PROTECTED]> wrote: > > I have a table which defines various possible file > > delimiters (CHAR(1) NOT > > NULL), for the moment it'll only contain comma and > > tab. Inserting a comma is > > easy, but inserting a tab is proving somewhat more > > difficult. > > > > How do

Re: [SQL] Lock timeout detection in postgres 7.3.1

2003-02-06 Thread Christoph Haller
> > I have recently migrated my database from MS Sql > Server to postgresql 7.3.1. In MS SQL SERVER, it is > very easy to set the lock time equals to zero on ROW > LEVEL. So that if some other user try to access the > same data, he/she will get the error immediately. I > have tried to run the same

Re: [SQL] Lock timeout detection in postgres 7.3.1

2003-02-06 Thread Christoph Haller
> > > > T1 (within psql): > > BEGIN; DELETE FROM ; > > DELETE n > > > > T2 (within psql): > > BEGIN; DELETE FROM ; > > > > ... > >I don't think there is a deadlock in the example > given above. If I'm not mistaken a deadlock occurs if > both transactions are waiting for each other to > relea

[SQL] SET TIMEOUT equivalent / was: Lock timeout detection

2003-02-07 Thread Christoph Haller
> > > > > > > T1 (within psql): > > > BEGIN; DELETE FROM ; > > > DELETE n > > > > > > T2 (within psql): > > > BEGIN; DELETE FROM ; > > > > > > > ... > > > >I don't think there is a deadlock in the example > > given above. If I'm not mistaken a deadlock occurs if > > both transactions are wai

Re: [SQL] conversi ms-sql7 vs postgresql 7.3

2003-02-07 Thread Christoph Haller
> > I have table xx: > id debet credit balance > 1 10000 0 > 2 2000 0 0 > 3 0 2500 0 > 4 0 100 0 > > command in ms-sql 7 can use calculate field (column) balance from id=1 to

Re: [SQL] Lock timeout detection in postgres 7.3.1

2003-02-07 Thread Christoph Haller
> > PostgreSQL 7.3 Documentation > 3.4. Run-time Configuration > STATEMENT_TIMEOUT (integer) > Aborts any statement that takes over the specified number of milliseconds. A value of zero turns off the timer. > DEADLOCK_TIMEOUT (integer) > This is the amount of time, in milliseconds, to wait on a loc

Re: [SQL] Porting from db2 problem

2003-02-24 Thread Christoph Haller
> > I am trying to port an app that currently runs over db2 and oracle (on windows > os/2 linux hpux aix etc) to also run over postgres. > I am currently porting the windows client (using odbc). > I am having major problems because of the lack of with hold cursors (cursors > that remain open ove

Re: [SQL] Help with query involving aggregation and joining.

2003-02-24 Thread Christoph Haller
> > ERROR: > SELECT DISTINCT ON expressions must match > initial ORDER BY expressions may be gotten over by > wrapping the first query result in a subselect. > > not sure though if its proper. > regds > mallah. > > test=# SELECT * from ( SELECT distinct on (a.id) b.id > ,courseid,name,submission

Re: [SQL] using Avg()

2003-03-04 Thread Christoph Haller
> > I have a table with a column named SwErr (Switch Error) with int values > date with datetime values and SwID with char(3) > I am trying to get a subset back where the folowing is true > > select the avg(SwErr) for the last 30 days where SwId = 'XX1' > Select the value of todays value of SwErr

Re: [SQL] How to notice column changes in trigger

2003-03-10 Thread Christoph Haller
> > >So you want the trigger executed only if assignments to b and/or c do > >not appear within the update command. Right? > > > > Right, that's what I want. > I'm afraid I have no idea how to accomplish that. Regards, Christoph ---(end of broadcast)

Re: [SQL] Create function statement with insert statement

2003-03-13 Thread Christoph Haller
Hello Susan, > > The relevant code for creating the hexorders table (and associated > constraints) is: > > > DROP TABLE HEXORDERS ; > > DROP SEQUENCE HEXORDERS_SEQ ; > > CREATE SEQUENCE HEXORDERS_SEQ START 1 ; > > CREATE TABL

Re: [HACKERS] [SQL] What's wrong with this group by clause?

2003-03-13 Thread Christoph Haller
> > On Tue, 4 Nov 2003 18:28:12 -0300, Franco Bruno Borghesi > <[EMAIL PROTECTED]> wrote: > >Below you can find a simplified example of a real case. > >I don't understand why I'm getting the "john" record twice. > > ISTM you have found a Postgres 7.3 bug. > > I get one john with > PostgreSQL 7.1.3

Re: [SQL] Formatting intervals..

2003-03-17 Thread Christoph Haller
> > > > Is it possible to customize interval display. > > > > eg, > > > > tradein_clients=# SELECT cast ('10-10-1999'::timestamp - '1-1-1999'::timestamp AS interval); > > +--+ > > | interval | > > +--+ > > | 282 days | > > +--+ > > (1 row) > > > > can i display it in month

Re: [SQL] the best way to get some records not in another table

2003-03-18 Thread Christoph Haller
> > Try to get some records not in another table. As the following, please > advise which one will be the best way to do. Or is there any other way to do > better? > > SELECT DISTINCT a.c1 > FROM test_j2 a > WHERE a.c1 NOT IN (SELECT DISTINCT b.c1 FROM test_j1 b); > > SELECT a.c1 FROM test_j2 a >

Re: [SQL] Casting with character and character varying

2003-03-19 Thread Christoph Haller
> > Hi all. > Recently I face some problem with casting character type variable and > varchar variable. > The situation was like: I had 2 table, on table A, the user_name is defined > as character(32), and table B uses varchar(32). I have 1 function and a > trigger to manipulate with these data. >

Re: [SQL] Seeking help with a query....

2003-03-24 Thread Christoph Haller
> > Hi folks, seeking help with a query that I thought was simple, but > apparantly isn't, at least for someone with my knowledge level. > > Given a table : > > create table atable ( > code1 char, > code2 char, > costint > ); > > And the rows > > code1code2cost > -

Re: [SQL] query 2 database

2003-03-24 Thread Christoph Haller
> > Can anybody help me, can't i make "query > 1 table in different database > (but not schema)" in postgre 7.3? > see $PGSQLD/contrib/dblink/ Regards, Christoph ---(end of broadcast)--- TIP 3: if posting/reading through Usenet, please send an app

Re: [SQL] How to show timestamp with milliseconds(3 digits) in Select

2003-03-26 Thread Christoph Haller
> > This is the query and result: > > select h323_setup_time from pv_legs_new where h323_setup_time = '2003-01-01 > 00:43:59.996-05'; > > h323_setup_time > --- > 2003-01-01 00:43:60.00-05 > > Actually, the real data of second and millisecond is 59.996-05, but it shows

Re: [SQL] howto/min values

2003-03-19 Thread Christoph Haller
> My postings seem to double on me. It's standard procedure to reply twice, one to the list and one to the sender, because you don't need to subscribe to the list to get the answers. But if you are subscribed and ask a question you usually get two. > > Now this works. So going to the next questio

Re: [SQL] Insert multiple Rows

2003-03-05 Thread Christoph Haller
> > If you use a 'prepared' insert within a transaction, would that speed things > up - maybe by defering index updates? > I doubt it. From: Neil Conway <[EMAIL PROTECTED]> ... I'd suspect that for most INSERT queries, the parsing/rewriting/planning stages are relatively inexpensive, and the bulk

Re: [SQL] string variable with spaces in psql

2003-04-04 Thread Christoph Haller
> > I need to define a variable in psql, but the variable needs to contain a > space: > > This is what I want to do; > > \set theName '\''John Nobody '\'' > SELECT add_agent( :theName, 'Test Company', 'Test Department' ); > > ... > etc > > Unfortunately psql removes the space, so that theName = 'Jo

Re: [SQL] Finding if a temp table exists in the current connection

2003-04-04 Thread Christoph Haller
> > Is there a way (i.e., access theinternal pg_ tables) to find out if a > particular temp table already exists (in the current connection)? > > I have written some stored procedures that check if a table exists and if a > column exists in a table. This is used so I can perform upgrades of our >

Re: [SQL] How Do I Hide Trigger ??

2003-04-14 Thread Christoph Haller
> > Dear Milist,=20 > For the security reason, i'd like=20 > to Hide or Encrypting some Function, > triggers or procedure on tables pg_proc,=20 > So If I have many user on my database, > there will be one user could see the > "prosrc" on pg_proc or could do select=20 > the pg_proc without encrypte

Re: [SQL] find open transactions/locks in 7.2?

2003-06-11 Thread Christoph Haller
> > [select version() --> PostgreSQL 7.2 on i686-pc-linux-gnu, compiled by GCC 3.0.4] > > I'm getting hangups every day or so, I presume due to some open transaction > that insert/update/delete'ed on a table that is used by my main app without > a commit. > > Is there some way (in 7.2!) to find who

Re: [SQL] How to make a IN without a table... ?

2003-06-12 Thread Christoph Haller
> > i ran today in a problem when doing some (i mean too much for me) advanced sql... > > What i want to do is something like this: > > SELECT > my_var1, > my_var2, > my_function(my_var1, my_var2) > FROM ( > SELECT > '1', > '2', > '3

Re: [SQL] How to make a IN without a table... ?

2003-06-12 Thread Christoph Haller
> > > These values are not taken in a table, but put in directly. > > I guess i wasn't clear enough. > "my_function" here is a function which calculate some results about some > datas from the database. > Example : a function which would calculate the sum of the money (which > would be stored in t

Re: [SQL] How to make a IN without a table... ?

2003-06-12 Thread Christoph Haller
> > Like "Tell me how much i spent between the 4th and the 7th og this month > ?" uses 4 and 7 as arguments, but need to fetch the datas in the > database. > Clear enough ? :-) Yes. > > What do you mean by table function ? Table functions are aka SetReturningFunctions. Refer to http://techdocs.pos

Re: [SQL] columnar format

2003-07-08 Thread Christoph Haller
> > i would like to ask for the sql statement to the output: > > ITEM DESC Jan Feb Mar Apr ... Sep Total > xx 999 999 999 999 ... 999 9,999 > > where "Jan" column is sum of all "x" items purchased on Jan, "Feb" column as > sum of Feb purchases, and so on up to "Sep", and "

Re: [SQL] Non-Blocking Locks (i.e. Oracle NOWAIT)

2003-07-15 Thread Christoph Haller
> > though this question has been asked several times before (but never really > answered), I have to give it another try. > > I have a multi-user application which synchronizes access to certain datasets > via the database itself. If a user has a project in that application open no > other user sh

Re: [SQL] time delay function

2003-07-22 Thread Christoph Haller
> > Pseudo code: > > begin trans > select * from table1 > WAIT FOR 20 SECS > update table1 set blah = 'blah' > end transcation > > In pgplsql, Im looking for something like a function that I can use to make the process to wait for 20 secs before con tinuing to execute the next sql statment? > AFAIK

Re: [SQL] Problem using Subselect results

2003-07-24 Thread Christoph Haller
> I want to use the result of a subselect as condition in another one. > > table1: a,b > table2: a,c > > CREATE VIEW my_view AS SELECT b,c > (SELECT a, b FROM table1 WHERE b=3D1) my_ab, > (SELECT c FROM table2, my_ab WHERE table3.a=3Dmy_ab.a) my_c; > > this is just an example - i know i could cros

Re: [SQL] time precision.

2003-07-30 Thread Christoph Haller
> I'm using PG-7.2.4 on Solaries. > When I do: > > template1# select time(6576); > ERROR: TIME(6576) precision must be between 0 and 13 > > Where am I wrong? What's the purpose of this function? And where did you find it in the docs? I didn't see it before. Regards, Christoph

Re: [SQL] One to many query question

2003-07-31 Thread Christoph Haller
> > On Wed, Jul 30, 2003 at 05:26:23PM -0400, Dmitry Tkach wrote: > > >How do I write a query to find all CDs that are NOT Rock? > > > > > What about > > select * from cd where not exists (select 1 from cd_genres where cd_id > > = cd.id and genre='Rock')? > > Thanks everyone! This did indeed work,

Re: [SQL] NEW and a subselect in a rule

2003-07-31 Thread Christoph Haller
> > So, I met such a problem: it's impossible to use NEW in a subselect > used in a (non-select) rule. The error is: exist>. Is this a way to do that newertheless (without using of a > function, of course)? > Could we see the CREATE RULE command causing the error? Regards, Christoph -

Re: [SQL] Fwd: Bad Join moment - how is this happening?

2003-07-31 Thread Christoph Haller
> I have a view: > > create or replace view addenda as > select > documents.id, > documents.oid, > documents.projects_id, > documents.doc_num, > documents.description, > documents.date, > documents.createdate, > documents.moddate, >

Re: [SQL] length of recordset read through a cursor

2003-08-01 Thread Christoph Haller
> > After declaring a cursor, one way of obtaining the length of the resultset > is to perform a "MOVE 0" and read the PQcmdStatus which returns a "MOVE nn" > where nn is the length of the resultset. (A negative MOVE can then be used > to allow starting to fetch records from the beginning of the re

Re: [SQL] Problem with looping on a table function result

2003-08-04 Thread Christoph Haller
> > I've met the following problem. > I had successfully written a function divide_into_days(timestamp, timestamp) > which returns setof (timestamp, timestamp) pairs - a list of days the > given interval is divided into. > > What I want is to use each record from resultset to pass to another > func

Re: [SQL] length of recordset read through a cursor

2003-08-11 Thread Christoph Haller
> > >> After declaring a cursor, one way of obtaining the length of the > >resultset > >> is to perform a "MOVE 0" and read the PQcmdStatus which returns a > >"MOVE nn" > >> where nn is the length of the resultset. (A negative MOVE can then be > >used > >> to allow starting to fetch records

Re: [SQL] sub-sel/group problem

2003-08-14 Thread Christoph Haller
> > select r.rtid, concat(r.rcid::text || ' on ' || l.lnumber::text) as task > from rides r, loco_dets l where r.rlid = l.lid group by rtid; > Looks like another implicit FROM clause mystery. Try ... GROUP BY r.rtid ; The same goes for the JOIN. Regards, Christoph --

Re: [SQL] Insert a description while creating a table

2003-08-14 Thread Christoph Haller
> > I want to insert descriptions at the columns of my tables but without > > using the command COMMENT ON. I want to do it together with the table > > creation. Is that possible? > > > > I wanna do something like this: > > > > create table test ( > > id serial 'Descripitions about ID', > >

Re: [SQL] Insert a description while creating a table

2003-08-14 Thread Christoph Haller
> On Wed, Aug 13, 2003 at 02:54:59PM +0200, Christoph Haller wrote: > > \dd test shows > > > > Object descriptions > > Schema | Name | Object | Description > > +--++- > > (0 rows) > > > > Thi

  1   2   >