POSTGRE
########### ALTER SEQUENCE #################
ALTER SEQUENCE seq RESTART WITH 1;
############################################
su postgres
psql
\list
\i [filename]
\dt or \dt+
\df or \df+
\df+ [funcname]
->
->
->
->
In this post we'll add some additional options and features related to the funct
ion's output.
==== VOID FUNCTIONS ====
Functions can return nothing. To do that we declare them as "RETURNS void". This
is appropriate for non-SELECT commands such as INSERT:
CREATE FUNCTION addsalesdata(name varchar, month varchar, value decimal) returns
void as $$
insert into salesfigures values($1,$2,$3);
$$ language 'sql';
For these functions one can call SELECT function_name(...) or SELECT * FROM func
tion_name(...).
==== FUNCTIONS THAT RETURN A SINGLE VALUE ====
Functions can return one value (one int, one decimal, one text etc.). For these
functions one can call SELECT function_name(...) or SELECT * FROM function_name(
...).
CREATE FUNCTION totalsalesformonth(month varchar) returns decimal as $$
select sum(sales) from salesfigures where month=$1;
$$ language 'sql';
Another option to define a function's output is using OUT parameters. Here we do
not use RETURNS but we list the order, names and types of output alongside the
input arguments preceding each field with "OUT".
CREATE FUNCTION salesforpersonmonth4(month varchar, OUT name varchar, OUT value
decimal) as $$
select name,sales from salesfigures where month=$1;
$$ language 'sql';
aggs=# select * from salesforpersonmonth4('jan');
name | value
------+------joe |
34
(1 row)
Notice that this is returning just one record when in fact the query would produ
ce multiple rows of results.
==== FUNCTIONS THAT RETURN A SETOF VALUES ====
Functions can also return a set of values of the same type. That is, imagine it
returning a column of decimals or a column of text. To specify this we use the S
ETOF modifier. Here is a function that returns the sales figures for each salesp
erson for January.
CREATE FUNCTION salesformonth(month varchar) returns SETOF decimal as $$
select sales from salesfigures where month=$1;
$$ language 'sql';
aggs=# select * from salesformonth('jan');
salesformonth
--------------34
18
(2 rows)
==== FUNCTIONS THAT RETURN A SETOF ROWS ====
(*
(*
(*
(*
(*
========================================================
3. ajax
function checkShippingCost(){
$objCityId = document.getElementById("list_city_id").value ;
$objDealId = "<?php echo $varTemplate['deal_id'] ?>";
$(document).ready(function(){
$.ajax({
url:"<?php echo site_url("deal/getShippingCost");?>",
type: 'POST',
data: "city_id="+$objCityId+"&deal_id="+$objDealId,
dataType: "json",
success:function(result){
if(result['status'] == "sukses"){
document.getElementById('shippingCost').
value = result['price_value'];
}else{
alert('error');
}
}
});
});
}
========================================================
4. sphinx
indexer --rotate --all //rotate semua index
searchd --stop // stop searchd
searchd //start searchd
=========================================================
5. MYSQL