Therefore, to create a database in PostgreSQL, execute the CREATE DATABASE query using this method. The execute() method of this class accepts a PostgreSQL query as a parameter and executes it. You can create a cursor object using the cursor() method of the Connection class. The cursor class of psycopg2 provides various methods execute various PostgreSQL commands, fetch records and copy data. You can also create a database in PostgreSQL from command prompt using the command createdb, a wrapper around the SQL statement CREATE DATABASE.Ĭ:\Program Files\PostgreSQL\11\bin> createdb -h localhost -p 5432 -U postgres sampledb Testdb | postgres | UTF8 | English_United States.1252 |. Template1 | postgres | UTF8 | English_United States.1252 |. Template0 | postgres | UTF8 | English_United States.1252 |. Postgres | postgres | UTF8 | English_United States.1252 |. Mydb | postgres | UTF8 | English_United States.1252 |. Name | Owner | Encoding | Collate | Ctype | If you verify the list of databases, you can find the newly created database as follows − You can list out the database in PostgreSQL using the \l command. Syntaxįollowing is the syntax of the CREATE DATABASE statement.įollowing statement creates a database named testdb in PostgreSQL. You can execute this statement in PostgreSQL shell prompt by specifying the name of the database to be created after the command. You can create a database in PostgreSQL using the CREATE DATABASE statement. Python SQLite - Establishing Connection.Python PostgreSQL - Database Connection.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |