[SQL] Make C file for create type

2005-08-05 Thread Louise Catherine
Hallo,
I found a problem making new data type kata,expecially
when make the C file ,can anyone help me solve it. 

This error occur when I'm compiling the C file :
/usr/lib/gcc-lib/i586-suse-linux/3.3.1/../../../crt1.o(.text+0x18):
In function `_start':
../sysdeps/i386/elf/start.S:98: undefined reference to
`main'
collect2: ld returned 1 exit status

Here it's my code :
file3.c
---
#include "postgres.h"

typedef struct kata
{
  char kt[30];
} kata;

kata *input_kata(char *str);
char *output_kata(kata * kata);

kata *
input_kata(char *str)
{
char kt[30];
kata *result;

if (sscanf(str, "( %s )", &kt) !=1)
{
printf ("error\n");
return NULL;
}

result = (kata *) malloc(sizeof(kata));
strcpy(result->kt,kt);
return result;
}

char *
output_kata(kata * kata)
{
char kt[30];
char *result;

strcpy(kt,kata->kt);

if (strcmp(kt,NULL))
return NULL;

result = (char *) malloc(60);
sprintf(result, "(%s)", kata->kt);
return result;
}

kata.sql

CREATE FUNCTION input_kata(cstring)
   RETURNS kata
   AS '_OBJWD_/file3'
   LANGUAGE C IMMUTABLE STRICT;

CREATE FUNCTION output_kata(kata)
   RETURNS cstring
   AS '_OBJWD_/file3'
   LANGUAGE C IMMUTABLE STRICT;

CREATE TYPE kata (
INPUT = input_kata,
OUTPUT = output_kata
)






Start your day with Yahoo! - make it your home page 
http://www.yahoo.com/r/hs 
 

---(end of broadcast)---
TIP 1: if posting/reading through Usenet, please send an appropriate
   subscribe-nomail command to [EMAIL PROTECTED] so that your
   message can get through to the mailing list cleanly


[SQL] 'select where' using multiple columns.

2005-08-05 Thread Rob Kirkbride

Hi,

I've googled around for this but can't see a decent way of doing this :

I've got a persons name which is being stored say in 3 columns :-  
Title, Forename_1, Forename_2, Surname. I want to allow a search say for 
'John Smith'. Problem is I can't just break it up into forename and 
surname because I won't also know.

Is there a way to do something like a
'select * where forename_1,forename_2,surname like '%String%'   ??

Thanks for any help. Apologies if its a FAQ.

Rob


---(end of broadcast)---
TIP 5: don't forget to increase your free space map settings


Re: [SQL] 'select where' using multiple columns.

2005-08-05 Thread Ian Johannesen
Hi.

Rob Kirkbride wrote:
> I've googled around for this but can't see a decent way of doing this :
> 
> I've got a persons name which is being stored say in 3 columns :- 
> Title, Forename_1, Forename_2, Surname. I want to allow a search say for
> 'John Smith'. Problem is I can't just break it up into forename and
> surname because I won't also know.
> Is there a way to do something like a
> 'select * where forename_1,forename_2,surname like '%String%'   ??
> 
> Thanks for any help. Apologies if its a FAQ.

SELECT * FROM table WHERE forename_1 || ' ' || forename_2 || ' ' ||
surname LIKE '%String%';

-- 
Digitally Yours,

Ian Johannesen
web: http://perlpimp.dk/
msn: [EMAIL PROTECTED]
cel: +45 31 13 73 76


smime.p7s
Description: S/MIME Cryptographic Signature


Re: [SQL] 'select where' using multiple columns.

2005-08-05 Thread daq


RK> Hi,

RK> I've googled around for this but can't see a decent way of doing this :

RK> I've got a persons name which is being stored say in 3 columns :-  
RK> Title, Forename_1, Forename_2, Surname. I want to allow a search say for 
RK> 'John Smith'. Problem is I can't just break it up into forename and 
RK> surname because I won't also know.
RK> Is there a way to do something like a
RK> 'select * where forename_1,forename_2,surname like '%String%'   ??

RK> Thanks for any help. Apologies if its a FAQ.

RK> Rob


RK> ---(end of broadcast)---
RK> TIP 5: don't forget to increase your free space map settings

Try this way:

select *  where forename_1||' '||forename_2||' '||surname like '%String%'

or

select *  where forename_1||' '||forename_2||' '||surname~'String'

DAQ


---(end of broadcast)---
TIP 3: Have you checked our extensive FAQ?

   http://www.postgresql.org/docs/faq


Re: [SQL] 'select where' using multiple columns.

2005-08-05 Thread Rob Kirkbride

Ian Johannesen wrote:


Hi.

Rob Kirkbride wrote:
 

I've got a persons name which is being stored say in 3 columns :- 
Title, Forename_1, Forename_2, Surname. I want to allow a search say for

'John Smith'. Problem is I can't just break it up into forename and
surname because I won't also know.
Is there a way to do something like a
'select * where forename_1,forename_2,surname like '%String%'   ??

   


SELECT * FROM table WHERE forename_1 || ' ' || forename_2 || ' ' ||
surname LIKE '%String%';

 

Thanks for the quick response. I've tried that and it works fine. Thanks 
a lot and thanks to Daq and Helder.


Rob

---(end of broadcast)---
TIP 6: explain analyze is your friend


Re: [SQL] 'select where' using multiple columns.

2005-08-05 Thread Hélder M. Vieira



Is there a way to do something like a
'select * where forename_1,forename_2,surname like '%String%'   ??



You could try the following, but it won't get a medal for performance...

SELECT * FROM xpto WHERE forename_1 LIKE '%String%' OR forename_2 LIKE 
'%String%' OR surname LIKE '%String%'




Helder M. Vieira 




---(end of broadcast)---
TIP 6: explain analyze is your friend


Re: [SQL] Make C file for create type

2005-08-05 Thread Richard Huxton

Louise Catherine wrote:

Hallo,
I found a problem making new data type kata,expecially
when make the C file ,can anyone help me solve it. 


This error occur when I'm compiling the C file :
/usr/lib/gcc-lib/i586-suse-linux/3.3.1/../../../crt1.o(.text+0x18):
In function `_start':
../sysdeps/i386/elf/start.S:98: undefined reference to
`main'
collect2: ld returned 1 exit status


You don't have a main() function. This is the function that gets called 
when you run an executable. Looking at your code, it seems like you want 
to produce a library rather than a standalone program.


This might help:
 http://www.tldp.org/HOWTO/Program-Library-HOWTO/shared-libraries.html
Also, read the section on C-language functions in the manuals.

Also, you're clearly missing bound-checking on your various copy 
operations, and I think you're supposed to use palloc() rather than 
malloc() if this is supposed to sit inside PostgreSQL.


Bear in mind it's been 10 years since I wrote any C though, so use your 
own judgement on my advice.


--
  Richard Huxton
  Archonet Ltd

---(end of broadcast)---
TIP 2: Don't 'kill -9' the postmaster


[SQL] sum but not grouped by?

2005-08-05 Thread Henry Ortega
I have the ff data:

id  | date |  hours
AAA07-01-2005   3
AAA07-02-2005   4
BBB07-01-2005   6
BBB07-02-2005   2
BBB07-03-2005   7

Would it be possible to get the ff:

id  | date |  hours   |   id_total
AAA07-01-2005   3  7
AAA07-02-2005   4  7
BBB07-01-2005   6  15
BBB07-02-2005   2  15
BBB07-03-2005   7  15

So it's like SUM OF, but not Grouped By? Is this possible at all?
Thank you for any help.

---(end of broadcast)---
TIP 3: Have you checked our extensive FAQ?

   http://www.postgresql.org/docs/faq


Re: [SQL] sum but not grouped by?

2005-08-05 Thread Mischa Sandberg
Quoting Henry Ortega <[EMAIL PROTECTED]>:

> I have the ff data:
> 
> id  | date |  hours
> AAA07-01-2005   3
> AAA07-02-2005   4
> BBB07-01-2005   6
> BBB07-02-2005   2
> BBB07-03-2005   7
> 
> Would it be possible to get the ff:
> 
> id  | date |  hours   |   id_total
> AAA07-01-2005   3  7
> AAA07-02-2005   4  7
> BBB07-01-2005   6  15
> BBB07-02-2005   2  15
> BBB07-03-2005   7  15
> 
> So it's like SUM OF, but not Grouped By? Is this possible at all?
> Thank you for any help.

You're really joining two sets:

select FFDATA.id, FFDATA.date, FFDATA.hours, FFSUM.id_total
fromFFDATA
join (select id, sum(hours) as id_total
  from FFDATA group by id
 ) as FFSUM using(id)



---(end of broadcast)---
TIP 1: if posting/reading through Usenet, please send an appropriate
   subscribe-nomail command to [EMAIL PROTECTED] so that your
   message can get through to the mailing list cleanly


Re: [SQL] sum but not grouped by?

2005-08-05 Thread Henry Ortega
Is it possible at all to do this without any joins
or subselect?



On 8/5/05, Mischa Sandberg <[EMAIL PROTECTED]> wrote:
> Quoting Henry Ortega <[EMAIL PROTECTED]>:
> 
> > I have the ff data:
> >
> > id  | date |  hours
> > AAA07-01-2005   3
> > AAA07-02-2005   4
> > BBB07-01-2005   6
> > BBB07-02-2005   2
> > BBB07-03-2005   7
> >
> > Would it be possible to get the ff:
> >
> > id  | date |  hours   |   id_total
> > AAA07-01-2005   3  7
> > AAA07-02-2005   4  7
> > BBB07-01-2005   6  15
> > BBB07-02-2005   2  15
> > BBB07-03-2005   7  15
> >
> > So it's like SUM OF, but not Grouped By? Is this possible at all?
> > Thank you for any help.
> 
> You're really joining two sets:
> 
> select FFDATA.id, FFDATA.date, FFDATA.hours, FFSUM.id_total
> fromFFDATA
> join (select id, sum(hours) as id_total
>  from FFDATA group by id
> ) as FFSUM using(id)
> 
> 
> 
> ---(end of broadcast)---
> TIP 1: if posting/reading through Usenet, please send an appropriate
>   subscribe-nomail command to [EMAIL PROTECTED] so that your
>   message can get through to the mailing list cleanly
>

---(end of broadcast)---
TIP 9: In versions below 8.0, the planner will ignore your desire to
   choose an index scan if your joining column's datatypes do not
   match


Re: [SQL] sum but not grouped by?

2005-08-05 Thread PFC
On Fri, 05 Aug 2005 19:53:14 +0200, Henry Ortega <[EMAIL PROTECTED]>  
wrote:



Is it possible at all to do this without any joins
or subselect?


I don't think so.
You could always hide them in a view...

---(end of broadcast)---
TIP 3: Have you checked our extensive FAQ?

  http://www.postgresql.org/docs/faq


[SQL] how to use column name with Case-sensitive with out usig ""

2005-08-05 Thread wisan watcharinporn

how can i use

create table myName(
  myColumnName varchar(32)
);

select myColumnName from myColumnName ;

instead

create table "myName" (
  "myColumnName" varchar(32)
);

select "myColumnName" from "myColumnName" ;

_
Express yourself instantly with MSN Messenger! Download today it's FREE! 
http://messenger.msn.click-url.com/go/onm00200471ave/direct/01/



---(end of broadcast)---
TIP 3: Have you checked our extensive FAQ?

  http://www.postgresql.org/docs/faq