Re: [SQL] [GENERAL] CURRENT_TIMESTAMP

2002-09-27 Thread Haller Christoph
> > 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 > > begin; > > the return value of the now() fun

Re: [SQL] rollback

2001-10-26 Thread Haller Christoph
> Hi everybody, > I was playing with psql and accidently deleted a couple of records from > my database. I am wondering if there is any way to restore them. I know > that in Oracle you can do 'rollback work' from SQLPlus interface and it > would rollback all the updates done to the database. That

Re: [SQL] Lock full database

2001-10-25 Thread Haller Christoph
> > I want lock full tables,how to write SQL command? > thanks > BEGIN ; LOCK TABLE ; /* done, locked until "commit;" */ Refer to the SQL-LOCK-command for further information. Regards, Christoph ---(end of broadcast)--- TIP 5: Have you ch

Re: [SQL] How to find primary keys by querying system tables

2001-10-25 Thread Haller Christoph
> > Is there a way of testing for membership in an int2vector-field? For > example: > select column, "prim.key" from ... where pg_attribute.attnum in > pg_index.indkey > ?? > I think so. Refer to the array section of the documentation. Extract: To search for a value in an array, you must check

Re: [SQL] pgsql embedded again!

2001-10-23 Thread Haller Christoph
Hi Esteban, Your problem looks familiar to me, and it seems you did not follow my advice. Anyway, here is a C sample program which works. It has nothing to do with wrong types, but with a missing connection, but see for yourself. /* /opt/pgsql/bin/ecpg -o sampleprog01.c sampleprog01.sql th

Re: [SQL] Query On Case structure

2001-10-23 Thread Haller Christoph
> > Hi All, > Can we create a query to find different values based on different criteria = > from a table using case structure. For example > Select Into :DBComment Case When localComment Is Null Then Comment When localComment = '123' Then 'Numeric Comment'

[SQL] Identifying obsolete values

2001-10-17 Thread Haller Christoph
First of all, thanks to Philip Hallstrom for the quick reply. Consider the following tables CREATE TABLE advncd_onfvalue (timepoint DATETIMENOT NULL, midINTEGER NOT NULL,/* measurement id */ lidINTEG

[SQL] Deleting obsolete values

2001-10-16 Thread Haller Christoph
This may look familiar to you - it was on the list last month. Consider the following table create table partitur (userid text, val integer, ts timestamp DEFAULT NOW() ); Do some inserts insert into partitur values('Bart', 1440); insert into partitur values('Lisa', 1024); insert into partitur

Re: [SQL] How to Return Unique Elements From An Array?

2001-10-08 Thread Haller Christoph
Have you tried already SELECT DISTINCT FROM ; If you receive an error message like Unable to identify an ordering operator ... Refer to 'Server Programming' section Extending SQL: Operators to learn about creating your own operators for array comparison Or search the mailing-list for simil

Re: [SQL] sql + C

2001-10-08 Thread Haller Christoph
I'm having some experience with C embedded SQL and what I can see at first sight is 1) DECLARE CURSOR statement - missing colon: EXEC SQL DECLARE C77 CURSOR FOR select datname from pg_user,pg_database where usename= :user and datdba= :usesysid; 2) before OPEN you have to declare and set the wh

Re: [SQL] challenging query

2001-10-05 Thread Haller Christoph
> > Consider the following table: > > A B C D select? > --- > 1 FOO A1 100 n > 1 BAR Z2 100 n > 2 FOO A1 101 y > 2 BAR Z2 101 y > 3 FOO A1 102 y > 4 BAR

Re: [SQL] challenging query

2001-10-05 Thread Haller Christoph
> > Consider the following table: > > A B C D select? > --- > 1 FOO A1 100 n > 1 BAR Z2 100 n > 2 FOO A1 101 y > 2 BAR Z2 101 y > 3 FOO A1 102 y > 4 BAR

Re: [SQL] TEXT in select

2001-09-29 Thread Haller Christoph
I've tried (column indexdef is of type text) select indexdef from pg_indexes where indexdef like '%pg_proc%' ; select indexdef from pg_indexes where position('pg_proc' in indexdef) > 0 ; select upper(indexdef) from pg_indexes where position('pg_proc' in indexdef) > 0 ; and all three worked as

Re: [SQL] is it possible to get the number of rows of a table?

2001-09-27 Thread Haller Christoph
> > I would like to compare the number of rows > of one table and of another and use it in > a query like this: > SELECT * FROM > WHERE "number of rows of table " > EQUALS >"number of rows of table " > i.e. I only want get a query result if th

Re: [SQL] Selecting latest value II

2001-09-20 Thread Haller Christoph
What do you mean by "the latest val for each userid" I cannot understand how a value of type integer can have a attribute like "latest". Sorry, but I need at least a bit more information. Regards, Christoph > > On Thu, 20 Sep 2001, Haller Christoph wrote: >

Re: [SQL] Selecting latest value

2001-09-20 Thread Haller Christoph
Try create NEWtable (userid text, val integer, ts timestamp); insert into NEWtable select userid, val, max(ts) from table group by userid, val; Regards, Christoph > > Hi, > > I have a table which basically looks like this: > > create table (userid text, val integer, ts timestamp); > > Thi

Re: [SQL] Registring a C function in PostgreSQL II

2001-09-20 Thread Haller Christoph
My understanding is, if you have system calls from within postgres, the child processes invoked are run in the postgres user's environment. So, login as user postgres and have a look what aliases are set. My idea is, because postgres is not a human user, these aliases are not set. I think, if

Re: [SQL] Registring a C function in PostgreSQL II

2001-09-19 Thread Haller Christoph
I'm working on a HP-UX system, so some of the following has to be adapted, but in principle it's the same on every system and it works. First piece of code is a standalone program, which you should always write and test before you start creating C functions inside PostgreSQL. Second piece is

Re: [SQL] Registring a C function in PostgreSQL

2001-09-19 Thread Haller Christoph
Did you use the compiler option for generating position independent code (PIC) for use in building shared libraries. Did you use the linker option for creating a shared library - I think you did, the file suffix .so looks that way. I did it several times successfully using commands like CREA

Re: [SQL] Out of free buffers... HELP!

2001-09-18 Thread Haller Christoph
As long as there are no nulls allowed in column 'dst' the select src,dst,count(dst) from ... should retrieve the same result. Try it. It should run faster anyway. Maybe there are other ways to word your query, but without more knowledge about your table structure and intentions I can't tell

Re: [SQL] How to see the definition of an existing table?

2001-09-18 Thread Haller Christoph
Within psql you can do commands like \d to learn rudimentary information about a table. Try this to learn more sophisticated information select u.usename, t.typname, a.attname, a.atttypid, a.attlen, a.attnotnull, a.attnum from pg_user u, pg_type t, pg_attribute a where u.usesysid = t.typo

Re: [SQL] Number the lines

2001-09-17 Thread Haller Christoph
Am I right in assuming you were asking for something like SELECT Rownumbering(), ... FROM ORDER BY ; and expecting a result like 1| ... 2| ... 3| ... ... where Rownumbering() is a PostgreSQL function If this is what you wanted, this is something I want for a long time too. Maybe we

[SQL] ERROR: Cannot insert a duplicate key into a unique index

2001-09-12 Thread Haller Christoph
[SQL] ERROR: Cannot insert a duplicate key into a unique index I'm working on a C code application using loads of insert commands. It is essential to distinguish between an error coming from a misformed command or other fatal reasons and a duplicate key. In either case, the PQresultStatus()

[SQL] ERROR: DefineQueryRewrite: rule plan string too big.

2001-09-07 Thread Haller Christoph
I tried to create a view as follows create view sesql_userindexes as SELECT c.relname AS TBL_NAME, i.relname AS IDX_NAME, x.indisunique 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 WHEN x.indkey[3]=0 THEN 0 ELSE 1 END)+(CASE

Re: [SQL]

2001-09-07 Thread Haller Christoph
My understanding is you did it the best way. Alternatively, you may word your query as SELECT i.cname FROM fc_client_info i WHERE EXISTS ( SELECT * FROM fc_communication c WHERE c.acode = i.acode AND c.contactdate = '09/06/2001' ) ORDER BY lower(i.cname); instead