Jump to content

Recommended Posts

Ok so as of right now, I've only been working with PostgreSQL for 15 minutes, so please bare with me.  Here's what I've done so far...

 

logged in with the command

psql -U [i]username[/i]

Which prompts for a password.  I entered the password which then brings me to the prompt where I select my database to use.  Now, I know SQL, but I'm having trouble using the SQL commands in PSQL.  I tried two different ways...

projop-#SELECT * FROM users

And...

projop-#\! SELECT * FROM users

 

The first returns nothing and the second says...

sh: SELECT: command not found

 

My Goal:  To be able to view records in a table, and alter them.  Any help would be greatly appreciated.

Link to comment
https://forums.phpfreaks.com/topic/163512-need-help-with-postgresql-command-line/
Share on other sites

Is it possible that the users table is empty?  If it is you should see something like this:

 

db=> select * from foo;

--
(0 rows)

 

You can also try selects that don't involve any tables, like this:

 

db=> select now();
              now
-------------------------------
2009-06-25 11:45:49.429334+10
(1 row)

 

If the table is empty, you need to insert some data into it.

Yes they can.  The command which alters records is "update".  For example

 

UPDATE foo SET name = 'btherl' WHERE userid = 10

 

That will change all rows in table foo which have column userid equal to 10, setting column name to 'btherl' in each one.  If there is only one row with userid 10 then only 1 column will change.  If there's 0 rows matching, 0 rows are changed and it isn't an error.  If there's many rows, all are changed.

 

PS: These are all generic SQL commands.  If you find a MySQL tutorial, which is easier to find than a postgresql tutorial, you can learn SQL from there and then use most of it in Postgresql.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.