« Info:: Postgresql » : différence entre les versions

De wiki_pcwiki2
Aller à la navigationAller à la recherche
Aucun résumé des modifications
Aucun résumé des modifications
Ligne 6 : Ligne 6 :
#!/bin/bash
#!/bin/bash
clear
clear
# Pour éviter d'avoir à donner le pwd: réer le fichier (format : host:port:db:user:password)
''- Pour éviter d'avoir à donner le pwd: réer le fichier (format : host:port:db:user:password)''
echo "127.0.0.1:5432:pcNrgy5:pcnrgy5:fromspace" > ~/.pgpass
echo "127.0.0.1:5432:pcNrgy5:pcnrgy5:fromspace" > ~/.pgpass
chmod 600 ~/.pgpass
chmod 600 ~/.pgpass


Pour avoir la liste des tables:  
''- Pour avoir la liste des tables:''
'''psql -U pcnrgy5 -d pcNrgy5 -h 127.0.0.1 -c '\d''''
'''psql -U pcnrgy5 -d pcNrgy5 -h 127.0.0.1 -c '\d''''


Pour avoir les définitions d'une ou deux tables:
''- Pour avoir les définitions d'une ou deux tables:''
'''psql -U pcnrgy5 -d pcNrgy5 -h 127.0.0.1 -c '\d nrgy_appliances''''
'''psql -U pcnrgy5 -d pcNrgy5 -h 127.0.0.1 -c '\d nrgy_appliances''''
   
   
'''psql -U pcnrgy5 -d pcNrgy5 -h 127.0.0.1 -c '\d nrgy_events' -c '\d nrgy_patterns''''  
'''psql -U pcnrgy5 -d pcNrgy5 -h 127.0.0.1 -c '\d nrgy_events' -c '\d nrgy_patterns''''  


Pour lancer une commande SQL:
''- Pour lancer une commande SQL:''
'''psql -U pcnrgy5 -d pcNrgy5 -h 127.0.0.1 -c "SELECT label, phase, delta_w_min, delta_w_max, time_start, time_end, weight, duree_moy_sec FROM nrgy_patterns ORDER BY label LIMIT 20;"'''
'''psql -U pcnrgy5 -d pcNrgy5 -h 127.0.0.1 -c "SELECT label, phase, delta_w_min, delta_w_max, time_start, time_end, weight, duree_moy_sec FROM nrgy_patterns ORDER BY label LIMIT 20;"'''
   
   

Version du 23 avril 2026 à 06:00

KEYWORDS: POSTGRESQL

Le 21/04/2026:
Exemples donnés sur la base pcNrgy5 (clone de la base Mariadb pour WATTS_SPEED)
#!/bin/bash
clear
- Pour éviter d'avoir à donner le pwd: réer le fichier (format : host:port:db:user:password)
echo "127.0.0.1:5432:pcNrgy5:pcnrgy5:fromspace" > ~/.pgpass
chmod 600 ~/.pgpass

- Pour avoir la liste des tables: 
psql -U pcnrgy5 -d pcNrgy5 -h 127.0.0.1 -c '\d'

- Pour avoir les définitions d'une ou deux tables:
psql -U pcnrgy5 -d pcNrgy5 -h 127.0.0.1 -c '\d nrgy_appliances'
 
psql -U pcnrgy5 -d pcNrgy5 -h 127.0.0.1 -c '\d nrgy_events' -c '\d nrgy_patterns' 

- Pour lancer une commande SQL:
psql -U pcnrgy5 -d pcNrgy5 -h 127.0.0.1 -c "SELECT label, phase, delta_w_min, delta_w_max, time_start, time_end, weight, duree_moy_sec FROM nrgy_patterns ORDER BY label LIMIT 20;"
 
psql -U pcnrgy5 -d pcNrgy5 -h 127.0.0.1 -c "SELECT * FROM nrgy_appliances_plages;"
 
psql -U pcnrgy5 -d pcNrgy5 -h 127.0.0.1 -c "SELECT a.id, a.label, a.phase, p.plage_debut, p.plage_fin FROM nrgy_appliances a LEFT JOIN nrgy_appliances_plages p ON p.appliance_id = a.id ORDER BY a.id;"
 
psql -U pcnrgy5 -d pcNrgy5 -h 127.0.0.1 -c "SELECT id, label, actif FROM nrgy_appliances WHERE actif = 0;"