Re: [SQL] Two way encryption in PG???

2001-03-05 Thread Boulat Khakimov
David Olbersen wrote: > > On Sun, 4 Mar 2001, Boulat Khakimov wrote: > > ->How do I encrypt/decrypt something in PG? > > Perhaps it'd be better to one-way encrypt something? Granted I don't know the > details of your project, but allowing a way to "decrypt" something is rather > insecure. > >

Re: [SQL] dates in functions

2001-03-05 Thread George Moga
Salvador Mainé wrote: > Hello: > > I'm trying to define a function that, given a date, returns its month. > The definition is as follows: > > CREATE function anyo_hidro (date) returns int AS ' >BEGIN >RETURN date_part("month",$1); >END; > ' LANGUAGE 'plpgsql'; > > But when

Re: [SQL] Two way encryption in PG???

2001-03-05 Thread clayton cottingham
Boulat Khakimov wrote: > > David Olbersen wrote: > > > > On Sun, 4 Mar 2001, Boulat Khakimov wrote: > > > > ->How do I encrypt/decrypt something in PG? > > > > Perhaps it'd be better to one-way encrypt something? Granted I don't know the > > details of your project, but allowing a way to "decrypt

Re: [SQL] Passing table names to PL/PGSQL for SELECT/UPDATE/INSERT

2001-03-05 Thread Jie Liang
Unfortunately, PL/PGSQL cannot pass table name. I have same problem, only thing I can do is pass an integer, then use IF .. THEN .. ELSE .. END IF; Jie LIANG St. Bernard Software 10350 Science Center Drive Suite 100, San Diego, CA 92121 Office:(858)320-4873 [EMAIL PROTECTED] www.stbernard.com

Re: [SQL]

2001-03-05 Thread Jie Liang
Unfortunately, in plsql you only can do DML(select/update/insert) instead of DDL(create/grant..). i.e. you cannot create a table in plsql. Jie LIANG St. Bernard Software 10350 Science Center Drive Suite 100, San Diego, CA 92121 Office:(858)320-4873 [EMAIL PROTECTED] www.stbernard.com www.ipinc

[SQL] count number of weeks??

2001-03-05 Thread rocael
Hi all! I wonder how in PG7.0.2 I can count the number of weeks from a date field that I have in a table, lets say: table trial has in its fields start_date as sysdate(), and now I want to do a select that will give me the number of weeks from now [sysdate()] to the start_date. Thanks for the he

[SQL] How do I use text script containing SQL?

2001-03-05 Thread Jeff S.
I want to build my tables by placing all the sql statements in a file. What is the correct way to use this file with psql? Example: My text file has this in it: CREATE TABLE table1 ( table1_id serial, field1 char(5), PRIMARY KEY (table1_id) ); I want to be able to use the file to crea

Re: [SQL] How do I use text script containing SQL?

2001-03-05 Thread clayton cottingham
"Jeff S." wrote: > > I want to build my tables by placing all the sql > statements in a file. What is the correct way to use > this file with psql? > > Example: My text file has this in it: > > CREATE TABLE table1 ( >table1_id serial, >field1 char(5), >PRIMARY KEY (table1_id) > );

Re: [SQL] How do I use text script containing SQL?

2001-03-05 Thread David Olbersen
On Mon, 5 Mar 2001, Jeff S. wrote: ->I want to be able to use the file to create my table. ->I've tried psql -d databasename -e < filename.txt ->but that doesn't work. You're making it too dificult :-) 'psql -d databasename < filename.txt' should work just fine -- Dave ---

[SQL] random

2001-03-05 Thread Jelle Ouwerkerk
Hi What would be the best way to select a random row from a result set? Possibilities: 1) o get the total number of rows using count() o generate a random number between 1 and the total o select the n'th row using OFFSET 2) o get the total number of rows using count() o generate a ran

[SQL] pl/pgsql and returning rows

2001-03-05 Thread wade
Here is the senario... I have a table defined as create table details ( field1 field2 . . . ); and a function: create function get_details(int4) returns details as ' declare ret details%ROWTYPE; site_recrecord; cntct contacts%ROWTYPE; begin select

Re: [SQL] random

2001-03-05 Thread Tom Lane
Jelle Ouwerkerk <[EMAIL PROTECTED]> writes: > Also, is there a way to randomize the order of a result set? There's always SELECT * FROM foo ORDER BY random(); regards, tom lane ---(end of broadcast)--- TIP 3: if pos

[SQL] Optimizing Query

2001-03-05 Thread Justin Long
Any suggestions welcome! Here is my query: select k.*, c.category from knowledge k, kb_categories c , kbwords w0 , kbwords w1 WHERE k.catid=c.catid AND ((k.kbid=w0.kbid and w0.wordid=42743) AND (k.kbid=w1.kbid and w1.wordid=85369)) ORDER BY k.kbid DESC LIMIT 25; Now for the details knowledge k

Re: [SQL] PL/SQL-to-PL/PgSQL-HOWTO beta Available

2001-03-05 Thread Bruce Momjian
Can someone comment on this? Is it being merged into the main docs? > Hi all, > > I finished the beta version of my PL/SQL-to-PL/PgSQL-HOWTO last night > and put it in http://www.brasileiro.net/roberto/howto . > It explains basic differences between Oracle's PL/SQL and PG's >

Re: [SQL] random

2001-03-05 Thread Bruce Momjian
> Jelle Ouwerkerk <[EMAIL PROTECTED]> writes: > > Also, is there a way to randomize the order of a result set? > > There's always > SELECT * FROM foo ORDER BY random(); > How does that work? test=> select random(); random ---

Re: [SQL] Optimizing Query

2001-03-05 Thread Bruce Momjian
Have you tried VACUUM ANALYZE and CLUSTER? > Any suggestions welcome! > > Here is my query: > > select k.*, c.category from knowledge k, kb_categories c , kbwords w0 , > kbwords w1 WHERE k.catid=c.catid AND ((k.kbid=w0.kbid and w0.wordid=42743) > AND (k.kbid=w1.kbid and w1.wordid=85369)) ORD

Re: [SQL] random

2001-03-05 Thread Tom Lane
Bruce Momjian <[EMAIL PROTECTED]> writes: >> Jelle Ouwerkerk <[EMAIL PROTECTED]> writes: > Also, is there a way to randomize the order of a result set? >> >> There's always >> SELECT * FROM foo ORDER BY random(); > However: > test=> select * from pg_class order by random(); > does return s

Re: [SQL] random

2001-03-05 Thread Stephan Szabo
On Mon, 5 Mar 2001, Bruce Momjian wrote: > > Jelle Ouwerkerk <[EMAIL PROTECTED]> writes: > > > Also, is there a way to randomize the order of a result set? > > > > There's always > > SELECT * FROM foo ORDER BY random(); > > > > How does that work? > > test=> select random(); >

Re: [SQL] random

2001-03-05 Thread Bruce Momjian
> Bruce Momjian <[EMAIL PROTECTED]> writes: > >> Jelle Ouwerkerk <[EMAIL PROTECTED]> writes: > > Also, is there a way to randomize the order of a result set? > >> > >> There's always > >> SELECT * FROM foo ORDER BY random(); > > > However: > > test=> select * from pg_class order by random();

Re: [SQL] random

2001-03-05 Thread Tom Lane
Bruce Momjian <[EMAIL PROTECTED]> writes: > But random returns a random value from 0-1, right? How does that work > in ORDER BY? What's the problem? Each row gets a different random value, then we sort. regards, tom lane ---(end of broadcast)---

Re: [SQL] Optimizing Query

2001-03-05 Thread Mathijs Brands
On Mon, Mar 05, 2001 at 04:07:57PM -0500, Bruce Momjian allegedly wrote: > Have you tried VACUUM ANALYZE and CLUSTER? I assume CLUSTER still drops all indexes except the one you're clustering on? Mathijs -- It's not that perl programmers are idiots, it's that the language rewards idiotic behavi

Re: [SQL] Optimizing Query

2001-03-05 Thread Bruce Momjian
Yes. > On Mon, Mar 05, 2001 at 04:07:57PM -0500, Bruce Momjian allegedly wrote: > > Have you tried VACUUM ANALYZE and CLUSTER? > > I assume CLUSTER still drops all indexes except the one you're clustering > on? > > Mathijs > -- > It's not that perl programmers are idiots, it's that the languag

Re: [SQL] random

2001-03-05 Thread Bruce Momjian
> Bruce Momjian <[EMAIL PROTECTED]> writes: > > But random returns a random value from 0-1, right? How does that work > > in ORDER BY? > > What's the problem? Each row gets a different random value, then we > sort. Oh, I see. Nifty. I am used to seeing a column name or number in ORDER BY. W

[SQL] Extending PostgreSQL Using C

2001-03-05 Thread Boulat Khakimov
Hi, Im writing a C function for PG to do one way encryption using crypt. Here is the source code #include #include #include "postgres.h" #include "utils/builtins.h" text *encrypt(text *string){ text *ret; int m; if ((string == (text *) NULL

Re: [SQL] Optimizing Query

2001-03-05 Thread Justin Long
Does that mean that if you have 3 indexes on a table and you cluster one, it deletes the other 2? At 04:45 PM 3/5/2001 -0500, you wrote: Yes. > On Mon, Mar 05, 2001 at 04:07:57PM -0500, Bruce Momjian allegedly wrote: > > Have you tried VACUUM ANALYZE and CLUSTER? > > I assume CLUSTER still drop

Re: [SQL] Optimizing Query

2001-03-05 Thread Justin Long
Yes, it drops indexes, much to my chagrin, as I just realized ... including SERIALs... Justin At 04:45 PM 3/5/2001 -0500, you wrote: Yes. > On Mon, Mar 05, 2001 at 04:07:57PM -0500, Bruce Momjian allegedly wrote: > > Have you tried VACUUM ANALYZE and CLUSTER? > > I assume CLUSTER still drops a

Re: [SQL] How do I use text script containing SQL?

2001-03-05 Thread Mathijs Brands
On Mon, Mar 05, 2001 at 11:08:40AM -0800, David Olbersen allegedly wrote: > On Mon, 5 Mar 2001, Jeff S. wrote: > > ->I want to be able to use the file to create my table. > ->I've tried psql -d databasename -e < filename.txt > ->but that doesn't work. > > You're making it too dificult :-) > 'psq

Re: [SQL] Optimizing Query

2001-03-05 Thread Justin Long
Ok, now I have another question... it doesn't seem to be accessing the index. explain select k.kbid,k.title from knowledge k , kbwords w0 , kbwords w1 WHERE ((k.kbid=w0.kbid and w0.wordid=42743) AND (k.kbid=w1.kbid and w1.wordid=85369)) NOTICE:  QUERY PLAN: Merge Join  (cost=32339.30..35496.97

Clustering (was Re: [SQL] Optimizing Query)

2001-03-05 Thread Mathijs Brands
On Mon, Mar 05, 2001 at 04:45:47PM -0500, Bruce Momjian allegedly wrote: > Yes. > > > On Mon, Mar 05, 2001 at 04:07:57PM -0500, Bruce Momjian allegedly wrote: > > > Have you tried VACUUM ANALYZE and CLUSTER? > > > > I assume CLUSTER still drops all indexes except the one you're clustering > > on

[SQL] How to count elements in an array?

2001-03-05 Thread Grant
How can I obtain a count (number) of elements in a text array? Thanks. test=# \d array Table "array" Attribute | Type |Modifier --+-+ id | integer | not null def

Re: [SQL] Optimizing Query

2001-03-05 Thread Michael Fork
Did you run VACUUM ANALYZE after running CLUSTER? Michael Fork - CCNA - MCP - A+ Network Support - Toledo Internet Access - Toledo Ohio On Mon, 5 Mar 2001, Justin Long wrote: > Ok, now I have another question... it doesn't seem to be accessing the index. > > explain select k.kbid,k.title from

Re: [SQL] Two way encryption in PG???

2001-03-05 Thread Mathijs Brands
On Mon, Mar 05, 2001 at 08:40:53AM -0800, clayton cottingham allegedly wrote: > Boulat Khakimov wrote: > > > > David Olbersen wrote: > > > > > > On Sun, 4 Mar 2001, Boulat Khakimov wrote: > > > > > > ->How do I encrypt/decrypt something in PG? > > > > > > Perhaps it'd be better to one-way encrypt

Re: [SQL] Optimizing Query

2001-03-05 Thread Mathijs Brands
On Mon, Mar 05, 2001 at 04:59:47PM -0500, Justin Long allegedly wrote: > Ok, now I have another question... it doesn't seem to be accessing the index. > > explain select k.kbid,k.title from knowledge k , kbwords w0 , kbwords w1 > WHERE ((k.kbid=w0.kbid and w0.wordid=42743) AND (k.kbid=w1.kbid an

[SQL] Re: [DOCS] Extending PostgreSQL Using C

2001-03-05 Thread Tom Lane
Boulat Khakimov <[EMAIL PROTECTED]> writes: > ERROR: Can't find function encrypt in file /[full path here]/encrypt.so > Why do I get this error Offhand I see nothing wrong with your procedure. Try running 'nm' on the .so file to see what symbols it says the .so defines. What platform is t

[SQL] Vacuum.

2001-03-05 Thread Grant
Does vacuuming and analyzing a database affect the users if they are currently inserting/deleting rows from a table on the database? How does it work exactly... Thanks. ---(end of broadcast)--- TIP 2: you can get off all lists at once with the unr

[SQL] Re: [DOCS] Extending PostgreSQL Using C

2001-03-05 Thread Boulat Khakimov
Tom Lane wrote: > > Boulat Khakimov <[EMAIL PROTECTED]> writes: > > ERROR: Can't find function encrypt in file /[full path here]/encrypt.so > > Why do I get this error > > Offhand I see nothing wrong with your procedure. Try running 'nm' on > the .so file to see what symbols it says the .s

Re: [SQL] How do I use text script containing SQL?

2001-03-05 Thread Jie Liang
if you are a user with privalege can create table psql -e dbname I want to build my tables by placing all the sql > statements in a file. What is the correct way to use > this file with psql? > > Example: My text file has this in it: > > CREATE TABLE table1 ( >table1_id serial, >field1

Re: [SQL] count number of weeks??

2001-03-05 Thread Christopher Sawtell
On Tue, 06 Mar 2001 06:55, [EMAIL PROTECTED] wrote: > Hi all! > I wonder how in PG7.0.2 I can count the number of weeks from a date > field that I have in a table, lets say: > > table trial has in its fields start_date as sysdate(), and now I want to > do a select that will give me the number of w

[GENERAL] MySQLs Describe emulator!

2001-03-05 Thread Boulat Khakimov
Hi, Here is a nifty query I came up with that provides a detailed information on any row of any table. Something that is build into mySQL (DESC tablename fieldname) but not into PG. SELECT a.attname AS Field, c.typname as Type, a.atttypmod-4 AS Size FROM pg_attribute a, pg

Re: [GENERAL] MySQLs Describe emulator!

2001-03-05 Thread Tom Lane
Boulat Khakimov <[EMAIL PROTECTED]> writes: > Here is a nifty query I came up with > that provides a detailed information on any row of any table. > Something that is build into mySQL (DESC tablename fieldname) > but not into PG. Er, what's wrong with psql's "\d table" ?

Re: [SQL] Optimizing Query

2001-03-05 Thread Tom Lane
Justin Long <[EMAIL PROTECTED]> writes: > Ok, now I have another question... it doesn't seem to be accessing the index. > explain select k.kbid,k.title from knowledge k , kbwords w0 , kbwords w1 > WHERE ((k.kbid=w0.kbid and w0.wordid=42743) AND (k.kbid=w1.kbid and > w1.wordid=85369)) > NOTICE:

[SQL] No Documentation for to_char(INTERVAL, mask)

2001-03-05 Thread Josh Berkus
Bruce, Tom, et. al., I can't find any documentation for what masks to use with the function TO_CHAR(INTERVAL, mask). Is there a TO_CHAR(INTERVAL)? If so, what masks are there? If not, how would you suggest I convert an interval value for user-friendly display?

Re: [SQL] How to count elements in an array?

2001-03-05 Thread Josh Berkus
Grant, The only way I know to enumarate arrays is procedural. This is a good reason to stay away from arrays except in buffer and temporary tables (aside from the fact that array columns violate the relational principle of atomicity). The following sample procedure, paraphrased

Re: [SQL] No Documentation for to_char(INTERVAL, mask)

2001-03-05 Thread Grant
Did you see: http://www.postgresql.org/users-lounge/docs/7.0/user/functions2872.htm On Mon, 5 Mar 2001, Josh Berkus wrote: > I can't find any documentation for what masks to use with the function > TO_CHAR(INTERVAL, mask). Is there a TO_CHAR(INTERVAL)? If so, what > masks are there? If