The stored procedure GET_PRIMARY_KEYS returns the list of fields that make up the primary key of a view. Each row represents a field that is part of a primary key.


      input_database_name : text
    , input_view_name : text
  • If you invoke the procedure using CALL and do not want to filter by a parameter, pass NULL.
  • If input_database_name and input_view_name are NULL, the procedure returns all the fields that are part of a primary key of all the databases.
  • If input_view_name is NULL, the procedure returns all the fields that are part of a primary key of any of view input_database_name.

The procedure returns these fields:

  • database_name: name of database where the element belongs to.
  • view_name: name of the view.
  • column_name: name of the field.
  • primary_key_name: always the value PRIMARY.

Privileges Required

The results of this procedure change depending on the privileges granted to the user that runs it. If the user is not an administrator user, consider the following:

  • If the parameter input_database_name is not NULL, the procedure returns an error if the user does not have CONNECT privileges over this database.
  • The procedure will only not return information about the primary keys of views over which the user has READ privileges.


SELECT view_name, column_name, primary_key_name
WHERE input_database_name ='chinook'

The result is:

view_name column_name primary_key_name
chinook_customer CustomerId PRIMARY
playlisttrack PlaylistId PRIMARY
playlisttrack TrackId PRIMARY
genre GenreId PRIMARY
playlist PlaylistId PRIMARY
invoiceline InvoiceLineId PRIMARY
track TrackId PRIMARY
invoice InvoiceId PRIMARY
album AlbumId PRIMARY
chinook_employee EmployeeId PRIMARY
mediatype MediaTypeId PRIMARY
artist ArtistId PRIMARY